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

resampler for a live-signal #243

Open
reFX-Mike opened this issue Feb 11, 2025 · 1 comment
Open

resampler for a live-signal #243

reFX-Mike opened this issue Feb 11, 2025 · 1 comment

Comments

@reFX-Mike
Copy link

Apologies if I'm being dense here, but I can't figure out how to use the resampler of only parts of a continuous signal.

My use case: I have an audio-app that plays back a buffer and adds some FX. I only render e.g. 512 samples at a time but my internal sample-rate is always 44.1 kHz, whereas the audio-card may wants 48 kHz, or 96 kHz or whatever.

So I need to fill 512 samples at 96 kHz, and now I need to feed in 235.2 audio-samples into the resampler. What do I do with the 0.2 samples left over? I need to roll this into the next call, but the resampler-class doesn't know anything about that. I think it always assume that you resample an entire buffer, all in one go, instead of parts of it over multiple calls. Or does it's filters continue from their previous state?

Again: maybe I'm being dense here, but I can't figure out how to write a FIFO buffer for the KFR resampler.

I want to feed in as much data as required to get "N" output samples, and then do that over and over, feeding data in as needed.

@dancazarin
Copy link
Member

First, sorry for the late reply.

The resampler class can process signals split into buffers of different sizes by maintaining an internal state.
Note that you should use the same instance of the samplerate_converter class for all subsequent calls for the same continuous signal, rather than creating a new instance for every fragment. Therefore, you should create two instances (one per channel) for stereo audio.

In your case, simply call input_size_for_output, passing the desired output buffer length to get the required input buffer size for the next call to process.
It will return either 236 or 235 samples in your case.

The process function takes two parameters:

  • output: Output buffer. Pass a univector with the desired size (512).
  • input: Input buffer. Pass a univector of the size returned by input_size_for_output or greater. The resampler consumes as many samples as needed to produce 512 output samples and returns the number of input samples read as the result of the process call. Adjust the input accordingly to skip these samples.

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

2 participants