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 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)) -