Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use hash bits more effectively #69

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions audfprint_analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,12 @@ def __init__(self, density=DENSITY):
# Limit the num of pairs we'll make from each peak (Fanout)
self.maxpairsperpeak = 3
# Values controlling peaks2landmarks
# +/- 31 bins in freq (LIMITED TO -32..31 IN LANDMARK2HASH)
self.targetdf = 31
# +/- 32 bins in freq (LIMITED TO -32..31 IN LANDMARK2HASH)
self.targetdf = 32
# min time separation (traditionally 1, upped 2014-08-04)
self.mindt = 2
# max lookahead in time (LIMITED TO <64 IN LANDMARK2HASH)
self.targetdt = 63
self.targetdt = 65
# global stores duration of most recently-read soundfile
self.soundfiledur = 0.0
# .. and total amount of sound processed
Expand Down Expand Up @@ -277,7 +277,7 @@ def find_peaks(self, d, sr):
a_dec = (1 - 0.01 * (self.density * np.sqrt(self.n_hop / 352.8) / 35)) ** (1 / OVERSAMP)
# Take spectrogram
mywin = np.hanning(self.n_fft + 2)[1:-1]
sgram = np.abs(stft.stft(d, n_fft=self.n_fft,
sgram = np.abs(stft.stft(d, n_fft=self.n_fft+2,
hop_length=self.n_hop,
window=mywin))
sgrammax = np.max(sgram)
Expand All @@ -289,10 +289,10 @@ def find_peaks(self, d, sr):
# zero. Not good, but let's let it through for now.
print("find_peaks: Warning: input signal is identically zero.")
# High-pass filter onset emphasis
# [:-1,] discards top bin (nyquist) of sgram so bins fit in 8 bits
# [1:-1,] discards bottom (0hz) and top (nyquist) bins of sgram so bins fit in 8 bits
sgram = np.array([scipy.signal.lfilter([1, -1],
[1, -HPF_POLE ** (1 / OVERSAMP)], s_row)
for s_row in sgram])[:-1, ]
for s_row in sgram])[1:-1, ]
# Prune to keep only local maxima in spectrum that appear above an online,
# decaying threshold
peaks = self._decaying_threshold_fwd_prune(sgram, a_dec)
Expand Down Expand Up @@ -329,15 +329,16 @@ def peaks2landmarks(self, pklist):
for peak in peaks_at[col]:
pairsthispeak = 0
for col2 in range(col + self.mindt,
min(scols, col + self.targetdt)):
min(scols, col + self.targetdt + 1)):
if pairsthispeak < self.maxpairsperpeak:
for peak2 in peaks_at[col2]:
if abs(peak2 - peak) < self.targetdf:
df = peak2 - peak
if -self.targetdf <= df and df < self.targetdf:
# and abs(peak2-peak) + abs(col2-col) > 2 ):
if pairsthispeak < self.maxpairsperpeak:
# We have a pair!
landmarks.append((col, peak,
peak2, col2 - col))
peak2, col2 - col - self.mindt))
pairsthispeak += 1

return landmarks
Expand Down