Skip to content

LPF destroys data on the source buffer #5

@j1elo

Description

@j1elo

I have a Buffer with 48kHz audio as PCM signed 16-bit little-endian (FFmpeg format s16le). Then I'm doing this simple test to find out that the resample function is affecting the source data:

while (...) {
  const audioBuffer = Buffer.from(...);
  const resampled = WaveResampler.resample(audioBuffer, 48000, 16000, {
    LPF: true,
  });
  // `resampled` is not used. `audioBuffer` has been modified but it shouldn't.
  fs.appendFileSync("/tmp/test.raw", audioBuffer);
}

Now playing this audio with FFmpeg, the audio contents have been destroyed and everything is just noise, except that the original audio can be kind of noticed very subtle in the background:

ffplay -f s16le -ar 48k -ac 1 /tmp/test.raw

Setting LPF: false avoids the issue. The mistake seems to be in the downsample_() function, which saves data directly into the source buffer, when I believe it shouldn't:

samples[i]  = filter.filter(samples[i]);

As it is, no LPF downsampling can be done with this library with default settings, because the resulting audio is garbled.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions