fitting to new audio api
authorhgn <hgodden00@gmail.com>
Wed, 5 Mar 2025 00:52:11 +0000 (00:52 +0000)
committerhgn <hgodden00@gmail.com>
Wed, 5 Mar 2025 00:52:11 +0000 (00:52 +0000)
16 files changed:
src/audio.c
src/audio.h
src/ent_challenge.c
src/ent_objective.c
src/menu.c
src/metascene.c
src/player.c
src/player_ragdoll.c
src/player_skate.c
src/player_skate.h
src/player_walk.c
src/skaterift.c
src/world_audio.c
src/world_entity.c
src/world_load.c
src/world_map.c

index 766425051acac81ec3db6892fd4dc08eafe6510c..d5eaed1ceb7f955bd7119a8ffec45fdf49225410 100644 (file)
@@ -205,33 +205,23 @@ void audio_init(void)
    audio_clip_loadn( audio_challenge, VG_ARRAY_LEN(audio_challenge), NULL );
 
    vg_audio_lock();
-   audio_lfo *bump_lfo = vg_audio_get_first_idle_lfo();
-   VG_ASSERT( bump_lfo );
-
-   vg_audio_set_lfo_polynomial_bipolar( bump_lfo, 80.0f );
-   vg_audio_set_lfo_frequency( bump_lfo, 20.0f );
-
-   air_audio_data.channel = vg_audio_get_first_idle_channel();
-   VG_ASSERT( air_audio_data.channel );
-   audio_channel_init( air_audio_data.channel, &air_synth, 0 );
+   air_audio_data.channel_id = vg_audio_get_first_idle_channel();
+   VG_ASSERT( air_audio_data.channel_id );
 
+   vg_audio_set_channel_clip( air_audio_data.channel_id, &air_synth );
+   vg_audio_start_channel( air_audio_data.channel_id );
    vg_audio_unlock();
 }
 
 void audio_ambient_sprite_play( v3f co, audio_clip *clip )
 {
-   audio_lock();
+   vg_audio_lock();
    u16 group_id = 0xfff0;
-   audio_channel *ch = audio_get_group_idle_channel( group_id, 4 );
-
-   if( ch ){
-      audio_channel_init( ch, clip, AUDIO_FLAG_SPACIAL_3D );
-      audio_channel_group( ch, group_id );
-      audio_channel_set_spacial( ch, co, 80.0f );
-      audio_channel_edit_volume( ch, 1.0f, 1 );
-      ch = audio_relinquish_channel( ch );
+   if( vg_audio_count_channels_in_group( group_id ) < 4 )
+   {
+      vg_audio_oneshot_3d( clip, co, 80.0f, 1.0f, group_id, 0 );
    }
-   audio_unlock();
+   vg_audio_unlock();
 }
 
 enum audio_sprite_type world_audio_sample_sprite_random(v3f origin, v3f output);
index 95894f1cedbdb380637da05fbe888ae583a1e82f..11eb136e785b0914c23b6f225b20b5a52eea2908 100644 (file)
@@ -18,7 +18,7 @@ struct air_synth_data {
    SDL_SpinLock sl;
 
    /* not used in locking */
-   audio_channel *channel;
+   audio_channel_id channel_id;
 }
 extern air_audio_data;
 
index c7d5bdcafc0eccfe79d1847b26d9caa250dda8e8..265acfc4608eb02c8e6959449bf6535588fca7c7 100644 (file)
@@ -151,9 +151,9 @@ void ent_challenge_update(void)
             next = objective->id_next;
             v3_fill( objective->transform.s, 1.0f );
          }
-         audio_lock();
-         audio_oneshot( &audio_challenge[5], 1.0f, 0.0f );
-         audio_unlock();
+         vg_audio_lock();
+         vg_audio_oneshot( &audio_challenge[5], 1.0f, 0.0f, 0, 0 );
+         vg_audio_unlock();
       }
       else if( button_down( k_srbind_mback ) )
       {
@@ -191,9 +191,9 @@ void ent_challenge_update(void)
             _world.active_challenge_id = 0;
             _world.challenge_target = NULL;
             _world.challenge_timer = 0.0f;
-            audio_lock();
-            audio_oneshot_3d( &audio_challenge[6], localplayer.rb.co, 30.0f, 1.0f );
-            audio_unlock();
+            vg_audio_lock();
+            vg_audio_oneshot_3d( &audio_challenge[6], localplayer.rb.co, 30.0f, 1.0f, 0, 0 );
+            vg_audio_unlock();
             vg_info( "Challenge expired due to player being out of range.\n" );
          }
       }
