Hi! Looking for expert advice on how to do this with FMOD Core API: Looping sound you can toggle on and off at will, cleanly (no pops or clicks) in a game. Typical use cases: engine exhaust sound effect of a player controlled ship in an Asteroids clone, or very short looping tune (1-2 seconds) that loops while a player is temporarily invicible in a platformer after he picked up a specific item (like Mario Bros star item).
Things I know (for context):
I know you set a sound as looping when creating it. And how to play it and stop it. It works but since you get a waveform discontinuity at sound stop you get pops.
I know audio timing must be done with the dsp clock, not game side clocks using performance counters. I also know fading (especially short ones) must be done at the sample level. Not by manipulating volume game side.
I know you can add fade points to a channel to setup fadeins and fadeouts using the dsp clock. I think internally the fade points must manipulate the envelope of the channel. This works but as far as I know you can’t really schedule a fadein while in the middle of a fadeout with this system. This is the pain point: Be able to fadein the channel to a target level while being in the middle of a fadeout to zero, starting the fadein at the current enveloppe level. Same thing for fading out while in the middle of a fadein.
A workaround I found is to enable the volume fade ramp of the looping sound channel and just set the volume to 0.0f or 1.0f to “toggle” the looping sound. Effectively, you never actually stop the channel and only change its volume. The fade ramp avoids pops and clicks since the change in volume isn’t instantaneous. But the caveat is: since the sound is always looping, wether you hear it or not, you can’t control the looping sound playback position (for example you can’t reset the sound playback at the beginning of the sound sample when you set the channel volume to 1.0f to “toggle it on”).
I’m a little confused and would like to know about the correct ways to think about this ( theory ) and the proper use of the API this kind of use case. I’ve recently dabbled into low level audio with WASAPI, for now making a very simplistic synth so I can educate myself enough to be able to talk about audio in a meaningful way.
Thank you for taking the time to read my message. Hope it makes sense ![]()