allow other channel for non-dsp sounds (2D oneshots) labs
authorhgn <hgodden00@gmail.com>
Tue, 9 Apr 2024 16:30:29 +0000 (17:30 +0100)
committerhgn <hgodden00@gmail.com>
Tue, 9 Apr 2024 16:30:29 +0000 (17:30 +0100)
vg_audio.c
vg_audio.h

index 1611a622e86ccdbe7782bf3235e697219eee4bb9..de57c9fc970479d9c9ebee52500f684346172050 100644 (file)
@@ -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; i<frame_count*2; i ++ )
       pOut32F[i] = 0.0f;
 
-   for( int i=0; i<AUDIO_LFOS; i++ ){
+   for( int i=0; i<AUDIO_LFOS; i++ )
+   {
       audio_lfo *lfo = &vg_audio.oscillators[i];
       lfo->time_startframe = lfo->time;
    }
 
-   for( int i=0; i<AUDIO_CHANNELS; i ++ ){
-      audio_channel *ch = &vg_audio.channels[i];
+   for( int j=0; j<2; j++ )
+   {
+      for( int i=0; i<AUDIO_CHANNELS; i ++ )
+      {
+         audio_channel *ch = &vg_audio.channels[i];
 
-      if( ch->activity == 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; i<frame_count; i++ )
-         vg_dsp_process( pOut32F + i*2, pOut32F + i*2 );
-      vg_profile_end( &_vg_prof_dsp );
+      if( use_dsp  )
+      {
+         if( j==0 )
+         {
+            vg_profile_begin( &_vg_prof_dsp );
+            for( int i=0; i<frame_count; i++ )
+               vg_dsp_process( pOut32F + i*2, pOut32F + i*2 );
+            vg_profile_end( &_vg_prof_dsp );
+         }
+      }
+      else
+         break;
    }
 
    audio_lock();
 
-   for( int i=0; i<AUDIO_CHANNELS; i ++ ){
+   for( int i=0; i<AUDIO_CHANNELS; i ++ )
+   {
       audio_channel *ch = &vg_audio.channels[i];
       ch->readable_activity = ch->activity;
    }
index 66a4fdb35af1b61fcf985048c93502b3fac2b992..ba103481b95ee486563fa912533a450885241fa2 100644 (file)
@@ -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