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
= main_camera
.transform
[3],
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_player4
, phys
->rb
.co
);
63 audio_player_set_position( &audio_player_gate
, world
.render_gate_pos
);
64 audio_player_set_vol( &audio_player_gate
, 5.0f
);
66 v3_sub( phys
->rb
.co
, main_camera
.transform
[3], delta
);
67 v3_normalize( delta
);
68 m3x3_mulv( main_camera
.transform
, ears
, ears
);
70 /* TODO, Make function */
71 v3_copy( ears
, vg_audio
.listener_ears
);
72 v3_copy( main_camera
.transform
[3], vg_audio
.listener_pos
);
74 /* Tunnel / occlusion */
75 audio_sample_occlusion( main_camera
.transform
[3] );
77 int sprite_avail
= -1;
78 for( int i
=0; i
<vg_list_size(ambient_sprites
); i
++ )
80 if( !audio_player_is_playing( &ambient_sprites
[i
] ) )
87 if( sprite_avail
!= -1 )
90 enum audio_sprite_type sprite_type
=
91 audio_sample_sprite_random( phys
->rb
.co
, waterpos
);
93 if( sprite_type
!= k_audio_sprite_type_none
)
95 audio_player
*avail
= &ambient_sprites
[ sprite_avail
];
97 audio_player_set_vol( avail
, 20.0f
);
98 audio_player_set_flags( avail
, AUDIO_FLAG_SPACIAL_3D
);
99 audio_player_set_position( avail
, waterpos
);
101 if( sprite_type
== k_audio_sprite_type_grass
)
103 audio_player_playclip( avail
, &audio_grass
[rand()%4] );
105 else if( sprite_type
== k_audio_sprite_type_water
)
107 if( world
.water
.enabled
)
108 audio_player_playclip( avail
, &audio_water
[rand()%6] );
113 if( freecam
|| player
.is_dead
|| !phys
->on_board
)
115 audio_player_set_vol( &audio_player0
, 0.0f
);
116 audio_player_set_vol( &audio_player1
, 0.0f
);
117 audio_player_set_vol( &audio_player2
, 0.0f
);
118 audio_player_set_vol( &audio_player3
, 0.0f
);
119 audio_player_set_vol( &audio_player4
, 0.0f
);
122 if( vg_fractf(player
.walk_timer
) > 0.5f
)
127 if( (player
.step_phase
!= walk_phase
) && !phys
->in_air
)
129 audio_player_set_flags( &audio_player_extra
, AUDIO_FLAG_SPACIAL_3D
);
130 audio_player_set_position( &audio_player_extra
, phys
->rb
.co
);
131 audio_player_set_vol( &audio_player_extra
, 6.0f
);
133 if( player
.surface_prop
== k_surface_prop_concrete
)
135 audio_player_playclip(
137 &audio_footsteps
[rand()%vg_list_size(audio_footsteps
)]
140 else if( player
.surface_prop
== k_surface_prop_grass
)
142 audio_player_playclip(
144 &audio_footsteps_grass
[rand()%vg_list_size(audio_footsteps_grass
)]
147 else if( player
.surface_prop
== k_surface_prop_wood
)
149 audio_player_playclip(
151 &audio_footsteps_wood
[rand()%vg_list_size(audio_footsteps_wood
)]
156 player
.step_phase
= walk_phase
;
161 float speed
= vg_minf(v3_length( phys
->rb
.v
)*0.1f
,1.0f
),
163 slide
= vg_clampf( fabsf(phys
->slip
), 0.0f
, 1.0f
),
165 vol0
= (1.0f
-air
)*attn
*(1.0f
-slide
)*(1.0f
-grind
),
166 vol1
= air
*attn
*(1.0f
-grind
),
167 vol2
= (1.0f
-air
)*attn
*slide
*(1.0f
-grind
),
170 audio_player_set_vol( &audio_player0
, vol0
*vg
.time_rate
);
171 audio_player_set_vol( &audio_player1
, vol1
*vg
.time_rate
);
172 audio_player_set_vol( &audio_player2
, vol2
*vg
.time_rate
);
173 audio_player_set_vol( &audio_player4
, vol4
*vg
.time_rate
);
175 float reverb_amt
= vol0
* audio_occlusion_current
* 0.5f
;
177 audio_player_set_pan( &audio_player3
, 0.0f
);
178 audio_player_set_vol( &audio_player3
, reverb_amt
*vg
.time_rate
);
182 world_audio_update( cam
, ears
);
186 if( player
.phys
.in_air
)
187 player
.air_time
+= vg
.time_delta
;
189 player
.air_time
= 0.0f
;
193 #endif /* PLAYER_AUDIO_H */