mackron / miniaudio

Audio playback and capture library written in C, in a single source file.
https://miniaud.io
Other
4.07k stars 361 forks source link

Fade equivalents of `ma_sound_set_start_time_*` #669

Closed npisanti closed 1 year ago

npisanti commented 1 year ago

It would be nice to be able to schedule fades like this

void ma_sound_set_fade_start_in_pcm_frames(ma_sound* pSound, float volumeBeg, float volumeEnd, ma_uint64 absoluteGlobalTimeInFrames, ma_uint64 fadeLengthInFrames);
void ma_sound_set_fade_start_in_milliseconds(ma_sound* pSound,  float volumeBeg, float volumeEnd, ma_uint64 absoluteGlobalTimeInMilliseconds, ma_uint64 fadeLengthInMilliseconds);

this would let sync the fade out of a sound with the triggering of another sound (expecially useful for choking percussions), or it could also be useful to sync a fade in with a fade out.

Having a fadeout parameter to ma_sound_set_stop_time_in_pcm_frames() could also be another viable solution, as most of the time you don't want the sounds to stop abruptly with a click.

mackron commented 1 year ago

I think both of your suggestions are reasonable. Certainly I've had people ask how to stop popping sounds when stopping and I've just flippantly said fade it out, so having a way to fade out and stop would be nice.

Will leave this ticket open. No timeframe on when I'll get to this.

mackron commented 1 year ago

I've added initial implementations of ma_sound_set_fade_start_in_pcm_frames() and ma_sound_set_fade_start_in_milliseconds() to the dev branch. Only difference with your proposal is the start time is the last parameter. I've only done limited testing so far.

mackron commented 1 year ago

I've also added support for stopping with a fade out. See commit message for details: https://github.com/mackron/miniaudio/commit/53907863c7b5ff2debf7106c1d6648f7fb6232e3. This is in the dev branch.

npisanti commented 1 year ago

Thank you very much for adding this feature, I will test it as soon as i'm updating the libraries on some of my projects =)