X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=player.h;h=7f02ec0eee4e0f09e5b18bded7da3938bd266b61;hb=4625f91b85d2badbb719a7f5bcaa2426af25911b;hp=8619308a0cffe686a929574701353ca2d3be4c23;hpb=d4746875c05dd3e077e1b266e50ffe4856b45502;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/player.h b/player.h index 8619308..7f02ec0 100644 --- a/player.h +++ b/player.h @@ -719,6 +719,13 @@ static void player_physics(void) player.jump = 0.0f; player.jump_time = vg_time; + + audio_lock(); + audio_player_set_flags( &audio_player_extra, AUDIO_FLAG_SPACIAL_3D ); + audio_player_set_position( &audio_player_extra, player.rb.co ); + audio_player_set_vol( &audio_player_extra, 3.0f ); + audio_player_playclip( &audio_player_extra, &audio_jumps[rand()%4] ); + audio_unlock(); } } else @@ -802,6 +809,10 @@ static void player_do_motion(void) m3x3_copy( player.vr, player.gate_vr_frame ); m3x3_copy( player.vr_pstep, player.gate_vr_pstep_frame ); + + audio_lock(); + audio_play_oneshot( &audio_gate_lap, 1.0f ); + audio_unlock(); break; } } @@ -1137,53 +1148,96 @@ static void player_animate_camera(void) */ static void player_audio(void) { - audio_sample_occlusion( player.camera[3] ); + static int _ding = 0; + + int last = _ding; + _ding = glfwGetKey(vg_window, GLFW_KEY_C); + + int trigger_ding = 0; + if( _ding && !last ) + trigger_ding = 1; + + static int _air = 0; + + int l2 = _air; + _air = player.in_air; + + static double last_revert = -2000.0; + - float speed = vg_minf(v3_length( player.rb.v )*0.1f,1.0f), - attn = v3_dist( player.rb.co, player.camera[3] )+1.0f; - attn = (1.0f/(attn*attn)) * speed; + + + audio_lock(); + + double revert_delta = vg_time - last_revert; + if( (!_air && l2) && (fabsf(player.slip) > 0.5f) && (revert_delta > 0.7) ) + { + audio_player_set_position( &audio_player_extra, player.rb.co ); + audio_player_set_flags( &audio_player_extra, AUDIO_FLAG_SPACIAL_3D ); + audio_player_set_vol( &audio_player_extra, 2.0f ); + audio_player_playclip( &audio_player_extra, &audio_lands[rand()%5] ); + + last_revert = vg_time; + } static float air = 0.0f; air = vg_lerpf(air, player.in_air? 1.0f: 0.0f, 5.0f*ktimestep); - + + /* Spacial info */ v3f ears = { 1.0f,0.0f,0.0f }; v3f delta; + float *cam = player.camera[3], + *pos = player.rb.co; + + if( trigger_ding ) + audio_player_playclip( &audio_player_extra, &audio_ding ); + + audio_player_set_position( &audio_player0, player.rb.co ); + audio_player_set_position( &audio_player1, player.rb.co ); + audio_player_set_position( &audio_player2, player.rb.co ); + audio_player_set_position( &audio_player_gate, world.render_gate_pos ); + v3_sub( player.rb.co, player.camera[3], delta ); v3_normalize( delta ); m3x3_mulv( player.camera, ears, ears ); - - float pan = v3_dot( ears, delta ); - audio_player0.pan = pan; - audio_player1.pan = pan; - audio_player2.pan = pan; - audio_player3.pan = 0.0f; + /* TODO, Make function */ + v3_copy( ears, vg_audio.listener_ears ); + v3_copy( player.camera[3], vg_audio.listener_pos ); - if( freecam ) + /* Tunnel / occlusion */ + audio_sample_occlusion( player.camera[3] ); + + if( freecam || player.is_dead || !player.on_board ) { - audio_player0.vol = 0.0f; - audio_player1.vol = 0.0f; - audio_player2.vol = 0.0f; + audio_player_set_vol( &audio_player0, 0.0f ); + audio_player_set_vol( &audio_player1, 0.0f ); + audio_player_set_vol( &audio_player2, 0.0f ); } else { - if( player.is_dead ) - { - audio_player0.vol = 0.0f; - audio_player1.vol = 0.0f; - audio_player2.vol = 0.0f; - } - else - { - float slide = vg_clampf( fabsf(player.slip), 0.0f, 1.0f ); - audio_player0.vol = (1.0f-air)*attn*(1.0f-slide); - audio_player1.vol = air *attn; - audio_player2.vol = (1.0f-air)*attn*slide; - } - } + /* Composite */ + float speed = vg_minf(v3_length( player.rb.v )*0.1f,1.0f), + attn = speed, + slide = vg_clampf( fabsf(player.slip), 0.0f, 1.0f ), + vol0 = (1.0f-air)*attn*(1.0f-slide), + vol1 = air *attn, + vol2 = (1.0f-air)*attn*slide; + + audio_player_set_vol( &audio_player0, vol0 ); + audio_player_set_vol( &audio_player1, vol1 ); + audio_player_set_vol( &audio_player2, vol2 ); - audio_player3.vol = audio_player0.vol * audio_occlusion_current * 2.0f; + float reverb_amt = vol0 * audio_occlusion_current * 0.5f; + audio_player_set_pan( &audio_player3, 0.0f ); + audio_player_set_vol( &audio_player3, reverb_amt ); + } + +#if 0 + world_audio_update( cam, ears ); +#endif + audio_unlock(); } /*