audio-stretch icon indicating copy to clipboard operation
audio-stretch copied to clipboard

Does it work with audio stream?

Open maciejmakowski2003 opened this issue 6 months ago • 1 comments

I have audio engine that should get 128 frames each cycle, so if I want to stretch sound twice I will have access to 256 frames. Will it work well in that case?

maciejmakowski2003 avatar Jul 03 '25 09:07 maciejmakowski2003

Yes, it should work well for that case, with one caveat.

What you will have to do is provide an output buffer because the library only outputs audio when it detects a complete harmonic cycle. So for many calls providing 128 frames of audio to the library you might get nothing back, and then one time you might get 500 samples. However, over the long term you will get exactly twice as many samples out as you put in. So there's an implicit delay that you have to compensate for. Once your buffer has enough delay, then you can always have 256 stretched samples for each 128 samples put in.

There is a function called stretch_output_capacity() that will tell you the maximum number of frames that you might receive from one call to stretch_samples(). This should give you a good idea of the amount of the required delay.

Let me know if you need any more clarification.

dbry avatar Jul 04 '25 20:07 dbry