i hope your hapy
[carveJwlIkooP6JGAAIwe30JlM.git] / audio.h
diff --git a/audio.h b/audio.h
index 9622c50a81eee572bb52a082339f45668d4e15b0..4f735099fb87fddbb8d6f40524c55bc885b5b664 100644 (file)
--- a/audio.h
+++ b/audio.h
@@ -16,10 +16,13 @@ VG_STATIC int   k_audio_debug_soundscape = 0;
 
 audio_clip audio_board[] =
 {
-   { .path="sound/skate.ogg" },
+   { .path="sound/skate_hpf.ogg" },
    { .path="sound/wheel.ogg" },
    { .path="sound/slide.ogg" },
-   { .path="sound/reverb.ogg" }
+   { .path="sound/reverb.ogg" },
+   { .path="sound/grind_loop.ogg" },
+   { .path="sound/grind_enter.ogg" },
+   { .path="sound/grind_exit.ogg" }
 };
 
 audio_clip audio_splash =
@@ -98,6 +101,7 @@ audio_clip audio_gate_ambient = {
 .path = "sound/gate_ambient.ogg"
 };
 
+#if 0
 audio_player ambient_player =
 {
    .name = "Ambience"
@@ -107,6 +111,7 @@ audio_player audio_rewind_player =
 {
    .name = "Rewind"
 };
+#endif
 
 audio_clip audio_rewind[] = {
 { .path = "sound/rewind_start.ogg" },
@@ -121,6 +126,12 @@ audio_clip audio_ui[] = {
    { .path = "sound/ui_ding.ogg" },
 };
 
+audio_clip audio_music[] = {
+   { .path = "sound/song.ogg", .flags = k_audio_format_vorbis },
+   { .path = "sound/skate.ogg", .flags = k_audio_format_vorbis },
+};
+
+#if 0
 audio_player ambient_sprites[4] =
 {
    { .name = "Ambient Sprites 0" },
@@ -149,6 +160,11 @@ audio_player audio_player3 =
    .name = "Player3",
 };
 
+audio_player audio_player4 =
+{
+   .name = "Player4",
+};
+
 audio_player audio_player_extra =
 {
    .name = "PlayerInst"
@@ -158,13 +174,16 @@ audio_player audio_player_gate =
 {
    .name = "Gate"
 };
+#endif
 
 VG_STATIC void audio_init(void)
 {
+#if 0
    audio_player_init( &audio_player0 );
    audio_player_init( &audio_player1 );
    audio_player_init( &audio_player2 );
    audio_player_init( &audio_player3 );
+   audio_player_init( &audio_player4 );
    audio_player_init( &audio_player_gate );
    audio_player_init( &ambient_player );
    audio_player_init( &ambient_sprites[0] );
@@ -173,6 +192,7 @@ VG_STATIC void audio_init(void)
    audio_player_init( &ambient_sprites[3] );
    audio_player_init( &audio_player_extra );
    audio_player_init( &audio_rewind_player );
+#endif
 
    audio_clip_loadn( audio_board, vg_list_size(audio_board), NULL );
    audio_clip_loadn( audio_ambience, vg_list_size(audio_ambience), NULL );
@@ -180,6 +200,8 @@ VG_STATIC void audio_init(void)
    audio_clip_loadn( &audio_gate_pass, 1, NULL );
    audio_clip_loadn( &audio_gate_lap, 1, NULL );
    audio_clip_loadn( &audio_gate_ambient, 1, NULL );
+   audio_clip_loadn( audio_music, vg_list_size(audio_music), NULL );
+
    audio_clip_loadn( audio_jumps, vg_list_size(audio_jumps), NULL );
    audio_clip_loadn( audio_lands, vg_list_size(audio_lands), NULL );
    audio_clip_loadn( audio_water, vg_list_size(audio_water), NULL );
@@ -192,12 +214,14 @@ VG_STATIC void audio_init(void)
    audio_clip_loadn( audio_rewind, vg_list_size(audio_rewind), NULL );
    audio_clip_loadn( audio_ui, vg_list_size(audio_ui), NULL );
 
+#if 0
    audio_lock();
    u32 flags = AUDIO_FLAG_LOOP|AUDIO_FLAG_SPACIAL_3D;
 
    audio_player_set_flags( &audio_player0, flags );
    audio_player_set_flags( &audio_player1, flags );
    audio_player_set_flags( &audio_player2, flags );
+   audio_player_set_flags( &audio_player4, flags );
    audio_player_set_flags( &audio_player_gate, flags );
    audio_player_set_flags( &audio_player3, AUDIO_FLAG_LOOP );
    audio_player_set_flags( &ambient_player, AUDIO_FLAG_LOOP );
@@ -205,6 +229,7 @@ VG_STATIC void audio_init(void)
    audio_player_set_flags( &ambient_sprites[1], AUDIO_FLAG_SPACIAL_3D );
    audio_player_set_flags( &ambient_sprites[2], AUDIO_FLAG_SPACIAL_3D );
    audio_player_set_flags( &ambient_sprites[3], AUDIO_FLAG_SPACIAL_3D );
+
    audio_player_set_vol( &ambient_player, 1.0f );
    audio_player_set_vol( &audio_player_gate, 0.0f );
    audio_player_set_vol( &audio_player_extra, 1.0f );
@@ -215,29 +240,63 @@ VG_STATIC void audio_init(void)
    audio_player_playclip( &audio_player1, &audio_board[1] );
    audio_player_playclip( &audio_player2, &audio_board[2] );
    audio_player_playclip( &audio_player3, &audio_board[3] );
+   audio_player_playclip( &audio_player4, &audio_board[4] );
    audio_player_playclip( &ambient_player, &audio_ambience[0] );
    audio_player_playclip( &audio_player_gate, &audio_gate_ambient );
 
    audio_unlock();
+#endif
 
-   vg_convar_push( (struct vg_convar){
+   vg_var_push( (struct vg_var){
       .name = "aud_debug_soundscape",
       .data = &k_audio_debug_soundscape,
-      .data_type = k_convar_dtype_i32,
+      .data_type = k_var_dtype_i32,
       .opt_i32 = { .min=0, .max=1, .clamp=0 },
       .persistent = 1
    });
 
-   vg_convar_push( (struct vg_convar){
+   vg_var_push( (struct vg_var){
       .name = "aud_occlusion_rate",
       .data = &k_audio_occlusion_rate,
-      .data_type = k_convar_dtype_f32,
+      .data_type = k_var_dtype_f32,
       .opt_f32 = { .clamp = 0 },
       .persistent = 1
    });
+
+   audio_lock();
+   audio_set_lfo_wave( 0, k_lfo_polynomial_bipolar, 80.0f );
+   audio_set_lfo_frequency( 0, 20.0f );
+   audio_unlock();
+}
+
+VG_STATIC void audio_update(void)
+{
+#if 0
+   static u32 flapflop = 0x00;
+   static audio_channel *channel = NULL;
+
+   u32 next = floorf( vg.time / 0.1f );
+
+   if( flapflop != next )
+   {
+      flapflop = next;
+
+      audio_lock();
+      channel = audio_channel_crossfade( channel, 
+                                         &audio_music[ next & 0x1 ], 0.05f,
+                                         AUDIO_FLAG_LOOP|AUDIO_FLAG_SPACIAL_3D 
+            );
+      channel = audio_channel_set_spacial( channel,
+                                           (v3f){ -22.3f, 60.1f, -52.7f },
+                                           50.0f );
+
+      audio_channel_sidechain_lfo( channel, 0, 1.0f );
+      audio_unlock();
+   }
+#endif
 }
 
-VG_STATIC void audio_free(void*_)
+VG_STATIC void audio_free(void)
 {
    /* TODO! */
    vg_warn( "UNIMPLEMENTED: audio_free()\n" );
@@ -254,6 +313,8 @@ VG_STATIC void audio_sample_occlusion( v3f origin )
    v3f last;
    v3_zero(last);
 
+   world_instance *world = get_active_world();
+
    for( int i=0; i<sample_count; i++ )
    {
       v3f dir;
@@ -262,15 +323,18 @@ VG_STATIC void audio_sample_occlusion( v3f origin )
       ray_hit contact;
       contact.dist = 15.0f;
       
-      if( ray_world( origin, dir, &contact ) )
+      if( ray_world( world, origin, dir, &contact ) )
       {
          d += contact.dist;
 
+#if 0
          vg_line( origin, contact.pos, 0xff0000ff );
          vg_line_pt3( contact.pos, 0.1f, 0xff0000ff );
 
          if( lv )
             vg_line( contact.pos, last, 0xffffffff );
+#endif
+
          v3_copy( contact.pos, last );
          lv = 1;
       }
@@ -278,7 +342,10 @@ VG_STATIC void audio_sample_occlusion( v3f origin )
       {
          v3f p1;
          v3_muladds( origin, dir, sample_dist, p1 );
+
+#if 0
          vg_line( origin, p1, 0xffcccccc );
+#endif
 
          d += sample_dist;
          lv = 0;
@@ -288,7 +355,7 @@ VG_STATIC void audio_sample_occlusion( v3f origin )
 
    float occlusion = 1.0f - (d * (1.0f/(sample_dist*(float)sample_count))),
          rate = VG_TIMESTEP_FIXED * k_audio_occlusion_rate,
-         target = powf( occlusion, 6.0f );
+         target = powf( vg_maxf(occlusion,0.0f), 6.0f );
    audio_occlusion_current = vg_lerpf( audio_occlusion_current, target, rate );
 }
 
@@ -315,20 +382,20 @@ VG_STATIC enum audio_sprite_type audio_sample_sprite_random( v3f origin,
    ray_hit contact;
    contact.dist = vg_minf( 16.0f, pos[1] );
 
+   world_instance *world = get_active_world();
    
-   if( ray_world( pos, (v3f){0.0f,-1.0f,0.0f}, &contact ) )
-   {
-      struct world_material *mat = ray_hit_material( &contact );
+   if( ray_world( world, pos, (v3f){0.0f,-1.0f,0.0f}, &contact ) ){
+      struct world_surface *mat = ray_hit_surface( world, &contact );
 
-      if( mat->info.surface_prop == k_surface_prop_grass) 
-      {
+      if( mat->info.surface_prop == k_surface_prop_grass){
          v3_copy( contact.pos, output );
          return k_audio_sprite_type_grass;
       }
-      else
-      {
+      else{
+#if 0
          vg_line( pos, contact.pos, 0xff0000ff );
          vg_line_pt3( contact.pos, 0.3f, 0xff0000ff );
+#endif
          return k_audio_sprite_type_none;
       }
    }
@@ -337,7 +404,7 @@ VG_STATIC enum audio_sprite_type audio_sample_sprite_random( v3f origin,
    output[1] = 0.0f;
    output[2] = pos[2];
    
-   if( world.water.enabled )
+   if( world->water.enabled )
       return k_audio_sprite_type_water;
    else
       return k_audio_sprite_type_none;