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

LPF destroys data on the source buffer #5

Open
j1elo opened this issue Jul 1, 2022 · 0 comments
Open

LPF destroys data on the source buffer #5

j1elo opened this issue Jul 1, 2022 · 0 comments

Comments

@j1elo
Copy link

j1elo commented Jul 1, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant