add late flips
[carveJwlIkooP6JGAAIwe30JlM.git] / audio.h
1 /*
2 * Copyright (C) 2021-2022 Mt.ZERO Software, Harry Godden - All Rights Reserved
3 */
4
5 #include "common.h"
6
7 #ifndef AUDIO_H
8 #define AUDIO_H
9
10 #include "world.h"
11
12 audio_clip audio_board[] =
13 {
14 { .path="sound/skate_hpf.ogg" },
15 { .path="sound/wheel.ogg" },
16 { .path="sound/slide.ogg" },
17 { .path="sound/grind_enter.ogg" },
18 { .path="sound/grind_exit.ogg" },
19 { .path="sound/grind_loop.ogg" },
20 { .path="sound/woodslide.ogg" },
21 { .path="sound/metalscrape.ogg" },
22 { .path="sound/slidetap.ogg" }
23 };
24
25 audio_clip audio_taps[] =
26 {
27 { .path="sound/tap0.ogg" },
28 { .path="sound/tap1.ogg" },
29 { .path="sound/tap2.ogg" },
30 { .path="sound/tap3.ogg" }
31 };
32
33 audio_clip audio_flips[] =
34 {
35 { .path="sound/lf0.ogg" },
36 { .path="sound/lf1.ogg" },
37 { .path="sound/lf2.ogg" },
38 { .path="sound/lf3.ogg" },
39 };
40
41 audio_clip audio_hits[] =
42 {
43 { .path="sound/hit0.ogg" },
44 { .path="sound/hit1.ogg" },
45 { .path="sound/hit2.ogg" },
46 { .path="sound/hit3.ogg" },
47 { .path="sound/hit4.ogg" }
48 };
49
50 audio_clip audio_splash =
51 { .path = "sound/splash.ogg" };
52
53 audio_clip audio_jumps[] = {
54 { .path = "sound/jump0.ogg" },
55 { .path = "sound/jump1.ogg" },
56 };
57
58 audio_clip audio_footsteps[] = {
59 {.path = "sound/step_concrete0.ogg" },
60 {.path = "sound/step_concrete1.ogg" },
61 {.path = "sound/step_concrete2.ogg" },
62 {.path = "sound/step_concrete3.ogg" }
63 };
64
65 audio_clip audio_footsteps_grass[] = {
66 {.path = "sound/step_bush0.ogg" },
67 {.path = "sound/step_bush1.ogg" },
68 {.path = "sound/step_bush2.ogg" },
69 {.path = "sound/step_bush3.ogg" },
70 {.path = "sound/step_bush4.ogg" },
71 {.path = "sound/step_bush5.ogg" }
72 };
73
74 audio_clip audio_footsteps_wood[] = {
75 {.path = "sound/step_wood0.ogg" },
76 {.path = "sound/step_wood1.ogg" },
77 {.path = "sound/step_wood2.ogg" },
78 {.path = "sound/step_wood3.ogg" },
79 {.path = "sound/step_wood4.ogg" },
80 {.path = "sound/step_wood5.ogg" }
81 };
82
83 audio_clip audio_lands[] = {
84 { .path = "sound/land0.ogg" },
85 { .path = "sound/land1.ogg" },
86 { .path = "sound/land2.ogg" },
87 { .path = "sound/landsk0.ogg" },
88 { .path = "sound/landsk1.ogg" },
89 { .path = "sound/onto.ogg" },
90 { .path = "sound/outo.ogg" },
91 };
92
93 audio_clip audio_water[] = {
94 { .path = "sound/wave0.ogg" },
95 { .path = "sound/wave1.ogg" },
96 { .path = "sound/wave2.ogg" },
97 { .path = "sound/wave3.ogg" },
98 { .path = "sound/wave4.ogg" },
99 { .path = "sound/wave5.ogg" }
100 };
101
102 audio_clip audio_grass[] = {
103 { .path = "sound/grass0.ogg" },
104 { .path = "sound/grass1.ogg" },
105 { .path = "sound/grass2.ogg" },
106 { .path = "sound/grass3.ogg" },
107 };
108
109 audio_clip audio_ambience[] =
110 {
111 { .path="sound/town_generic.ogg" }
112 };
113
114 audio_clip audio_gate_pass = {
115 .path = "sound/gate_pass.ogg"
116 };
117
118 audio_clip audio_gate_lap = {
119 .path = "sound/gate_lap.ogg"
120 };
121
122 audio_clip audio_gate_ambient = {
123 .path = "sound/gate_ambient.ogg"
124 };
125
126 audio_clip audio_rewind[] = {
127 { .path = "sound/rewind_start.ogg" },
128 { .path = "sound/rewind_end_1.5.ogg" },
129 { .path = "sound/rewind_end_2.5.ogg" },
130 { .path = "sound/rewind_end_6.5.ogg" },
131 { .path = "sound/rewind_clack.ogg" },
132 };
133
134 audio_clip audio_ui[] = {
135 { .path = "sound/ui_click.ogg" },
136 { .path = "sound/ui_ding.ogg" },
137 { .path = "sound/teleport.ogg" }
138 };
139
140 audio_clip audio_challenge[] = {
141 { .path = "sound/objective0.ogg" },
142 { .path = "sound/objective1.ogg" },
143 { .path = "sound/objective_win.ogg" },
144 { .path = "sound/ui_good.ogg" },
145 { .path = "sound/ui_inf.ogg" },
146 { .path = "sound/ui_ok.ogg" },
147 { .path = "sound/objective_fail.ogg" }
148 };
149
150 static void audio_init(void)
151 {
152 audio_clip_loadn( audio_board, vg_list_size(audio_board), NULL );
153 audio_clip_loadn( audio_taps, vg_list_size(audio_taps), NULL );
154 audio_clip_loadn( audio_flips, vg_list_size(audio_flips), NULL );
155 audio_clip_loadn( audio_hits, vg_list_size(audio_hits), NULL );
156 audio_clip_loadn( audio_ambience, vg_list_size(audio_ambience), NULL );
157 audio_clip_loadn( &audio_splash, 1, NULL );
158 audio_clip_loadn( &audio_gate_pass, 1, NULL );
159 audio_clip_loadn( &audio_gate_lap, 1, NULL );
160 audio_clip_loadn( &audio_gate_ambient, 1, NULL );
161
162 audio_clip_loadn( audio_jumps, vg_list_size(audio_jumps), NULL );
163 audio_clip_loadn( audio_lands, vg_list_size(audio_lands), NULL );
164 audio_clip_loadn( audio_water, vg_list_size(audio_water), NULL );
165 audio_clip_loadn( audio_grass, vg_list_size(audio_grass), NULL );
166 audio_clip_loadn( audio_footsteps, vg_list_size(audio_footsteps), NULL );
167 audio_clip_loadn( audio_footsteps_grass,
168 vg_list_size(audio_footsteps_grass), NULL );
169 audio_clip_loadn( audio_footsteps_wood,
170 vg_list_size(audio_footsteps_wood), NULL );
171 audio_clip_loadn( audio_rewind, vg_list_size(audio_rewind), NULL );
172 audio_clip_loadn( audio_ui, vg_list_size(audio_ui), NULL );
173 audio_clip_loadn( audio_challenge, vg_list_size(audio_challenge), NULL );
174
175 audio_lock();
176 audio_set_lfo_wave( 0, k_lfo_polynomial_bipolar, 80.0f );
177 audio_set_lfo_frequency( 0, 20.0f );
178 audio_unlock();
179 }
180
181 static void audio_free(void)
182 {
183 /* TODO! */
184 vg_warn( "UNIMPLEMENTED: audio_free()\n" );
185 }
186
187 enum audio_sprite_type
188 {
189 k_audio_sprite_type_none,
190 k_audio_sprite_type_grass,
191 k_audio_sprite_type_water
192 };
193
194 static void audio_ambient_sprite_play( v3f co, audio_clip *clip )
195 {
196 audio_lock();
197 u16 group_id = 0xfff0;
198 audio_channel *ch = audio_get_group_idle_channel( group_id, 4 );
199
200 if( ch ){
201 audio_channel_init( ch, clip, AUDIO_FLAG_SPACIAL_3D );
202 audio_channel_group( ch, group_id );
203 audio_channel_set_spacial( ch, co, 80.0f );
204 audio_channel_edit_volume( ch, 1.0f, 1 );
205 ch = audio_relinquish_channel( ch );
206 }
207 audio_unlock();
208 }
209
210 static
211 enum audio_sprite_type world_audio_sample_sprite_random(v3f origin, v3f output);
212 static void audio_ambient_sprites_update( world_instance *world, v3f co )
213 {
214 static float accum = 0.0f;
215 accum += vg.time_delta;
216
217 if( accum > 0.1f )
218 accum -= 0.1f;
219 else return;
220
221 v3f sprite_pos;
222 enum audio_sprite_type sprite_type =
223 world_audio_sample_sprite_random( co, sprite_pos );
224
225 if( sprite_type != k_audio_sprite_type_none ){
226 if( sprite_type == k_audio_sprite_type_grass ){
227 audio_ambient_sprite_play( sprite_pos, &audio_grass[vg_randu32()%4] );
228 }
229 else if( sprite_type == k_audio_sprite_type_water ){
230 if( world->water.enabled ){
231 audio_ambient_sprite_play( sprite_pos,
232 &audio_water[vg_randu32()%6] );
233 }
234 }
235 }
236 }
237
238 #endif /* AUDIO_H */