Skip to content

Commit dc1af3b

Browse files
committed
Depending on python version and hardware the DEFAULT_BUFFER_SIZE which
we use to ingest/feed in fingerprinting can influence the generated fingerprints. This fixes the issue by only consuming the expected samples.
1 parent 7ce306c commit dc1af3b

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

acoustid.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -222,12 +222,21 @@ def fingerprint(samplerate, channels, pcmiter, maxlength=MAX_AUDIO_LENGTH):
222222
fper = chromaprint.Fingerprinter()
223223
fper.start(samplerate, channels)
224224

225-
position = 0 # Samples of audio fed to the fingerprinter.
226-
for block in pcmiter:
227-
fper.feed(block)
228-
position += len(block) // 2 # 2 bytes/sample.
229-
if position >= endposition:
225+
position = 0
226+
while position < endposition:
227+
try:
228+
block = next(pcmiter)
229+
except StopIteration:
230+
# No more data
230231
break
232+
233+
# Calculate remaining samples needed
234+
remaining = endposition - position
235+
# Feed only up to remaining samples
236+
bytes_to_feed = min(len(block), remaining * 2)
237+
fper.feed(block[:bytes_to_feed])
238+
position += bytes_to_feed // 2
239+
231240

232241
return fper.finish()
233242
except chromaprint.FingerprintError:

0 commit comments

Comments
 (0)