2 * Copyright (C) 2021-2022 Mt.ZERO Software, Harry Godden - All Rights Reserved
13 VG_STATIC
void player_audio(void)
15 struct player_phys
*phys
= &player
.phys
;
22 static double last_revert
= -2000.0;
29 double revert_delta
= vg
.time
- last_revert
;
30 if( phys
->on_board
&& (!_air
&& l2
) && (revert_delta
> 0.7) &&
31 (player
.air_time
> 0.5f
) )
33 audio_player_set_position( &audio_player_extra
, phys
->rb
.co
);
34 audio_player_set_flags( &audio_player_extra
, AUDIO_FLAG_SPACIAL_3D
);
35 audio_player_set_vol( &audio_player_extra
, 2.0f
);
37 if( (fabsf(phys
->slip
) > 0.75f
) )
39 audio_player_playclip( &audio_player_extra
, &audio_lands
[rand()%2+3] );
43 audio_player_playclip( &audio_player_extra
, &audio_lands
[rand()%3] );
46 last_revert
= vg
.time
;
49 static float air
= 0.0f
;
50 air
= vg_lerpf( air
, phys
->in_air
? 1.0f
: 0.0f
, 5.0f
*vg
.time_delta
);
53 v3f ears
= { 1.0f
,0.0f
,0.0f
};
56 float *cam
= camera_pos
,
59 audio_player_set_position( &audio_player0
, phys
->rb
.co
);
60 audio_player_set_position( &audio_player1
, phys
->rb
.co
);
61 audio_player_set_position( &audio_player2
, phys
->rb
.co
);
62 audio_player_set_position( &audio_player_gate
, world
.render_gate_pos
);
63 audio_player_set_vol( &audio_player_gate
, 5.0f
);
65 v3_sub( phys
->rb
.co
, camera_pos
, delta
);
66 v3_normalize( delta
);
67 m3x3_mulv( camera_mtx
, ears
, ears
);
69 /* TODO, Make function */
70 v3_copy( ears
, vg_audio
.listener_ears
);
71 v3_copy( camera_pos
, vg_audio
.listener_pos
);
73 /* Tunnel / occlusion */
74 audio_sample_occlusion( camera_pos
);
76 int sprite_avail
= -1;
77 for( int i
=0; i
<vg_list_size(ambient_sprites
); i
++ )
79 if( !audio_player_is_playing( &ambient_sprites
[i
] ) )
86 if( sprite_avail
!= -1 )
89 enum audio_sprite_type sprite_type
=
90 audio_sample_sprite_random( phys
->rb
.co
, waterpos
);
92 if( sprite_type
!= k_audio_sprite_type_none
)
94 audio_player
*avail
= &ambient_sprites
[ sprite_avail
];
96 audio_player_set_vol( avail
, 20.0f
);
97 audio_player_set_flags( avail
, AUDIO_FLAG_SPACIAL_3D
);
98 audio_player_set_position( avail
, waterpos
);
100 if( sprite_type
== k_audio_sprite_type_grass
)
102 audio_player_playclip( avail
, &audio_grass
[rand()%4] );
104 else if( sprite_type
== k_audio_sprite_type_water
)
106 if( world
.water
.enabled
)
107 audio_player_playclip( avail
, &audio_water
[rand()%6] );
112 if( freecam
|| player
.is_dead
|| !phys
->on_board
)
114 audio_player_set_vol( &audio_player0
, 0.0f
);
115 audio_player_set_vol( &audio_player1
, 0.0f
);
116 audio_player_set_vol( &audio_player2
, 0.0f
);
117 audio_player_set_vol( &audio_player3
, 0.0f
);
120 if( vg_fractf(player
.walk_timer
) > 0.5f
)
125 if( (player
.step_phase
!= walk_phase
) && !phys
->in_air
)
127 audio_player_set_flags( &audio_player_extra
, AUDIO_FLAG_SPACIAL_3D
);
128 audio_player_set_position( &audio_player_extra
, phys
->rb
.co
);
129 audio_player_set_vol( &audio_player_extra
, 6.0f
);
131 if( player
.surface_prop
== k_surface_prop_concrete
)
133 audio_player_playclip(
135 &audio_footsteps
[rand()%vg_list_size(audio_footsteps
)]
138 else if( player
.surface_prop
== k_surface_prop_grass
)
140 audio_player_playclip(
142 &audio_footsteps_grass
[rand()%vg_list_size(audio_footsteps_grass
)]
145 else if( player
.surface_prop
== k_surface_prop_wood
)
147 audio_player_playclip(
149 &audio_footsteps_wood
[rand()%vg_list_size(audio_footsteps_wood
)]
154 player
.step_phase
= walk_phase
;
159 float speed
= vg_minf(v3_length( phys
->rb
.v
)*0.1f
,1.0f
),
161 slide
= vg_clampf( fabsf(phys
->slip
), 0.0f
, 1.0f
),
162 vol0
= (1.0f
-air
)*attn
*(1.0f
-slide
),
164 vol2
= (1.0f
-air
)*attn
*slide
;
166 audio_player_set_vol( &audio_player0
, vol0
*vg
.time_rate
);
167 audio_player_set_vol( &audio_player1
, vol1
*vg
.time_rate
);
168 audio_player_set_vol( &audio_player2
, vol2
*vg
.time_rate
);
170 float reverb_amt
= vol0
* audio_occlusion_current
* 0.5f
;
171 audio_player_set_pan( &audio_player3
, 0.0f
);
172 audio_player_set_vol( &audio_player3
, reverb_amt
*vg
.time_rate
);
176 world_audio_update( cam
, ears
);
180 if( player
.phys
.in_air
)
181 player
.air_time
+= vg
.time_delta
;
183 player
.air_time
= 0.0f
;
187 #endif /* PLAYER_AUDIO_H */