Skip to content

Commit 89c3be3

Browse files
committed
fix(audio): zero-fill FFT buffer tail after partial frame read
When ReadNextFrame returns fewer samples than the buffer size, the tail contains stale samples from the previous iteration, contaminating frequency analysis. Add clear() call after the partial-frame copy to zero-fill the tail, matching the pattern already used in Pass 2 (rendering). Signed-off-by: Martin Wimpress <code@wimpress.io>
1 parent 68154fc commit 89c3be3

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

internal/audio/analyzer.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ func AnalyzeAudio(filename string, progressCb ProgressCallback) (*Profile, error
140140
// Shift buffer left by samplesPerFrame, append new samples
141141
copy(fftBuffer, fftBuffer[samplesPerFrame:])
142142
copy(fftBuffer[config.FFTSize-samplesPerFrame:], frameBuf[:nRead])
143+
if nRead < samplesPerFrame {
144+
clear(fftBuffer[config.FFTSize-samplesPerFrame+nRead:])
145+
}
143146
}
144147

145148
// Set actual frame count and duration

0 commit comments

Comments
 (0)