Capturing DSP/Recording Bus Output to Create FMOD Sound

Hello!

I’m looking into the '‘correct’ way of capturing a bus’s output then playing it back, not sure if attaching dsp to a bus or using the wavwriter is the correct way, but ideally the fastest would be better as I want to simulate a loop pedal, capturing game audio then creating a sound with it (loop it etc) and play back as soon as we stop capture.

I’d say I was lower intermidiate with scripting so I’m happy to dive in and learn anything but a relatively simple solution would be better haha

If anyone can point me in the right direction it’d be much appreciated!

Many thanks!

Hi! Apologies for the delayed response.

Based on what you’ve described, I think using a capture DSP would likely be the best option, since WAVWRITER specifically writes the output of the entire system to file, and while used doesn’t output any audio to your audio devices.

With a capture DSP, you would place it on a bus’ underlying channel group to capture audio for a specified time. When capturing is then disabled, the captured audio data would be either stored in memory or written to file, and can the be played back using a programmer instrument in the Studio API, or as a sound using the Core API.

If you were wanting to play back the captured data from memory, you’d likey want to use a combination of FMOD_OPENMEMORY and FMOD_OPENRAW to open the sound. Writing to file simplifies this process, but also requires extra code to actually write the audio data and WAV header - a Unity C# example of this can be found here, and a C++ example here.

If you have any further questions or run into any issues, feel free to let me know.

Hey Leah,

Thanks so much for the response! Indeed the example script from the other forum post worked beautifully thanks so much! However there’s a slight problem, in the example script after pressing the button to stop the recording we write to a file, I’ve then created a sound and passed the file path to it for playback but there’s a touch of latency there so when looping the file back it staggers at the start of the loop due to silence at the start of the file.

Would it be quicker to play back straight from memory? and if so how could I modify the script to do that?

I want to simulate a loop pedal so playback and looping needs to be snappy and on beat. Saving the data to file can be done when the player stops recording.

Thanks so much!

You may wish to try using a different sound mode, such as a stream, which may help cut down on any initial loading/decompressing. Playing back straight from memory could help, and it would involve keeping the sound data in the array instead of writing it to disk, and passing it to the Sytem::createSound(). ChannelControl::setDelay can also be used for sample-accurate scheduling, which may help.

Alternatively, using a programmer sound might help with the scheduling side of things, especially if you’re using the Studio API already and have existing events playing that you want to synchronize with. In this case, you’d want to use a programmer sound creation callback, which you can use to create a pass a sound to a programmer instrument as it’s about to start playing - you can take a look at the programmer_sound Studio API example from the FMOD Engine installer, or at our Unity Programmer Sounds example script for examples of this.