-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
audio: Resampling in chunks produces different results than resampling complete buffer #7358
Comments
Also the usual chorus of "the libsamplerate path doesn't have this problem" applies, which makes we wonder if our time is better spent asking @erikd if we can use it under the zlib license and just integrate it into SDL's code. :/ |
At this point, maybe that's a good idea... |
I am the original author of libsamplerate but I am no longer the maintainer and almost certainly not the sole copyright owner. I therefore do not have the authority to change the license or provide exceptions. |
@icculus, I've looked a little bit. libsamplerate:
SDL:
maybe the solution, would be simply to clamp more what has to be generated |
Looking again, and maybe here's a suggestion to improve. In chunk mode: Then, the right padding is copied back to the left. but we should start to process more on the left padding. (maybe that just move the issue of calculation the number of frame to another place ...). Maybe the API, to get the converted data should tell if we should never reach the right-padding, or we have to process it.
in 1 shot: |
This applies to SDL2 and SDL3, but this test program happens to use SDL2 function names:
Basically, it loads a .wav file, resamples it to 48000Hz, and writes it to output.raw.
If you run the
#if 0
block, you'll get all the audio resampled in a single operation. If you recompile with the#else
block, it'll resample the audio in chunks.In the latter case, we produce slightly less data. It's drifting by around 60 bytes per megabyte of audio provided (s16, mono, 44100Hz, resampled to 48000Hz).
I suspect the culprit is this line:
SDL/src/audio/SDL_audiocvt.c
Line 299 in 1e5e8e2
When it has the entire buffer to work from, it comes up with a reasonable output buffer size as a one-time operation, but when it resamples in chunks, we're losing a few bytes here and there for each operation (and maybe accumulating extra bytes in the other direction, too, perhaps).
Not only is this inconsistent, I believe it's causing audio artifacts at these edges.
We need a better way to calculate output size here.
(and while it won't fix this problem in a case where we are actually streaming, maybe we should only convert the audio when the data is requested from the stream, instead of as it is pushed into the stream.)
The text was updated successfully, but these errors were encountered: