X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=vg%2Fvg_audio.h;h=aefc0fc81cd0693688a125304877a15ae354be39;hb=75a3b6f858d49acc38de2fda22133b218760d6f0;hp=0c9a666691e64f62f4926041d41f4fc0679e33cf;hpb=3a55f20f6b627db61294523f7bf34344514e7166;p=fishladder.git diff --git a/vg/vg_audio.h b/vg/vg_audio.h index 0c9a666..aefc0fc 100644 --- a/vg/vg_audio.h +++ b/vg/vg_audio.h @@ -625,20 +625,14 @@ static void sfx_set_init( sfx_set *dest, char *sources ) sfx_set_strings( dest, sources, dest->flags, 0 ); } -// Pick a random sound from the buffer and play it into system -static void sfx_set_playrnd( sfx_set *source, sfx_system *sys, int min_id, int max_id ) +static void sfx_set_play( sfx_set *source, sfx_system *sys, int id ) { - if( !source->numsegments ) - return; - - int pick = (rand() % (max_id-min_id)) + min_id; - if( sfx_begin_edit( sys ) ) { sys->fadeout = 0; sys->source = source->main; - sys->cur = source->segments[ pick*2 + 0 ]; - sys->end = source->segments[ pick*2 + 1 ]; + sys->cur = source->segments[ id*2 + 0 ]; + sys->end = source->segments[ id*2 + 1 ]; sys->ch = source->ch; // Diagnostics @@ -650,6 +644,23 @@ static void sfx_set_playrnd( sfx_set *source, sfx_system *sys, int min_id, int m } } +// Pick a random sound from the buffer and play it into system +static void sfx_set_playrnd( sfx_set *source, sfx_system *sys, int min_id, int max_id ) +{ + if( !source->numsegments ) + return; + + if( max_id > source->numsegments ) + { + vg_error( "Max ID out of range for playrnd\n" ); + return; + } + + int pick = (rand() % (max_id-min_id)) + min_id; + + sfx_set_play( source, sys, pick ); +} + static void sfx_system_fadeout( sfx_system *sys, u32 length_samples ) { if( sfx_begin_edit( sys ) )