audio ui stuffs
authorhgn <hgodden00@gmail.com>
Wed, 5 Mar 2025 11:42:36 +0000 (11:42 +0000)
committerhgn <hgodden00@gmail.com>
Wed, 5 Mar 2025 11:42:36 +0000 (11:42 +0000)
vg_audio.c
vg_audio.h

index 77d5eb591648a96a2d862b21a126e32407f3df9c..e39ab802009a1a41ff153998def4fce1c34c8058 100644 (file)
@@ -317,6 +317,8 @@ audio_channel_id vg_audio_get_first_idle_channel(void)
          channel->clip = NULL;
          channel->ui_volume = 0;
          channel->ui_pan = 0;
+         channel->ui_spacial_volume = 0;
+         channel->ui_spacial_pan = 0;
          channel->ui_activity = k_channel_activity_wake;
 
          struct audio_channel_controls *controls = get_audio_channel_controls( id );
@@ -537,6 +539,15 @@ audio_channel_id vg_audio_crossfade( audio_channel_id id, audio_clip *new_clip,
    return new_id;
 }
 
+bool vg_audio_is_channel_using_clip( audio_channel_id id, audio_clip *clip )
+{
+   vg_audio_assert_lock();
+   audio_channel *channel = get_audio_channel( id );
+
+   if( channel->clip == clip ) return 1;
+   else return 0;
+}
+
 void vg_audio_fadeout_flagged_audio( u32 flag, f32 length )
 {
    vg_audio_lock();
@@ -599,7 +610,7 @@ void vg_audio_oneshot( audio_clip *clip, f32 volume, f32 pan, u16 group, u32 fla
       vg_audio_set_channel_clip( id, clip );
       vg_audio_set_channel_group( id, group );
       vg_audio_set_channel_volume( id, volume, 1 );
-      vg_audio_set_channel_pan( id, volume, 1 );
+      vg_audio_set_channel_pan( id, pan, 1 );
       vg_audio_add_channel_flags( id, AUDIO_FLAG_RELINQUISHED );
       vg_audio_start_channel( id );
    }
@@ -1102,6 +1113,8 @@ static void _vg_audio_mixer( void *user, u8 *stream, int byte_count )
       channel->ui_activity = state->activity;
       channel->ui_volume = state->volume;
       channel->ui_pan = state->pan;
+      channel->ui_spacial_volume = state->spacial_volume;
+      channel->ui_spacial_pan = state->spacial_pan;
 
       if( controls->flags & AUDIO_FLAG_RELINQUISHED )
       {
@@ -1204,6 +1217,7 @@ static void cb_vg_audio_view( ui_context *ctx, ui_rect rect, struct vg_magi_pane
             vg_strcatch( &str, (flags & AUDIO_FLAG_WORLD)? 'W': '_' );
             vg_strcatch( &str, (flags & AUDIO_FLAG_NO_DOPPLER)? '_':'D' );
             vg_strcatch( &str, (flags & AUDIO_FLAG_NO_DSP)? '_':'E' );
+            vg_strcatch( &str, (flags & AUDIO_FLAG_LOOP)? 'L':'_' );
 
             const char *formats[] =
             {
@@ -1240,7 +1254,7 @@ static void cb_vg_audio_view( ui_context *ctx, ui_rect rect, struct vg_magi_pane
             vg_strcat( &str, activties[channel->ui_activity] );
 
             vg_strcat( &str, " " );
-            f32 volume = audio_volume_integer_to_float( channel->ui_volume );
+            f32 volume = (f32)channel->ui_volume / (f32)AUDIO_VOLUME_100;
             vg_strcati32r( &str, volume * 100.0f, 3, ' ' );
             vg_strcatch( &str, '%' );
 
@@ -1250,16 +1264,45 @@ static void cb_vg_audio_view( ui_context *ctx, ui_rect rect, struct vg_magi_pane
             ui_rect row_l, row_r;
             ui_split( row, k_ui_axis_v, 32, 2, row_l, row_r );
             
-            //ui_rect indicator_l, indicator_r;
-            //ui_split_ratio( row, k_ui_axis_v, 0.5f, 1, indicator_l, indicator_r );
+            ui_rect indicator_l, indicator_r;
+            ui_split_ratio( row_l, k_ui_axis_v, 0.5f, 1, indicator_l, indicator_r );
+
+            ui_fill( ctx, indicator_l, 0xff000000 );
+            if( volume > 0.01f )
+            {
+               f32 h = volume * (f32)indicator_l[3];
+               ui_rect vol_bar = { indicator_l[0], indicator_l[1] + indicator_l[3] - h, indicator_l[2], h };
+               ui_fill( ctx, vol_bar, 0xff00ff00 );
+
+               if( flags & AUDIO_FLAG_SPACIAL_3D )
+               {
+                  f32 h = ((f32)channel->ui_spacial_volume / (f32)AUDIO_VOLUME_100) * (f32)indicator_l[3];
+                  ui_rect space_bar = { indicator_l[0], indicator_l[1] + indicator_l[3] - h, indicator_l[2], 1 };
+                  ui_fill( ctx, space_bar, 0xffffffff );
+               }
+            }
 
-            //f32 volume = audio_volume_integer_to_float( channel->ui_volume );
-            //ui_rect vol_bar;
-            //ui_split_ratio( indicator_l, k_ui_axis_h, -volume, 0, vol_bar, indicator_l );
-            //ui_fill( ctx, indicator_l, 0xff000000 );
-            //ui_fill( ctx, vol_bar, 0xff00ff00 );
+            f32 pan = (f32)channel->ui_pan / (f32)AUDIO_PAN_RIGHT_100;
+            ui_fill( ctx, indicator_r, 0xff111111 );
+            f32 midpoint = (f32)indicator_r[0] + (f32)indicator_r[2] * 0.5f;
+
+            f32 pan_abs = fabsf(pan);
+            if( pan_abs > 0.01f )
+            {
+               ui_rect bar = { midpoint,indicator_r[1], pan_abs * (f32)indicator_r[2] * 0.5f, indicator_r[3] };
+               
+               if( pan < 0.0f )
+                  bar[0] -= (f32)bar[2];
 
-            //ui_fill( ctx, indicator_r, 0xff111111 );
+               ui_fill( ctx, bar, 0xff00aaff );
+            }
+
+            if( flags & AUDIO_FLAG_SPACIAL_3D )
+            {
+               f32 w = ((f32)channel->ui_spacial_pan / (f32)AUDIO_PAN_RIGHT_100) * (f32)indicator_r[2] * 0.5f;
+               ui_rect space_bar = { midpoint+w, indicator_r[1], 1, indicator_r[3] };
+               ui_fill( ctx, space_bar, 0xffffffff );
+            }
             
             ui_fill( ctx, row_r, 0xa0000000 | channel->ui_colour );
             ui_text( ctx, row_r, buf, 1, k_ui_align_middle_left, 0 );
index 6a25d7cd1820921e6d2fcb00434a8f55fd44b9eb..87414c8c66fe9045011448768580320d36dd71d1 100644 (file)
@@ -130,6 +130,8 @@ struct audio_channel
    char ui_name[32];
    u32  ui_colour;
    i32  ui_volume, ui_pan;
+   f32  ui_spacial_volume, ui_spacial_pan;
+
    enum channel_activity ui_activity;
    u16 group;
 
@@ -246,3 +248,4 @@ void vg_audio_oneshot( audio_clip *clip, f32 volume, f32 pan, u16 group, u32 fla
 /* half measures... Don't expect these functions to stay. */
 void vg_audio_fadeout_flagged_audio( u32 flag, f32 length );
 bool vg_audio_flagged_stopped( u32 flag );
+bool vg_audio_is_channel_using_clip( audio_channel_id id, audio_clip *clip );