From 67b33aa7a4c80b8e6fda8383e048c321e553db64 Mon Sep 17 00:00:00 2001 From: Casey Goldstein Date: Fri, 13 Jul 2018 14:20:28 -0400 Subject: [PATCH 1/2] smoother. faster. the all new 2018 findthreshold method --- songmatch/findthreshold.py | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/songmatch/findthreshold.py b/songmatch/findthreshold.py index 9968197..fac3ad4 100644 --- a/songmatch/findthreshold.py +++ b/songmatch/findthreshold.py @@ -22,25 +22,26 @@ Outputs: cutoff_log_amplitude - Threshold value between foreground/background of spectrogram """ + + + + def findthreshold (specArray): flattenedArray = specArray.flatten() absArray = np.abs(flattenedArray) loggedArray = np.log(absArray) - print(loggedArray.shape) + return np.percentile(loggedArray,90) +with open("/Users/caseygoldstein/Week1_Student/Day2/data/trumpet.txt", 'r') as R: + trumpet_audio = np.asarray([int(i) for i in R]) - hist,bins = np.histogram(loggedArray,len(loggedArray)//2,density = True) - cumulative_distr = np.zeros(len(hist)) - binsize = np.diff(bins) - cumulative_distr = (np.cumsum(hist*binsize)) - - print('hist:' + str(len(hist))) - bin_index_of_cutoff = np.searchsorted(cumulative_distr, 0.9) - cutoff_log_amplitude = bins[bin_index_of_cutoff] - return cutoff_log_amplitude - +sampling_rate = 44100 # sampling rate in Hz +fig,ax = plt.subplots() +S, freqs, times, im = ax.specgram(trumpet_audio, NFFT=4096, Fs=sampling_rate, + window=mlab.window_hanning, + noverlap=4096 // 2) +print(newfindthreshold(S)) - From b30e3086534801547414abfc1056660fd1381773 Mon Sep 17 00:00:00 2001 From: Casey Goldstein Date: Fri, 13 Jul 2018 14:29:42 -0400 Subject: [PATCH 2/2] testing? --- songmatch/addfingerprintstodatabase.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/songmatch/addfingerprintstodatabase.py b/songmatch/addfingerprintstodatabase.py index dd66aeb..83acd35 100644 --- a/songmatch/addfingerprintstodatabase.py +++ b/songmatch/addfingerprintstodatabase.py @@ -12,4 +12,7 @@ def addfingerprintstodatabase (fingerprints): printToSong[holderfingerprint[0]] = (1,holderfingerprint[1]) + + + \ No newline at end of file