index 7fa1bf86f73a2e1384a1e42f9035ff40ad22cca7..c1750c816078b61938a7f7215062f4851472af33 100644 (file)
@@ -21,17 +21,17 @@ static void ent_objective_pass( world_instance *world, ent_objective *objective
       else
       {
          vg_info( "pass challenge point\n" );
-         audio_lock();
-         audio_oneshot_3d( &audio_challenge[0], localplayer.rb.co, 30.0f, 1.0f );
-         audio_unlock();
+         vg_audio_lock();
+         vg_audio_oneshot_3d( &audio_challenge[0], localplayer.rb.co, 30.0f, 1.0f, 0, 0 );
+         vg_audio_unlock();
       }
    }
    else 
    {
       vg_success( "challenge win\n" );
-      audio_lock();
-      audio_oneshot( &audio_challenge[2], 1.0f, 0.0f );
-      audio_unlock();
+      vg_audio_lock();
+      vg_audio_oneshot( &audio_challenge[2], 1.0f, 0.0f, 0, 0 );
+      vg_audio_unlock();
 
       if( objective->id_win )
       {
@@ -109,9 +109,9 @@ entity_call_result ent_objective_call( world_instance *world, ent_call *call )
          }
          else 
          {
-            audio_lock();
-            audio_oneshot_3d( &audio_challenge[6], localplayer.rb.co, 30.0f, 1.0f );
-            audio_unlock();
+            vg_audio_lock();
+            vg_audio_oneshot_3d( &audio_challenge[6], localplayer.rb.co, 30.0f, 1.0f, 0, 0 );
+            vg_audio_unlock();
             vg_error( "challenge failed, filter was not met\n" );
 
             if( world_clear_event( k_world_event_challenge ) )
index 34358ccf28a967b6895b0b1ac491ef9169526061..7397e8952db47b6f372ece20ed7feab62c0ee1c5 100644 (file)
@@ -212,9 +212,9 @@ bool menu_button_rect( ui_context *ctx, ui_rect rect, bool select, bool clickabl
 
    if( state == k_ui_button_click )
    {
-      audio_lock();
-      audio_oneshot( &audio_ui[0], 1.0f, 0.0f );
-      audio_unlock();
+      vg_audio_lock();
+      vg_audio_oneshot( &audio_ui[0], 1.0f, 0.0f, 0, 0 );
+      vg_audio_unlock();
       return 1;
    }
    else return 0;
@@ -285,9 +285,9 @@ static bool menu_checkbox( ui_context *ctx, ui_rect inout_panel, bool select, co
 
    if( state == k_ui_button_click )
    {
-      audio_lock();
-      audio_oneshot( &audio_ui[0], 1.0f, 0.0f );
-      audio_unlock();
+      vg_audio_lock();
+      vg_audio_oneshot( &audio_ui[0], 1.0f, 0.0f, 0, 0 );
+      vg_audio_unlock();
       return 1;
    }
    else return 0;
@@ -334,9 +334,9 @@ static i32 menu_nav( i32 *p_row, int mv, i32 max )
 
    if( *p_row != row_prev )
    {
-      audio_lock();
-      audio_oneshot( &audio_ui[3], 1.0f, 0.0f );
-      audio_unlock();
+      vg_audio_lock();
+      vg_audio_oneshot( &audio_ui[3], 1.0f, 0.0f, 0, 0 );
+      vg_audio_unlock();
    }
 
    return *p_row;
@@ -419,9 +419,9 @@ void menu_gui( ui_context *ctx )
 
    if( button_down( k_srbind_mclose ) )
    {
-      audio_lock();
-      audio_oneshot( &audio_ui[3], 1.0f, 0.0f );
-      audio_unlock();
+      vg_audio_lock();
+      vg_audio_oneshot( &audio_ui[3], 1.0f, 0.0f, 0, 0 );
+      vg_audio_unlock();
       skaterift.activity = k_skaterift_default;
       srinput.state = k_input_state_resume;
       return;
@@ -525,9 +525,9 @@ void menu_gui( ui_context *ctx )
       
       if( menu_button( ctx, c, R==2, 1, "No" ) || button_down( k_srbind_mback ) )
       {
-         audio_lock();
-         audio_oneshot( &audio_ui[3], 1.0f, 0.0f );
-         audio_unlock();
+         vg_audio_lock();
+         vg_audio_oneshot( &audio_ui[3], 1.0f, 0.0f, 0, 0 );
+         vg_audio_unlock();
          menu.web_link = NULL;
       }
 
@@ -539,9 +539,9 @@ void menu_gui( ui_context *ctx )
    {
       if( button_down( k_srbind_mback ) )
       {
-         audio_lock();
-         audio_oneshot( &audio_ui[3], 1.0f, 0.0f );
-         audio_unlock();
+         vg_audio_lock();
+         vg_audio_oneshot( &audio_ui[3], 1.0f, 0.0f, 0, 0 );
+         vg_audio_unlock();
          vg_settings_close();
          srinput.state = k_input_state_resume;
       }
@@ -669,9 +669,9 @@ void menu_gui( ui_context *ctx )
 
       if( menu_button( ctx, b, R == 1, 1, "Nah" ) || button_down( k_srbind_mback ) )
       {
-         audio_lock();
-         audio_oneshot( &audio_ui[3], 1.0f, 0.0f );
-         audio_unlock();
+         vg_audio_lock();
+         vg_audio_oneshot( &audio_ui[3], 1.0f, 0.0f, 0, 0 );
+         vg_audio_unlock();
          skaterift.activity = k_skaterift_default;
          return;
       }
@@ -718,9 +718,9 @@ void menu_gui( ui_context *ctx )
       if( menu.main_index == VG_ARRAY_LEN(opts) )
          menu.main_index --;
 
-      audio_lock();
-      audio_oneshot( &audio_ui[3], 1.0f, 0.0f );
-      audio_unlock();
+      vg_audio_lock();
+      vg_audio_oneshot( &audio_ui[3], 1.0f, 0.0f, 0, 0 );
+      vg_audio_unlock();
    }
 
    ui_px x = 0, spacer = 8;
@@ -873,7 +873,7 @@ void menu_gui( ui_context *ctx )
          menu_checkbox( ctx, list, R == 1, "Auto connect to global server", &network_client.auto_connect );
 
          menu_heading( ctx, list, "Audio/Video", 0 );
-         menu_slider( ctx, list, R == 2, "Volume", 0, 100, &vg_audio.external_global_volume, "%.f%%" );
+         menu_slider( ctx, list, R == 2, "Volume", 0, 100, &_vg_audio.master_volume_ui, "%.f%%" );
          menu_slider( ctx, list, R == 3, "Resolution", 0, 100, &k_render_scale, "%.f%%" );
          menu_checkbox( ctx, list, R == 4, "Motion Blur", &k_blur_effect );
 
@@ -1018,9 +1018,9 @@ void menu_gui( ui_context *ctx )
    
    if( button_down( k_srbind_mback ) && menu_backable_to_exit )
    {
-      audio_lock();
-      audio_oneshot( &audio_ui[3], 1.0f, 0.0f );
-      audio_unlock();
+      vg_audio_lock();
+      vg_audio_oneshot( &audio_ui[3], 1.0f, 0.0f, 0, 0 );
+      vg_audio_unlock();
       srinput.state = k_input_state_resume;
       skaterift.activity = k_skaterift_default;
    }
index a9e51eb30086a296c89691b53b74248469e97b6e..ca8f2f8330b04560caa4517cb88d5d0ce163d521 100644 (file)
@@ -50,30 +50,24 @@ void _cutscene_play(void)
 {
    _cutscene.state = k_cutscene_state_playing;
 
-   audio_lock();
+   vg_audio_lock();
    for( u32 j=0; j<af_arrcount( &_cutscene.meta.audios ); j++ )
    {
       ent_audio *audio = af_arritm( &_cutscene.meta.audios, j );
-      ent_audio_clip *clip = af_arritm( &_cutscene.meta.audio_clips, 
-                                         audio->clip_start );
+      ent_audio_clip *clip = af_arritm( &_cutscene.meta.audio_clips, audio->clip_start );
 
       if( audio->flags & AUDIO_FLAG_AUTO_START )
       {
-         audio_channel *ch;
+         const u16 group = 0xfff1;
+         const u32 flags = AUDIO_FLAG_CUTSCENE;
+
          if( audio->flags & AUDIO_FLAG_SPACIAL_3D )
-         {
-            ch = audio_oneshot_3d( &clip->_.clip, audio->transform.co,
-                                    audio->transform.s[0],
-                                    audio->volume );
-         }
+            vg_audio_oneshot_3d( &clip->_.clip, audio->transform.co, audio->transform.s[0], audio->volume, group,flags);
          else
-            ch = audio_oneshot( &clip->_.clip, 1.0f, 0.0f );
-
-         if( ch )
-            audio_channel_group( ch, 0xfff1 );
+            vg_audio_oneshot( &clip->_.clip, 1.0f, 0.0f, group, flags );
       }
    }
-   audio_unlock();
+   vg_audio_unlock();
 }
 
 void _cutscene_subtitle( const char *text )
@@ -84,15 +78,7 @@ void _cutscene_subtitle( const char *text )
 void _cutscene_unload(void)
 {
    vg_info( "Unloading cutscene\n" );
-
-   audio_lock();
-   for( u32 i=0; i<AUDIO_CHANNELS; i++ )
-   {
-      audio_channel *ch = &vg_audio.channels[i];
-      if( ch->allocated && (ch->group == 0xfff1) )
-         audio_channel_fadeout( ch, 1.0f );
-   }
-   audio_unlock();
+   vg_audio_fadeout_flagged_audio( AUDIO_FLAG_CUTSCENE, 1.0f );
 
    for( u32 i=0; i<_cutscene.unique_refs; i ++ )
       mdl_sync_std_unload( &_cutscene.refs[i].mdl );
@@ -333,7 +319,7 @@ static void cutscene_load_thread( void *data )
             clip->_.clip.path = af_str( &_cutscene.meta.af,
                                          clip->_.file.pstr_path );
             clip->_.clip.flags = audio->flags;
-            clip->_.clip.data = NULL;
+            clip->_.clip.any_data = NULL;
             clip->_.clip.size = 0;
          }
 
@@ -508,17 +494,8 @@ void cutscene_update( f32 delta )
 {
    if( _cutscene.state == k_cutscene_state_unloading )
    {
-      audio_lock();
-      for( u32 i=0; i<AUDIO_CHANNELS; i++ )
-      {
-         audio_channel *ch = &vg_audio.channels[i];
-         if( ch->allocated && (ch->group == 0xfff1) )
-         {
-            audio_unlock();
-            return;
-         }
-      }
-      audio_unlock();
+      if( !vg_audio_flagged_stopped( AUDIO_FLAG_CUTSCENE ) )
+         return;
 
       vg_allocator_free( _cutscene.arena );
       _cutscene.arena = NULL;
index e80430906b7dd394704f0b6c1a349ce01497631f..057c8cf2193bdd8cd977b5819766ce0c28df18aa 100644 (file)
@@ -109,10 +109,8 @@ void player__debugtext( ui_context *ctx, int size, const char *fmt, ... )
 
 void player__use_model( u16 reg_id )
 {
-   addon_cache_unwatch( k_addon_type_player, 
-                        localplayer.playermodel_view_slot );
-   localplayer.playermodel_view_slot = 
-      addon_cache_create_viewer( k_addon_type_player, reg_id );
+   addon_cache_unwatch( k_addon_type_player, localplayer.playermodel_view_slot );
+   localplayer.playermodel_view_slot = addon_cache_create_viewer( k_addon_type_player, reg_id );
 }
 
 void player__bind(void)
@@ -199,9 +197,9 @@ void player__transport( m4x3f transport )
  */
 void player__pass_gate( u32 id )
 {
-   audio_lock();
-   audio_oneshot( &audio_gate_pass, 1.0f, 0.0f );
-   audio_unlock();
+   vg_audio_lock();
+   vg_audio_oneshot( &audio_gate_pass, 1.0f, 0.0f, 0, 0 );
+   vg_audio_unlock();
 
    world_instance *world = &_world.main;
    ent_gate *gate = af_arritm( &world->ent_gate, mdl_entity_id_id(id) );
index c79e7f89fa4980b0f3129910c1f5821f14245c50..a919eebc7e6637a9c7b9d85ddd7b705756999c37 100644 (file)
@@ -620,11 +620,11 @@ void player_ragdoll_iter( struct player_ragdoll *rd )
       return;
    }
 
-   if( stress ){
+   if( stress )
+   {
       temp_filter = 20;
-      audio_lock();
-      audio_oneshot_3d( &audio_hits[vg_randu32(&vg.rand)%5], 
-                        stress->co, 20.0f, 1.0f );
-      audio_unlock();
+      vg_audio_lock();
+      vg_audio_oneshot_3d( &audio_hits[vg_randu32(&vg.rand)%5], stress->co, 20.0f, 1.0f, 0, 0 );
+      vg_audio_unlock();
    }
 }
index c53c00ae119b0de3f85b072c1e6aa4a60f6dae49..159ef86d6d2629258738c69b108a0482c99429fb 100644 (file)
@@ -64,19 +64,20 @@ void player__skate_bind(void){
       player_get_anim( bindings[i].anim, bindings[i].name );
 }
 
-void player__skate_kill_audio(void){
+void player__skate_kill_audio(void)
+{
    vg_audio_lock();
-   if( player_skate.aud_main ){
-      player_skate.aud_main = 
-         audio_channel_fadeout( player_skate.aud_main, 0.1f );
+   if( player_skate.aud_main )
+   {
+      player_skate.aud_main = vg_audio_crossfade( player_skate.aud_main, NULL, 0.1f );
    }
-   if( player_skate.aud_air ){
-      player_skate.aud_air = 
-         audio_channel_fadeout( player_skate.aud_air, 0.1f );
+   if( player_skate.aud_air )
+   {
+      player_skate.aud_air = vg_audio_crossfade( player_skate.aud_air, NULL, 0.1f );
    }
-   if( player_skate.aud_slide ){
-      player_skate.aud_slide = 
-         audio_channel_fadeout( player_skate.aud_slide, 0.1f );
+   if( player_skate.aud_slide )
+   {
+      player_skate.aud_slide = vg_audio_crossfade( player_skate.aud_slide, NULL, 0.1f );
    }
    vg_audio_unlock();
 }
@@ -770,7 +771,8 @@ static void skate_apply_trick_model(void){
       v3_muladds( state->trick_euler, state->trick_vel, vg.time_fixed_delta,
                   state->trick_euler );
 
-      if( !carry_on && (state->trick_time + vg.time_fixed_delta/interval >= next_end) ){
+      if( !carry_on && (state->trick_time + vg.time_fixed_delta/interval >= next_end) )
+      {
          state->trick_time = 0.0f;
          state->trick_euler[0] = roundf( state->trick_euler[0] );
          state->trick_euler[1] = roundf( state->trick_euler[1] );
@@ -779,8 +781,7 @@ static void skate_apply_trick_model(void){
          v3_zero( state->trick_vel );
 
          vg_audio_lock();
-         audio_oneshot_3d( &audio_flips[vg_randu32(&vg.rand)%4], 
-               localplayer.rb.co, 40.0f, 1.0f );
+         vg_audio_oneshot_3d( &audio_flips[vg_randu32(&vg.rand)%4], localplayer.rb.co, 40.0f, 1.0f, 0, 0 );
          vg_audio_unlock();
       }
       else 
@@ -1282,25 +1283,31 @@ void player__skate_pre_update(void){
    else 
       state->trick_input_collect = 0.0f;
 
-   if( state->activity <= k_skate_activity_air_to_grind ){
-      if( trick && (state->trick_input_collect < 0.1f) ){
-         if( state->trick_time == 0.0f ){
+   if( state->activity <= k_skate_activity_air_to_grind )
+   {
+      if( trick && (state->trick_input_collect < 0.1f) )
+      {
+         if( state->trick_time == 0.0f )
+         {
             vg_audio_lock();
-            audio_oneshot_3d( &audio_flips[vg_randu32(&vg.rand)%4], 
-                  localplayer.rb.co, 40.0f, 1.0f );
+            vg_audio_oneshot_3d( &audio_flips[vg_randu32(&vg.rand)%4], localplayer.rb.co, 40.0f, 1.0f, 0, 0 );
             vg_audio_unlock();
          }
 
-         if( state->trick_time < 0.1f ){
+         if( state->trick_time < 0.1f )
+         {
             v3_zero( state->trick_vel );
 
-            if( trick == k_trick_type_kickflip ){
+            if( trick == k_trick_type_kickflip )
+            {
                state->trick_vel[0] = 3.0f;
             }
-            else if( trick == k_trick_type_shuvit ){
+            else if( trick == k_trick_type_shuvit )
+            {
                state->trick_vel[2] = 3.0f;
             }
-            else if( trick == k_trick_type_treflip ){
+            else if( trick == k_trick_type_treflip )
+            {
                state->trick_vel[0] = 2.0f;
                state->trick_vel[2] = 2.0f;
             }
@@ -1332,48 +1339,75 @@ void player__skate_comp_audio( void *_animator )
       gate = vg_minf( 1.0f, fabsf(player_replay.track_velocity) );
    }
 
-   f32
-       vol_main    = sqrtf( (1.0f-air)*attn*(1.0f-slide) * 0.4f ) * gate,
+   f32 vol_main    = sqrtf( (1.0f-air)*attn*(1.0f-slide) * 0.4f ) * gate,
        vol_air     = sqrtf(       air *attn * 0.5f )              * gate,
        vol_slide   = sqrtf( (1.0f-air)*attn*slide * 0.25f )       * gate;
 
-   const u32 flags = AUDIO_FLAG_SPACIAL_3D|AUDIO_FLAG_LOOP;
-
-   if( !player_skate.aud_air ){
-      player_skate.aud_air = audio_get_first_idle_channel();
-      if( player_skate.aud_air )
-         audio_channel_init( player_skate.aud_air, &audio_board[1], flags );
+   if( !player_skate.aud_air )
+   {
+      audio_channel_id channel_id = vg_audio_get_first_idle_channel();
+      if( channel_id )
+      {
+         player_skate.aud_air = channel_id;
+         vg_audio_set_channel_clip( channel_id, &audio_board[1] );
+         vg_audio_set_channel_spacial_falloff( channel_id, animator->root_co, 40.0f );
+         vg_audio_set_channel_volume( channel_id, 0.0, 1 );
+         vg_audio_add_channel_flags( channel_id, AUDIO_FLAG_LOOP );
+         vg_audio_start_channel( channel_id );
+      }
    }
 
-   if( !player_skate.aud_slide ){
-      player_skate.aud_slide = audio_get_first_idle_channel();
-      if( player_skate.aud_slide ) 
-         audio_channel_init( player_skate.aud_slide, &audio_board[2], flags );
+   if( !player_skate.aud_slide )
+   {
+      audio_channel_id channel_id = vg_audio_get_first_idle_channel();
+      if( channel_id )
+      {
+         player_skate.aud_slide = channel_id;
+         vg_audio_set_channel_clip( channel_id, &audio_board[2] );
+         vg_audio_set_channel_spacial_falloff( channel_id, animator->root_co, 40.0f );
+         vg_audio_set_channel_volume( channel_id, 0.0, 1 );
+         vg_audio_add_channel_flags( channel_id, AUDIO_FLAG_LOOP );
+         vg_audio_start_channel( channel_id );
+      }
    }
 
-
    /* brrrrrrrrrrrt sound for tiles and stuff 
     * --------------------------------------------------------*/
-   float sidechain_amt = 0.0f,
-         hz            = vg_maxf( speed * 2.0f, 2.0f );
+   f32 sidechain_amt = 0.0f;
+   f32 bump_hz = vg_maxf( speed * 2.0f, 2.0f );
 
-   if( (animator->surface == k_surface_prop_tiles) &&
-       (animator->activity < k_skate_activity_grind_any) )
+   if( (animator->surface == k_surface_prop_tiles) && (animator->activity < k_skate_activity_grind_any) )
       sidechain_amt = 1.0f;
    else
       sidechain_amt = 0.0f;
 
-   audio_set_lfo_frequency( 0, hz );
-   audio_set_lfo_wave( 0, k_lfo_polynomial_bipolar, 
-                          vg_lerpf( 250.0f, 80.0f, attn ) );
+   if( player_skate.lfo_bumps == 0 )
+   {
+      audio_channel_id lfo_id = vg_audio_get_first_idle_lfo();
+      if( lfo_id )
+      {
+         player_skate.lfo_bumps = lfo_id;
+         vg_audio_set_lfo_polynomial_bipolar( lfo_id, 80.0f );
+         vg_audio_set_lfo_frequency( lfo_id, bump_hz );
+         vg_audio_start_lfo( lfo_id );
+      }
+   }
+   else
+   {
+      vg_audio_set_lfo_polynomial_bipolar( player_skate.lfo_bumps, vg_lerpf( 250.0f, 80.0f, attn ) );
+      vg_audio_set_lfo_frequency( player_skate.lfo_bumps, bump_hz );
+   }
 
-   if( player_skate.sample_change_cooldown > 0.0f ){
+   if( player_skate.sample_change_cooldown > 0.0f )
+   {
       player_skate.sample_change_cooldown -= vg.time_frame_delta;
    }
-   else{
+   else
+   {
       int sample_type = k_skate_sample_concrete;
 
-      if( animator->activity == k_skate_activity_grind_5050 ){
+      if( animator->activity == k_skate_activity_grind_5050 )
+      {
          if( animator->surface == k_surface_prop_metal )
             sample_type = k_skate_sample_metal_scrape_generic;
          else
@@ -1385,7 +1419,8 @@ void player__skate_comp_audio( void *_animator )
          if( animator->surface == k_surface_prop_metal ){
             sample_type = k_skate_sample_metal_scrape_generic;
          }
-         else{
+         else
+         {
 #if 0
             float a = v3_dot( localplayer.rb.to_world[2], 
                               state->grind_dir );
@@ -1398,14 +1433,16 @@ void player__skate_comp_audio( void *_animator )
             sample_type = k_skate_sample_concrete_scrape_wood;
          }
       }
-      else if( animator->activity == k_skate_activity_grind_boardslide ){
+      else if( animator->activity == k_skate_activity_grind_boardslide )
+      {
          if( animator->surface == k_surface_prop_metal )
             sample_type = k_skate_sample_metal_scrape_generic;
          else
             sample_type = k_skate_sample_concrete_scrape_wood;
       }
 
-      audio_clip *relevant_samples[] = {
+      audio_clip *relevant_samples[] = 
+      {
          &audio_board[0],
          &audio_board[0],
          &audio_board[7],
@@ -1413,71 +1450,71 @@ void player__skate_comp_audio( void *_animator )
          &audio_board[5]
       };
 
-      if( (player_skate.main_sample_type != sample_type) || (!player_skate.aud_main) )
+      if( (player_skate.main_sample_type != sample_type) || !player_skate.aud_main )
       {
-         player_skate.aud_main = 
-            audio_channel_crossfade( player_skate.aud_main, 
-                                     relevant_samples[sample_type],
-                                     0.06f, flags );
+         audio_channel_id channel_id = player_skate.aud_main;
+         if( channel_id )
+            channel_id = vg_audio_crossfade( channel_id, relevant_samples[sample_type], 0.06f );
+         else
+         {
+            channel_id = vg_audio_get_first_idle_channel();
+            
+            if( channel_id )
+            {
+               vg_audio_set_channel_clip( channel_id, relevant_samples[sample_type] );
+               vg_audio_add_channel_flags( channel_id, AUDIO_FLAG_LOOP );
+               vg_audio_start_channel( channel_id );
+            }
+         }
+
          player_skate.sample_change_cooldown = 0.1f;
          player_skate.main_sample_type = sample_type;
-      }
-   }
-
-   if( player_skate.lfo_bumps == NULL )
-   {
-      audio_lfo *lfo = vg_audio_get_first_idle_lfo();
-      if( lfo )
-      {
-         player_skate.lfo_bumps = lfo;
-         vg_audio_set_lfo_polynomial_bipolar( lfo, 80.0f );
-         vg_audio_set_lfo_frequency( lfo, 20.0f );
-         vg_audio_start_lfo( lfo );
+         player_skate.aud_main = channel_id;
       }
    }
 
    if( player_skate.aud_main )
    {
-      player_skate.aud_main->ui_colour = 0x00103efe;
-      vg_audio_channel_set_spacial_falloff( player_skate.aud_main, animator->root_co, 40.0f );
-      audio_channel_edit_volume( player_skate.aud_main, vol_main, 1 );
-      audio_channel_sidechain_lfo( player_skate.aud_main, 0, sidechain_amt );
+      //player_skate.aud_main->ui_colour = 0x00103efe;
+      vg_audio_set_channel_spacial_falloff( player_skate.aud_main, animator->root_co, 40.0f );
+      vg_audio_set_channel_volume( player_skate.aud_main, vol_main, 0 );
+      vg_audio_sidechain_lfo_to_channel( player_skate.aud_main, player_skate.lfo_bumps, sidechain_amt );
 
       float rate = 1.0f + (attn-0.5f)*0.2f;
-      audio_channel_set_sampling_rate( player_skate.aud_main, rate );
+      vg_audio_set_channel_sampling_rate( player_skate.aud_main, rate );
    }
 
-   if( player_skate.aud_slide ){
-      player_skate.aud_slide->colour = 0x00103efe;
-      audio_channel_set_spacial( player_skate.aud_slide, 
-                                 animator->root_co, 40.0f );
-      //audio_channel_slope_volume( player_skate.aud_slide, 0.05f, vol_slide );
-      audio_channel_edit_volume( player_skate.aud_slide, vol_slide, 1 );
-      audio_channel_sidechain_lfo( player_skate.aud_slide, 0, sidechain_amt );
+   if( player_skate.aud_slide )
+   {
+      //player_skate.aud_slide->ui_colour = 0x00103efe;
+      vg_audio_set_channel_spacial_falloff( player_skate.aud_slide, animator->root_co, 40.0f );
+      vg_audio_set_channel_volume( player_skate.aud_slide, vol_slide, 0 );
+      vg_audio_sidechain_lfo_to_channel( player_skate.aud_slide, player_skate.lfo_bumps, sidechain_amt );
    }
 
-   if( player_skate.aud_air ){
-      player_skate.aud_air->colour = 0x00103efe;
-      audio_channel_set_spacial( player_skate.aud_air, 
-                                 animator->root_co, 40.0f );
-      //audio_channel_slope_volume( player_skate.aud_air, 0.05f, vol_air );
-      audio_channel_edit_volume( player_skate.aud_air, vol_air, 1 );
+   if( player_skate.aud_air )
+   {
+      //player_skate.aud_air->ui_colour = 0x00103efe;
+      vg_audio_set_channel_spacial_falloff( player_skate.aud_air, animator->root_co, 40.0f );
+      vg_audio_set_channel_volume( player_skate.aud_air, vol_air, 0 );
    }
 
    vg_audio_unlock();
 }
 
-void player__skate_post_update(void){
+void player__skate_post_update(void)
+{
    struct player_skate_state *state = &player_skate.state;
 
-   for( int i=0; i<player_skate.possible_jump_count; i++ ){
+   for( int i=0; i<player_skate.possible_jump_count; i++ )
+   {
       jump_info *jump = &player_skate.possible_jumps[i];
 
-      if( jump->log_length == 0 ){
+      if( jump->log_length == 0 )
          vg_fatal_error( "assert: jump->log_length == 0\n" );
-      }
       
-      for( int j=0; j<jump->log_length - 1; j ++ ){
+      for( int j=0; j<jump->log_length - 1; j ++ )
+      {
          float brightness = jump->score*jump->score*jump->score;
          v3f p1;
          v3_lerp( jump->log[j], jump->log[j+1], brightness, p1 );
@@ -3650,22 +3687,22 @@ void player__skate_sfx_oneshot( u8 id, v3f pos, f32 volume )
    vg_audio_lock();
 
    if( id == k_player_skate_soundeffect_jump ){
-      audio_oneshot_3d( &audio_jumps[vg_randu32(&vg.rand)%2], pos, 40.0f, volume );
+      vg_audio_oneshot_3d( &audio_jumps[vg_randu32(&vg.rand)%2], pos, 40.0f, volume, 0, 0 );
    }
    else if( id == k_player_skate_soundeffect_tap ){
-      audio_oneshot_3d( &audio_taps[vg_randu32(&vg.rand)%4], pos, 40.0f, volume );
+      vg_audio_oneshot_3d( &audio_taps[vg_randu32(&vg.rand)%4], pos, 40.0f, volume, 0, 0);
    }
    else if( id == k_player_skate_soundeffect_land_good ){
-      audio_oneshot_3d( &audio_lands[vg_randu32(&vg.rand)%3], pos, 40.0f, volume );
+      vg_audio_oneshot_3d( &audio_lands[vg_randu32(&vg.rand)%3], pos, 40.0f, volume, 0, 0 );
    }
    else if( id == k_player_skate_soundeffect_land_bad ){
-      audio_oneshot_3d( &audio_lands[vg_randu32(&vg.rand)%2+3], pos, 40.0f, volume );
+      vg_audio_oneshot_3d( &audio_lands[vg_randu32(&vg.rand)%2+3], pos, 40.0f, volume, 0, 0 );
    }
    else if( id == k_player_skate_soundeffect_grind_metal ){
-      audio_oneshot_3d( &audio_board[3], pos, 40.0f, volume );
+      vg_audio_oneshot_3d( &audio_board[3], pos, 40.0f, volume, 0, 0 );
    }
    else if( id == k_player_skate_soundeffect_grind_wood ){
-      audio_oneshot_3d( &audio_board[8], pos, 40.0f, volume );
+      vg_audio_oneshot_3d( &audio_board[8], pos, 40.0f, volume, 0, 0 );
    }
 
    vg_audio_unlock();
index 1e4899e777b92d176f20f930b36c3de84c5ce5d1..207873cf765da821eb12f067c0a6147496972f14 100644 (file)
@@ -161,8 +161,8 @@ struct player_skate{
    /* vectors representing the direction of the axels in localspace */
    v3f truckv0[2];
 
-   audio_channel *aud_main, *aud_slide, *aud_air;
-   audio_lfo *lfo_bumps;
+   audio_channel_id aud_main, aud_slide, aud_air;
+   audio_channel_id lfo_bumps;
    enum mdl_surface_prop surface, audio_surface;
 
    int wheel_contacts[2];
index fd7aeb669cf89bcfe83df6d79d4316e2357f04f9..cf28d251475cf5deec0ed173d6426da43ae42369 100644 (file)
@@ -777,32 +777,36 @@ void player__walk_post_update(void){
    if( (w->state.step_phase != walk_phase) && 
        (w->state.activity == k_walk_activity_ground ) )
    {
-      audio_lock();
-      if( w->surface == k_surface_prop_concrete ){
-         audio_oneshot_3d( 
+      vg_audio_lock();
+      if( w->surface == k_surface_prop_concrete )
+      {
+         vg_audio_oneshot_3d( 
                &audio_footsteps[vg_randu32(&vg.rand) % 4],
-               localplayer.rb.co, 40.0f, 1.0f 
+               localplayer.rb.co, 40.0f, 1.0f, 0, 0
          );
       }
-      else if( w->surface == k_surface_prop_grass ){
-         audio_oneshot_3d( 
+      else if( w->surface == k_surface_prop_grass )
+      {
+         vg_audio_oneshot_3d( 
            &audio_footsteps_grass[ vg_randu32(&vg.rand) % 6 ],
-            localplayer.rb.co, 40.0f, 1.0f 
+            localplayer.rb.co, 40.0f, 1.0f, 0, 0
          );
       }
-      else if( w->surface == k_surface_prop_wood ){
-         audio_oneshot_3d( 
+      else if( w->surface == k_surface_prop_wood )
+      {
+         vg_audio_oneshot_3d( 
            &audio_footsteps_wood[ vg_randu32(&vg.rand) % 6 ],
-            localplayer.rb.co, 40.0f, 1.0f 
+            localplayer.rb.co, 40.0f, 1.0f, 0, 0
          );
       }
-      audio_unlock();
+      vg_audio_unlock();
    }
 
    w->state.step_phase = walk_phase;
 }
 
-void player__walk_update(void){
+void player__walk_update(void)
+{
    struct player_walk *w = &player_walk;
 
    if( (w->state.activity == k_walk_activity_air) ||
@@ -1232,11 +1236,10 @@ void player__walk_animator_exchange( bitpack_ctx *ctx, void *data ){
 
 void player__walk_sfx_oneshot( u8 id, v3f pos, f32 volume )
 {
-   audio_lock();
+   vg_audio_lock();
 
-   if( id == k_player_walk_soundeffect_splash ){
-      audio_oneshot_3d( &audio_splash, pos, 40.0f, 1.0f );
-   }
+   if( id == k_player_walk_soundeffect_splash )
+      vg_audio_oneshot_3d( &audio_splash, pos, 40.0f, 1.0f, 0, 0 );
 
-   audio_unlock();
+   vg_audio_unlock();
 }
index 20f69ee68a0426fc6c90067e4d621b0f65b192de..b6a8dbcad69b93f5c87bda65c6c57c6c042f88fa 100644 (file)
@@ -228,19 +228,19 @@ void vg_post_update(void)
    int sample_index;
    world_audio_sample_distances( localplayer.rb.co, &sample_index, &dist );
 
-   audio_lock();
+   vg_audio_lock();
    vg_dsp.echo_distances[sample_index] = dist;
 
    v3f ears = { 1.0f,0.0f,0.0f };
    m3x3_mulv( g_render.cam.transform, ears, ears );
-   v3_copy( ears, _vg_audio.listener_right_ear_direction );
-   v3_copy( g_render.cam.transform[3], _vg_audio.listener_position );
+   v3_copy( ears, _vg_audio.controls.listener_right_ear_direction );
+   v3_copy( g_render.cam.transform[3], _vg_audio.controls.listener_position );
 
    if( localplayer.gate_waiting )
-      m4x3_mulv( localplayer.gate_waiting->transport, _vg_audio.listener_position, _vg_audio.listener_position );
+      m4x3_mulv( localplayer.gate_waiting->transport, _vg_audio.controls.listener_position, _vg_audio.controls.listener_position );
 
-   v3_copy( localplayer.rb.v, _vg_audio.listener_velocity );
-   audio_unlock();
+   v3_copy( localplayer.rb.v, _vg_audio.controls.listener_velocity );
+   vg_audio_unlock();
 
    vehicle_update_post();
    skaterift_autosave_update();
index dff4993ae2b5ce57b73c93ea7bac617a85e94b7b..3e0fecd571b49cbcb3f4b85903b850539ea13ef3 100644 (file)
@@ -1,19 +1,6 @@
 #include "audio.h"
 #include "world_audio.h"
 
-void world_fadeout_audio( world_instance *world )
-{
-   audio_lock();
-   for( u32 i=0; i<AUDIO_CHANNELS; i++ )
-   {
-      audio_channel *ch = &vg_audio.channels[i];
-
-      if( ch->allocated && (ch->flags & AUDIO_FLAG_WORLD) )
-         audio_channel_fadeout( ch, 1.0f );
-   }
-   audio_unlock();
-}
-
 /*
  * Trace out a random point, near the player to try and determine water areas
  */
@@ -91,20 +78,20 @@ void world_audio_sample_distances( v3f co, int *index, float *value )
 
    float dist = 200.0f;
 
-   for( int i=0; i<10; i++ ){
-      if( ray_world( &_world.main, rc, rd, &ray, 
-                     k_material_flag_ghosts ) ){
+   for( int i=0; i<10; i++ )
+   {
+      if( ray_world( &_world.main, rc, rd, &ray, k_material_flag_ghosts ) )
+      {
          dist = (float)i*5.0f + ray.dist;
          break;
       }
-      else{
+      else
          v3_muladds( rc, rd, ray.dist, rc );
-      }
    }
 
    distances[si] = dist;
 
-   if( vg_audio.inspector_open && vg_lines.enabled )
+   if( _vg_audio.inspector_open && vg_lines.enabled )
    {
       for( int i=0; i<14; i++ )
       {
index e992ae3c90397603f889b06fba401ab30ad0030a..abcbbd0e623e73697756674c8ec87d7c92325bd0 100644 (file)
@@ -253,8 +253,7 @@ void world_gen_entities_init( world_instance *world )
 
       for( u32 k=0; k<audio->clip_count; k++ )
       {
-         ent_audio_clip *clip = af_arritm( &world->ent_audio_clip,  
-                                             audio->clip_start+k );
+         ent_audio_clip *clip = af_arritm( &world->ent_audio_clip, audio->clip_start+k );
 
          if( clip->_.file.pack_size )
          {
@@ -265,14 +264,13 @@ void world_gen_entities_init( world_instance *world )
              * external audio uses it */
 
             vg_linear_clear( vg_mem.scratch );
-            void *data = vg_linear_alloc( vg_mem.scratch, 
-                                          clip->_.file.pack_size );
+            void *data = vg_linear_alloc( vg_mem.scratch, clip->_.file.pack_size );
 
             mdl_fread_pack_file( &world->meta, &clip->_.file, data );
 
             clip->_.clip.path = NULL;
             clip->_.clip.flags = audio->flags;
-            clip->_.clip.data = data;
+            clip->_.clip.any_data = data;
             clip->_.clip.size = size;
          }
          else
@@ -280,7 +278,7 @@ void world_gen_entities_init( world_instance *world )
             clip->_.clip.path = af_str( &world->meta.af, 
                                          clip->_.file.pstr_path );
             clip->_.clip.flags = audio->flags;
-            clip->_.clip.data = NULL;
+            clip->_.clip.any_data = NULL;
             clip->_.clip.size = 0;
          }
 
@@ -484,75 +482,59 @@ entity_call_result ent_audio_call( world_instance *world, ent_call *call )
       bar += p;
       if( chance < bar )
       {
-         audio_lock();
+         vg_audio_lock();
 
          if( audio->behaviour == k_channel_behaviour_unlimited )
          {
-            audio_channel *ch = audio_get_first_idle_channel();
-
-            if( ch )
+            audio_channel_id channel_id = vg_audio_get_first_idle_channel();
+            if( channel_id )
             {
-               audio_channel_init( ch, &clip->_.clip, 
-                                   audio->flags|AUDIO_FLAG_WORLD );
-               audio_channel_set_spacial( ch, sound_co, audio->transform.s[0] );
-               audio_channel_edit_volume( ch, audio->volume, 1 );
-               audio_relinquish_channel( ch );
+               vg_audio_add_channel_flags( channel_id, AUDIO_FLAG_WORLD | AUDIO_FLAG_RELINQUISHED );
+               vg_audio_set_channel_clip( channel_id, &clip->_.clip );
+               vg_audio_set_channel_spacial_falloff( channel_id, sound_co, audio->transform.s[0] );
+               vg_audio_set_channel_volume( channel_id, audio->volume, 1 );
+               vg_audio_start_channel( channel_id );
             }
          }
          else if( audio->behaviour == k_channel_behaviour_discard_if_full )
          {
-            audio_channel *ch = 
-               audio_get_group_idle_channel( audio->group, 
-                                             audio->max_channels );
-
-            if( ch )
+            /* TODO This and above are the same */
+            if( vg_audio_count_channels_in_group( audio->group ) < audio->max_channels )
             {
-               audio_channel_init( ch, &clip->_.clip, 
-                                    audio->flags | AUDIO_FLAG_WORLD );
-               audio_channel_group( ch, audio->group );
-               audio_channel_set_spacial( ch, sound_co, audio->transform.s[0] );
-               audio_channel_edit_volume( ch, audio->volume, 1 );
-               ch = audio_relinquish_channel( ch );
+               audio_channel_id channel_id = vg_audio_get_first_idle_channel();
+               if( channel_id )
+               {
+                  vg_audio_add_channel_flags( channel_id, AUDIO_FLAG_WORLD | AUDIO_FLAG_RELINQUISHED );
+                  vg_audio_set_channel_clip( channel_id, &clip->_.clip );
+                  vg_audio_set_channel_spacial_falloff( channel_id, sound_co, audio->transform.s[0] );
+                  vg_audio_set_channel_volume( channel_id, audio->volume, 1 );
+                  vg_audio_start_channel( channel_id );
+               }
             }
          }
-         else if( audio->behaviour == k_channel_behaviour_crossfade_if_full)
+         else if( audio->behaviour == k_channel_behaviour_crossfade_if_full )
          {
-            audio_channel *ch =
-               audio_get_group_idle_channel( audio->group,
-                                             audio->max_channels );
-
-            /* group is full */
-            if( !ch )
+            if( vg_audio_count_channels_in_group( audio->group ) >= audio->max_channels )
             {
-               audio_channel *existing = 
-                  audio_get_group_first_active_channel( audio->group );
-
-               if( existing )
-               {
-                  if( existing->source == &clip->_.clip )
-                  {
-                     audio_unlock();
-                     return k_entity_call_result_OK;
-                  }
-                 
-                  existing->group = 0;
-                  existing = audio_channel_fadeout(existing, audio->crossfade);
-               }
-
-               ch = audio_get_first_idle_channel();
+               audio_channel_id channel_id = vg_audio_get_first_active_channel_in_group( audio->group );
+               if( channel_id )
+                  vg_audio_crossfade( channel_id, &clip->_.clip, audio->crossfade );
             }
-
-            if( ch )
+            else
             {
-               audio_channel_init( ch, &clip->_.clip, 
-                                       audio->flags | AUDIO_FLAG_WORLD );
-               audio_channel_group( ch, audio->group );
-               audio_channel_fadein( ch, audio->crossfade );
-               ch = audio_relinquish_channel( ch );
+               audio_channel_id channel_id = vg_audio_get_first_idle_channel();
+               if( channel_id )
+               {
+                  vg_audio_add_channel_flags( channel_id, AUDIO_FLAG_WORLD|AUDIO_FLAG_RELINQUISHED );
+                  vg_audio_set_channel_clip( channel_id, &clip->_.clip );
+                  vg_audio_set_channel_spacial_falloff( channel_id, sound_co, audio->transform.s[0] );
+                  vg_audio_set_channel_volume( channel_id, audio->volume, 1 );
+                  vg_audio_start_channel( channel_id );
+               }
             }
          }
 
-         audio_unlock();
+         vg_audio_unlock();
          return k_entity_call_result_OK;
       }
    }
index b68ed81ae7ce155382c6f0965a2beb8ae4ba6a78..b67102d845aaf049ed36fc62612e109f167324a9 100644 (file)
@@ -424,23 +424,7 @@ void world_switcher_update(void)
    /* pre-load step aka waiting for audio to end. */
    if( _world.loader_state == k_world_loader_unloading_current )
    {
-      bool all_world_audio_stopped = 1;
-      audio_lock();
-      for( u32 i=0; i<AUDIO_CHANNELS; i++ )
-      {
-         audio_channel *ch = &vg_audio.channels[i];
-         if( ch->allocated && (ch->flags & AUDIO_FLAG_WORLD))
-         {
-            if( !audio_channel_finished( ch ) )
-            {
-               all_world_audio_stopped = 0;
-               break;
-            }
-         }
-      }
-      audio_unlock();
-
-      if( !all_world_audio_stopped )
+      if( !vg_audio_flagged_stopped( AUDIO_FLAG_WORLD ) )
          return;
       
       _skaterift_script_unlink_all_challenges();
@@ -520,7 +504,7 @@ void skaterift_load_world_start( addon_reg *reg, bool preview )
       }
    }
    else
-      world_fadeout_audio( &_world.main );
+      vg_audio_fadeout_flagged_audio( AUDIO_FLAG_WORLD, 1.0f );
 
    _world.loader_reg = reg;
    _world.loader_instance = world;
index 87df0cac25cce87b24dec52e91d1da98ad6cf056..3acda21698c154c14874cc0eacccf6d6113cd5b3 100644 (file)
@@ -555,9 +555,9 @@ void world_map_gui( ui_context *ctx, ui_rect main_area, i32 mh, i32 mv, bool *al
 
             if( button_down( k_srbind_mhub ) )
             {
-               audio_lock();
-               audio_oneshot( &audio_ui[3], 1.0f, 0.0f );
-               audio_unlock();
+               vg_audio_lock();
+               vg_audio_oneshot( &audio_ui[3], 1.0f, 0.0f, 0, 0 );
+               vg_audio_unlock();
                go_to_super = 1;
             }
          }