2 * Copyright (C) 2021-2022 Mt.ZERO Software, Harry Godden - All Rights Reserved
12 VG_STATIC
float audio_occlusion_current
= 0.0f
,
13 k_audio_occlusion_rate
= 1.0f
;
15 VG_STATIC
int k_audio_debug_soundscape
= 0;
17 audio_clip audio_board
[] =
19 { .path
="sound/skate_hpf.ogg" },
20 { .path
="sound/wheel.ogg" },
21 { .path
="sound/slide.ogg" },
22 { .path
="sound/grind_enter.ogg" },
23 { .path
="sound/grind_exit.ogg" },
24 { .path
="sound/grind_loop.ogg" },
25 { .path
="sound/woodslide.ogg" },
26 { .path
="sound/metalscrape.ogg" },
27 { .path
="sound/slidetap.ogg" }
30 audio_clip audio_taps
[] =
32 { .path
="sound/tap0.ogg" },
33 { .path
="sound/tap1.ogg" },
34 { .path
="sound/tap2.ogg" },
35 { .path
="sound/tap3.ogg" }
38 audio_clip audio_hits
[] =
40 { .path
="sound/hit0.ogg" },
41 { .path
="sound/hit1.ogg" },
42 { .path
="sound/hit2.ogg" },
43 { .path
="sound/hit3.ogg" },
44 { .path
="sound/hit4.ogg" }
47 audio_clip audio_splash
=
48 { .path
= "sound/splash.ogg" };
50 audio_clip audio_jumps
[] = {
51 { .path
= "sound/jump0.ogg" },
52 { .path
= "sound/jump1.ogg" },
55 audio_clip audio_footsteps
[] = {
56 {.path
= "sound/step_concrete0.ogg" },
57 {.path
= "sound/step_concrete1.ogg" },
58 {.path
= "sound/step_concrete2.ogg" },
59 {.path
= "sound/step_concrete3.ogg" }
62 audio_clip audio_footsteps_grass
[] = {
63 {.path
= "sound/step_bush0.ogg" },
64 {.path
= "sound/step_bush1.ogg" },
65 {.path
= "sound/step_bush2.ogg" },
66 {.path
= "sound/step_bush3.ogg" },
67 {.path
= "sound/step_bush4.ogg" },
68 {.path
= "sound/step_bush5.ogg" }
71 audio_clip audio_footsteps_wood
[] = {
72 {.path
= "sound/step_wood0.ogg" },
73 {.path
= "sound/step_wood1.ogg" },
74 {.path
= "sound/step_wood2.ogg" },
75 {.path
= "sound/step_wood3.ogg" },
76 {.path
= "sound/step_wood4.ogg" },
77 {.path
= "sound/step_wood5.ogg" }
80 audio_clip audio_lands
[] = {
81 { .path
= "sound/land0.ogg" },
82 { .path
= "sound/land1.ogg" },
83 { .path
= "sound/land2.ogg" },
84 { .path
= "sound/landsk0.ogg" },
85 { .path
= "sound/landsk1.ogg" },
86 { .path
= "sound/onto.ogg" },
87 { .path
= "sound/outo.ogg" },
90 audio_clip audio_water
[] = {
91 { .path
= "sound/wave0.ogg" },
92 { .path
= "sound/wave1.ogg" },
93 { .path
= "sound/wave2.ogg" },
94 { .path
= "sound/wave3.ogg" },
95 { .path
= "sound/wave4.ogg" },
96 { .path
= "sound/wave5.ogg" }
99 audio_clip audio_grass
[] = {
100 { .path
= "sound/grass0.ogg" },
101 { .path
= "sound/grass1.ogg" },
102 { .path
= "sound/grass2.ogg" },
103 { .path
= "sound/grass3.ogg" },
106 audio_clip audio_ambience
[] =
108 { .path
="sound/town_generic.ogg" }
111 audio_clip audio_gate_pass
= {
112 .path
= "sound/gate_pass.ogg"
115 audio_clip audio_gate_lap
= {
116 .path
= "sound/gate_lap.ogg"
119 audio_clip audio_gate_ambient
= {
120 .path
= "sound/gate_ambient.ogg"
123 audio_clip audio_rewind
[] = {
124 { .path
= "sound/rewind_start.ogg" },
125 { .path
= "sound/rewind_end_1.5.ogg" },
126 { .path
= "sound/rewind_end_2.5.ogg" },
127 { .path
= "sound/rewind_end_6.5.ogg" },
128 { .path
= "sound/rewind_clack.ogg" },
131 audio_clip audio_ui
[] = {
132 { .path
= "sound/ui_click.ogg" },
133 { .path
= "sound/ui_ding.ogg" },
136 VG_STATIC
void audio_init(void)
138 audio_clip_loadn( audio_board
, vg_list_size(audio_board
), NULL
);
139 audio_clip_loadn( audio_taps
, vg_list_size(audio_taps
), NULL
);
140 audio_clip_loadn( audio_hits
, vg_list_size(audio_hits
), NULL
);
141 audio_clip_loadn( audio_ambience
, vg_list_size(audio_ambience
), NULL
);
142 audio_clip_loadn( &audio_splash
, 1, NULL
);
143 audio_clip_loadn( &audio_gate_pass
, 1, NULL
);
144 audio_clip_loadn( &audio_gate_lap
, 1, NULL
);
145 audio_clip_loadn( &audio_gate_ambient
, 1, NULL
);
147 audio_clip_loadn( audio_jumps
, vg_list_size(audio_jumps
), NULL
);
148 audio_clip_loadn( audio_lands
, vg_list_size(audio_lands
), NULL
);
149 audio_clip_loadn( audio_water
, vg_list_size(audio_water
), NULL
);
150 audio_clip_loadn( audio_grass
, vg_list_size(audio_grass
), NULL
);
151 audio_clip_loadn( audio_footsteps
, vg_list_size(audio_footsteps
), NULL
);
152 audio_clip_loadn( audio_footsteps_grass
,
153 vg_list_size(audio_footsteps_grass
), NULL
);
154 audio_clip_loadn( audio_footsteps_wood
,
155 vg_list_size(audio_footsteps_wood
), NULL
);
156 audio_clip_loadn( audio_rewind
, vg_list_size(audio_rewind
), NULL
);
157 audio_clip_loadn( audio_ui
, vg_list_size(audio_ui
), NULL
);
159 vg_var_push( (struct vg_var
){
160 .name
= "aud_debug_soundscape",
161 .data
= &k_audio_debug_soundscape
,
162 .data_type
= k_var_dtype_i32
,
163 .opt_i32
= { .min
=0, .max
=1, .clamp
=0 },
167 vg_var_push( (struct vg_var
){
168 .name
= "aud_occlusion_rate",
169 .data
= &k_audio_occlusion_rate
,
170 .data_type
= k_var_dtype_f32
,
171 .opt_f32
= { .clamp
= 0 },
176 audio_set_lfo_wave( 0, k_lfo_polynomial_bipolar
, 80.0f
);
177 audio_set_lfo_frequency( 0, 20.0f
);
181 VG_STATIC
void audio_free(void)
184 vg_warn( "UNIMPLEMENTED: audio_free()\n" );
187 enum audio_sprite_type
189 k_audio_sprite_type_none
,
190 k_audio_sprite_type_grass
,
191 k_audio_sprite_type_water
195 * Trace out a random point, near the player to try and determine water areas
197 VG_STATIC
enum audio_sprite_type
audio_sample_sprite_random( v3f origin
,
200 v3f chance
= { (vg_randf()-0.5f
) * 30.0f
,
202 (vg_randf()-0.5f
) * 30.0f
};
205 v3_add( chance
, origin
, pos
);
208 contact
.dist
= vg_minf( 16.0f
, pos
[1] );
210 world_instance
*world
= get_active_world();
212 if( ray_world( world
, pos
, (v3f
){0.0f
,-1.0f
,0.0f
}, &contact
) ){
213 struct world_surface
*mat
= ray_hit_surface( world
, &contact
);
215 if( mat
->info
.surface_prop
== k_surface_prop_grass
){
216 v3_copy( contact
.pos
, output
);
217 return k_audio_sprite_type_grass
;
221 vg_line( pos
, contact
.pos
, 0xff0000ff );
222 vg_line_pt3( contact
.pos
, 0.3f
, 0xff0000ff );
224 return k_audio_sprite_type_none
;
232 float dist
= fabsf(output
[1] - origin
[1]);
234 if( world
->water
.enabled
&& dist
<=40.0f
)
235 return k_audio_sprite_type_water
;
237 return k_audio_sprite_type_none
;
240 VG_STATIC
void audio_ambient_sprite_play( v3f co
, audio_clip
*clip
)
243 u32 channel_id
= 31342352;
244 audio_channel
*ch
= audio_get_group_idle_channel( channel_id
, 4 );
247 audio_channel_init( ch
, clip
, AUDIO_FLAG_SPACIAL_3D
);
248 audio_channel_group( ch
, channel_id
);
249 audio_channel_set_spacial( ch
, co
, 80.0f
);
250 audio_channel_edit_volume( ch
, 1.0f
, 1 );
251 ch
= audio_relinquish_channel( ch
);
256 VG_STATIC
void audio_ambient_sprites_update( world_instance
*world
, v3f co
)
258 static float accum
= 0.0f
;
259 accum
+= vg
.frame_delta
;
266 enum audio_sprite_type sprite_type
=
267 audio_sample_sprite_random( co
, sprite_pos
);
269 if( sprite_type
!= k_audio_sprite_type_none
){
270 if( sprite_type
== k_audio_sprite_type_grass
){
271 audio_ambient_sprite_play( sprite_pos
, &audio_grass
[rand()%4] );
273 else if( sprite_type
== k_audio_sprite_type_water
){
274 if( world
->water
.enabled
)
275 audio_ambient_sprite_play( sprite_pos
, &audio_water
[rand()%6] );