From 56dbcb529c4e291d5bb62ea6401d29f22db3644d Mon Sep 17 00:00:00 2001 From: David Reid Date: Sun, 16 Aug 2020 16:57:53 +1000 Subject: [PATCH] Add support for fading in to sound groups. --- research/ma_engine.c | 3 ++- research/ma_engine.h | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/research/ma_engine.c b/research/ma_engine.c index 22d1244f..dc783763 100644 --- a/research/ma_engine.c +++ b/research/ma_engine.c @@ -37,6 +37,7 @@ int main(int argc, char** argv) //ma_engine_sound_group_set_pan(&engine, NULL, -1); ma_engine_sound_group_set_pitch(&engine, NULL, 1.0f); + ma_engine_sound_group_set_fade_in(&engine, NULL, 4000); /*ma_engine_sound_set_volume(&engine, &sound, 0.25f);*/ //ma_engine_sound_set_pitch(&engine, &sound, 2.0f); @@ -58,7 +59,7 @@ int main(int argc, char** argv) ma_engine_play_sound(&engine, argv[3], NULL);*/ #endif -#if 1 +#if 0 float pitch = 1; float pitchStep = 0.01f; float pitchMin = 0.125f; diff --git a/research/ma_engine.h b/research/ma_engine.h index 624e4a24..f664ba77 100644 --- a/research/ma_engine.h +++ b/research/ma_engine.h @@ -997,6 +997,7 @@ MA_API ma_result ma_engine_sound_group_set_gain_db(ma_engine* pEngine, ma_sound_ MA_API ma_result ma_engine_sound_group_set_effect(ma_engine* pEngine, ma_sound_group* pGroup, ma_effect* pEffect); MA_API ma_result ma_engine_sound_group_set_pan(ma_engine* pEngine, ma_sound_group* pGroup, float pan); MA_API ma_result ma_engine_sound_group_set_pitch(ma_engine* pEngine, ma_sound_group* pGroup, float pitch); +MA_API ma_result ma_engine_sound_group_set_fade_in(ma_engine* pEngine, ma_sound_group* pGroup, ma_uint64 fadeTimeInMilliseconds); MA_API ma_result ma_engine_listener_set_position(ma_engine* pEngine, ma_vec3 position); MA_API ma_result ma_engine_listener_set_rotation(ma_engine* pEngine, ma_quat rotation); @@ -6554,6 +6555,19 @@ MA_API ma_result ma_engine_sound_group_set_pitch(ma_engine* pEngine, ma_sound_gr return MA_SUCCESS; } +MA_API ma_result ma_engine_sound_group_set_fade_in(ma_engine* pEngine, ma_sound_group* pGroup, ma_uint64 fadeTimeInMilliseconds) +{ + if (pEngine == NULL) { + return MA_INVALID_ARGS; + } + + if (pGroup == NULL) { + pGroup = &pEngine->masterSoundGroup; + } + + return ma_dual_fader_set_fade(&pGroup->effect.fader, 0, 0, 1, pGroup->effect.fader.timeInFramesCur, pGroup->effect.fader.timeInFramesCur + (fadeTimeInMilliseconds * pGroup->effect.fader.config.sampleRate) / 1000); +} + MA_API ma_result ma_engine_listener_set_position(ma_engine* pEngine, ma_vec3 position) {