From 0b8f57a12f41b67b6f088fb56855a0a70ecc7ca8 Mon Sep 17 00:00:00 2001 From: hgn Date: Tue, 9 Apr 2024 17:30:29 +0100 Subject: [PATCH] allow other channel for non-dsp sounds (2D oneshots) --- vg_audio.c | 78 +++++++++++++++++++++++++++++++++++++----------------- vg_audio.h | 1 + 2 files changed, 55 insertions(+), 24 deletions(-) diff --git a/vg_audio.c b/vg_audio.c index 1611a62..de57c9f 100644 --- a/vg_audio.c +++ b/vg_audio.c @@ -360,11 +360,12 @@ int audio_oneshot_3d( audio_clip *clip, v3f position, f32 range, f32 volume ) audio_require_lock(); audio_channel *ch = audio_get_first_idle_channel(); - if( ch ){ + if( ch ) + { audio_channel_init( ch, clip, AUDIO_FLAG_SPACIAL_3D ); audio_channel_set_spacial( ch, position, range ); audio_channel_edit_volume( ch, volume, 1 ); - ch = audio_relinquish_channel( ch ); + audio_relinquish_channel( ch ); return 1; } @@ -377,10 +378,11 @@ int audio_oneshot( audio_clip *clip, f32 volume, f32 pan ) audio_require_lock(); audio_channel *ch = audio_get_first_idle_channel(); - if( ch ){ - audio_channel_init( ch, clip, 0x00 ); + if( ch ) + { + audio_channel_init( ch, clip, AUDIO_FLAG_NO_DSP ); audio_channel_edit_volume( ch, volume, 1 ); - ch = audio_relinquish_channel( ch ); + audio_relinquish_channel( ch ); return 1; } @@ -875,39 +877,67 @@ static void audio_mixer_callback( void *user, u8 *stream, int byte_count ){ for( int i=0; itime_startframe = lfo->time; } - for( int i=0; iactivity == k_channel_activity_alive ){ - if( ch->_.lfo ) - ch->_.lfo->time = ch->_.lfo->time_startframe; + if( use_dsp ) + { + if( ch->flags & AUDIO_FLAG_NO_DSP ) + { + if( j==0 ) + continue; + } + else + { + if( j==1 ) + continue; + } + } + + if( ch->activity == k_channel_activity_alive ) + { + if( ch->_.lfo ) + ch->_.lfo->time = ch->_.lfo->time_startframe; - u32 remaining = frame_count, - subpos = 0; + u32 remaining = frame_count, + subpos = 0; - while( remaining ){ - audio_channel_mix( ch, pOut32F+subpos ); - remaining -= AUDIO_MIX_FRAME_SIZE; - subpos += AUDIO_MIX_FRAME_SIZE*2; + while( remaining ) + { + audio_channel_mix( ch, pOut32F+subpos ); + remaining -= AUDIO_MIX_FRAME_SIZE; + subpos += AUDIO_MIX_FRAME_SIZE*2; + } } } - } - if( use_dsp ){ - vg_profile_begin( &_vg_prof_dsp ); - for( int i=0; ireadable_activity = ch->activity; } diff --git a/vg_audio.h b/vg_audio.h index 66a4fdb..ba10348 100644 --- a/vg_audio.h +++ b/vg_audio.h @@ -17,6 +17,7 @@ #define AUDIO_FLAG_NO_DOPPLER 0x2 #define AUDIO_FLAG_SPACIAL_3D 0x4 #define AUDIO_FLAG_AUTO_START 0x8 +#define AUDIO_FLAG_NO_DSP 0x10 #define AUDIO_FLAG_FORMAT 0x1E00 enum audio_format -- 2.25.1