X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=player_audio.h;h=8e5c0d2c83e7affb77a30396380bde604e7e05f1;hb=c88172d6968a02a4e643b74cc419c0ac8168d92a;hp=5402b7a6d424db068532d2f537016aec19483266;hpb=1740c935bfdacc65c5c7e4bb95fba1ada1f7118a;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/player_audio.h b/player_audio.h index 5402b7a..8e5c0d2 100644 --- a/player_audio.h +++ b/player_audio.h @@ -1,3 +1,7 @@ +/* + * Copyright (C) 2021-2022 Mt.ZERO Software, Harry Godden - All Rights Reserved + */ + #ifndef PLAYER_AUDIO_H #define PLAYER_AUDIO_H @@ -6,7 +10,7 @@ /* * Audio */ -static void player_audio(void) +VG_STATIC void player_audio(void) { struct player_phys *phys = &player.phys; @@ -21,44 +25,54 @@ static void player_audio(void) audio_lock(); - - double revert_delta = vg_time - last_revert; - if( phys->on_board && (!_air && l2) && (fabsf(phys->slip) > 0.5f) && - (revert_delta > 0.7) ) + + double revert_delta = vg.time - last_revert; + if( phys->on_board && (!_air && l2) && (revert_delta > 0.7) && + (player.air_time > 0.5f) ) { audio_player_set_position( &audio_player_extra, phys->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; + if( (fabsf(phys->slip) > 0.75f) ) + { + audio_player_playclip( &audio_player_extra, &audio_lands[rand()%2+3] ); + } + else + { + audio_player_playclip( &audio_player_extra, &audio_lands[rand()%3] ); + } + + last_revert = vg.time; } static float air = 0.0f; - air = vg_lerpf(air, phys->in_air? 1.0f: 0.0f, 5.0f*ktimestep); + air = vg_lerpf( air, phys->in_air? 1.0f: 0.0f, 5.0f*vg.time_delta ); /* Spacial info */ v3f ears = { 1.0f,0.0f,0.0f }; v3f delta; - float *cam = player.camera[3], + float *cam = main_camera.transform[3], *pos = phys->rb.co; audio_player_set_position( &audio_player0, phys->rb.co ); audio_player_set_position( &audio_player1, phys->rb.co ); audio_player_set_position( &audio_player2, phys->rb.co ); + audio_player_set_position( &audio_player4, phys->rb.co ); audio_player_set_position( &audio_player_gate, world.render_gate_pos ); + audio_player_set_vol( &audio_player_gate, 5.0f ); - v3_sub( phys->rb.co, player.camera[3], delta ); + v3_sub( phys->rb.co, main_camera.transform[3], delta ); v3_normalize( delta ); - m3x3_mulv( player.camera, ears, ears ); + m3x3_mulv( main_camera.transform, ears, ears ); /* TODO, Make function */ v3_copy( ears, vg_audio.listener_ears ); - v3_copy( player.camera[3], vg_audio.listener_pos ); + v3_copy( main_camera.transform[3], vg_audio.listener_pos ); /* Tunnel / occlusion */ - audio_sample_occlusion( player.camera[3] ); + audio_sample_occlusion( main_camera.transform[3] ); int sprite_avail = -1; for( int i=0; i 0.5f ) @@ -113,8 +129,28 @@ static void player_audio(void) audio_player_set_flags( &audio_player_extra, AUDIO_FLAG_SPACIAL_3D ); audio_player_set_position( &audio_player_extra, phys->rb.co ); audio_player_set_vol( &audio_player_extra, 6.0f ); - audio_player_playclip( &audio_player_extra, - &audio_footsteps[rand()%4] ); + + if( player.surface_prop == k_surface_prop_concrete ) + { + audio_player_playclip( + &audio_player_extra, + &audio_footsteps[rand()%vg_list_size(audio_footsteps)] + ); + } + else if( player.surface_prop == k_surface_prop_grass ) + { + audio_player_playclip( + &audio_player_extra, + &audio_footsteps_grass[rand()%vg_list_size(audio_footsteps_grass)] + ); + } + else if( player.surface_prop == k_surface_prop_wood ) + { + audio_player_playclip( + &audio_player_extra, + &audio_footsteps_wood[rand()%vg_list_size(audio_footsteps_wood)] + ); + } } player.step_phase = walk_phase; @@ -125,23 +161,33 @@ static void player_audio(void) float speed = vg_minf(v3_length( phys->rb.v )*0.1f,1.0f), attn = speed, slide = vg_clampf( fabsf(phys->slip), 0.0f, 1.0f ), - vol0 = (1.0f-air)*attn*(1.0f-slide), - vol1 = air *attn, - vol2 = (1.0f-air)*attn*slide; + grind = phys->grind, + vol0 = (1.0f-air)*attn*(1.0f-slide)*(1.0f-grind), + vol1 = air *attn*(1.0f-grind), + vol2 = (1.0f-air)*attn*slide*(1.0f-grind), + vol4 = grind*2.0f; - audio_player_set_vol( &audio_player0, vol0 ); - audio_player_set_vol( &audio_player1, vol1 ); - audio_player_set_vol( &audio_player2, vol2 ); + audio_player_set_vol( &audio_player0, vol0*vg.time_rate ); + audio_player_set_vol( &audio_player1, vol1*vg.time_rate ); + audio_player_set_vol( &audio_player2, vol2*vg.time_rate ); + audio_player_set_vol( &audio_player4, vol4*vg.time_rate ); 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 ); + audio_player_set_vol( &audio_player3, reverb_amt*vg.time_rate ); } #if 0 world_audio_update( cam, ears ); #endif audio_unlock(); + + if( player.phys.in_air ) + player.air_time += vg.time_delta; + else + player.air_time = 0.0f; + } #endif /* PLAYER_AUDIO_H */