# DSP plugin, Need help implementing a time stretching library into FMOD

**URL:** <https://qa.fmod.com/t/dsp-plugin-need-help-implementing-a-time-stretching-library-into-fmod/20164>\
**Category:** FMOD Engine\
**Tags:** unity, csharp, cpp\
**Created:** [April 25, 2023, 8:29am UTC](https://qa.fmod.com/t/dsp-plugin-need-help-implementing-a-time-stretching-library-into-fmod/20164 "2023-04-25T08:29:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kr29003](https://avatars.discourse-cdn.com/v4/letter/k/b487fb/32.png) [@kr29003](https://qa.fmod.com/u/kr29003)\
**Post date:** [April 25, 2023, 8:29am UTC](https://qa.fmod.com/t/dsp-plugin-need-help-implementing-a-time-stretching-library-into-fmod/20164/1 "2023-04-25T08:29:23Z")

</div>

Hi! Been playing around with FMOD for a few days while evaluating it for a possible migration for our game and it’s been awesome.

For our game we need the ability to slow down or up multiple audio files in realtime to limits not possible with the workaround that most people are using to timestretch (10% of the original audio file length up to 1000%) as that is currently a feature on our live version of that game on which we are using another audio library.

So we are looking into implementing the RubberBand time stretching library running in realtime mode for this. We’ve got a DSP plugin up and running with the slowing down part working almost perfectly, the main issue, which is where i need help, is on the speed ups.

So, the library (as described in here [Rubber Band Audio Time Stretcher Library](https://breakfastquay.com/rubberband/integration.html)) outputs less samples than what I give to it on the dsp read call when speeding up the audio. (eg, I receive 512 samples from FMOD, I only get back 170 from the timestretch library). The regular way of working around this is to just request more samples from the audio library on the same call on a while loop and feed the time stretching library until I get enough samples to avoid buffer underruns. But after looking at the FMOD docs for 2 full days, it doesn’t seem like it is possible to do that ☹ .

Is there a way I can get more samples that what FMOD gave to me mid dsp read while being hooked to a ChannelGroup in realtime? Or maybe is there an alternative way to implement this library? I saw that you could in theory get the base sound object and use sound::read, but our issue with that is that; 1.- It doesn’t seem like you can do that from inside the dsp plugin 2.- We are playing multiple tracks at the same time that need to be timestretched. We would probably run into issues if we try to timestretch multiple sounds instead of just the channelgroup output, which is the mix of all those sounds.

Thanks in advance!

Karla

---

<div class="post-metadata">

**Author:** ![jeff\_fmod](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/jeff_fmod/32/1766_2.png) [@jeff\_fmod](https://qa.fmod.com/u/jeff_fmod)\
**Post date:** [May 1, 2023, 1:53am UTC](https://qa.fmod.com/t/dsp-plugin-need-help-implementing-a-time-stretching-library-into-fmod/20164/2 "2023-05-01T01:53:15Z")

</div>

Unfortunately you cannot speed up the rate of the dsp read callback dynamically, due to limitations with the design of our resampling system.  
Perhaps you could try calling `Sound::read` on your sound to retrieve the full audio buffer, and pass in a pointer to the buffer in [`DSP::setUserData`](https://fmod.com/docs/2.02/api/core-api-dsp.html#dsp_setuserdata). Then during your [`FMOD_DSP_READ_CALLBACK`](https://fmod.com/docs/2.02/api/plugin-api-dsp.html#fmod_dsp_read_callback) you can access the full audio buffer through `dsp_state->plugindata`. There would be additional challenges with accessing the full audio buffer from a stream, but for shorter sounds, or longer sounds that you don’t mind keeping in memory, it should allow you to perform faster-than-realtime time stretching.

---

<div class="post-metadata">

**Author:** ![kr29003](https://avatars.discourse-cdn.com/v4/letter/k/b487fb/32.png) [@kr29003](https://qa.fmod.com/u/kr29003)\
**Post date:** [May 1, 2023, 12:37pm UTC](https://qa.fmod.com/t/dsp-plugin-need-help-implementing-a-time-stretching-library-into-fmod/20164/3 "2023-05-01T12:37:18Z")

</div>

Thanks, but would it be possible somehow to do that but for the full mix? As I mentioned in the post, we have multiple sounds playing at the same time and having an stretcher calling sound::read on each sound would probably hurt performance. So ideally we would do that with the channelgroup instead.

---

<div class="post-metadata">

**Author:** ![jeff\_fmod](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/jeff_fmod/32/1766_2.png) [@jeff\_fmod](https://qa.fmod.com/u/jeff_fmod)\
**Post date:** [May 2, 2023, 5:49am UTC](https://qa.fmod.com/t/dsp-plugin-need-help-implementing-a-time-stretching-library-into-fmod/20164/4 "2023-05-02T05:49:42Z")

</div>

Currently there is no equivalent to `Sound::read` that can be used on a `ChannelGroup` and will let you read samples faster than realtime. I have let the Dev team know of this limitation and suggested implementing a means of calling the mixer multiple times as you have suggested- thank you for bringing this to our attention.

In the meantime, you could potentially try calling [`ChannelControl::setPitch`](https://fmod.com/docs/2.02/api/core-api-channelcontrol.html#channelcontrol_setpitch) to speed up playback of the entire `ChannelGroup` instead of going through Rubber Band, and just use Rubber Band for slowing down audio?
