maths api changes
[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_hits[] =
34 {
35 { .path="sound/hit0.ogg" },
36 { .path="sound/hit1.ogg" },
37 { .path="sound/hit2.ogg" },
38 { .path="sound/hit3.ogg" },
39 { .path="sound/hit4.ogg" }
40 };
41
42 audio_clip audio_splash =
43 { .path = "sound/splash.ogg" };
44
45 audio_clip audio_jumps[] = {
46 { .path = "sound/jump0.ogg" },
47 { .path = "sound/jump1.ogg" },
48 };
49
50 audio_clip audio_footsteps[] = {
51 {.path = "sound/step_concrete0.ogg" },
52 {.path = "sound/step_concrete1.ogg" },
53 {.path = "sound/step_concrete2.ogg" },
54 {.path = "sound/step_concrete3.ogg" }
55 };
56
57 audio_clip audio_footsteps_grass[] = {
58 {.path = "sound/step_bush0.ogg" },
59 {.path = "sound/step_bush1.ogg" },
60 {.path = "sound/step_bush2.ogg" },
61 {.path = "sound/step_bush3.ogg" },
62 {.path = "sound/step_bush4.ogg" },
63 {.path = "sound/step_bush5.ogg" }
64 };
65
66 audio_clip audio_footsteps_wood[] = {
67 {.path = "sound/step_wood0.ogg" },
68 {.path = "sound/step_wood1.ogg" },
69 {.path = "sound/step_wood2.ogg" },
70 {.path = "sound/step_wood3.ogg" },
71 {.path = "sound/step_wood4.ogg" },
72 {.path = "sound/step_wood5.ogg" }
73 };
74
75 audio_clip audio_lands[] = {
76 { .path = "sound/land0.ogg" },
77 { .path = "sound/land1.ogg" },
78 { .path = "sound/land2.ogg" },
79 { .path = "sound/landsk0.ogg" },
80 { .path = "sound/landsk1.ogg" },
81 { .path = "sound/onto.ogg" },
82 { .path = "sound/outo.ogg" },
83 };
84
85 audio_clip audio_water[] = {
86 { .path = "sound/wave0.ogg" },
87 { .path = "sound/wave1.ogg" },
88 { .path = "sound/wave2.ogg" },
89 { .path = "sound/wave3.ogg" },
90 { .path = "sound/wave4.ogg" },
91 { .path = "sound/wave5.ogg" }
92 };
93
94 audio_clip audio_grass[] = {
95 { .path = "sound/grass0.ogg" },
96 { .path = "sound/grass1.ogg" },
97 { .path = "sound/grass2.ogg" },
98 { .path = "sound/grass3.ogg" },
99 };
100
101 audio_clip audio_ambience[] =
102 {
103 { .path="sound/town_generic.ogg" }
104 };
105
106 audio_clip audio_gate_pass = {
107 .path = "sound/gate_pass.ogg"
108 };
109
110 audio_clip audio_gate_lap = {
111 .path = "sound/gate_lap.ogg"
112 };
113
114 audio_clip audio_gate_ambient = {
115 .path = "sound/gate_ambient.ogg"
116 };
117
118 audio_clip audio_rewind[] = {
119 { .path = "sound/rewind_start.ogg" },
120 { .path = "sound/rewind_end_1.5.ogg" },
121 { .path = "sound/rewind_end_2.5.ogg" },
122 { .path = "sound/rewind_end_6.5.ogg" },
123 { .path = "sound/rewind_clack.ogg" },
124 };
125
126 audio_clip audio_ui[] = {
127 { .path = "sound/ui_click.ogg" },
128 { .path = "sound/ui_ding.ogg" },
129 };
130
131 VG_STATIC void audio_init(void)
132 {
133 audio_clip_loadn( audio_board, vg_list_size(audio_board), NULL );
134 audio_clip_loadn( audio_taps, vg_list_size(audio_taps), NULL );
135 audio_clip_loadn( audio_hits, vg_list_size(audio_hits), NULL );
136 audio_clip_loadn( audio_ambience, vg_list_size(audio_ambience), NULL );
137 audio_clip_loadn( &audio_splash, 1, NULL );
138 audio_clip_loadn( &audio_gate_pass, 1, NULL );
139 audio_clip_loadn( &audio_gate_lap, 1, NULL );
140 audio_clip_loadn( &audio_gate_ambient, 1, NULL );
141
142 audio_clip_loadn( audio_jumps, vg_list_size(audio_jumps), NULL );
143 audio_clip_loadn( audio_lands, vg_list_size(audio_lands), NULL );
144 audio_clip_loadn( audio_water, vg_list_size(audio_water), NULL );
145 audio_clip_loadn( audio_grass, vg_list_size(audio_grass), NULL );
146 audio_clip_loadn( audio_footsteps, vg_list_size(audio_footsteps), NULL );
147 audio_clip_loadn( audio_footsteps_grass,
148 vg_list_size(audio_footsteps_grass), NULL );
149 audio_clip_loadn( audio_footsteps_wood,
150 vg_list_size(audio_footsteps_wood), NULL );
151 audio_clip_loadn( audio_rewind, vg_list_size(audio_rewind), NULL );
152 audio_clip_loadn( audio_ui, vg_list_size(audio_ui), NULL );
153
154 audio_lock();
155 audio_set_lfo_wave( 0, k_lfo_polynomial_bipolar, 80.0f );
156 audio_set_lfo_frequency( 0, 20.0f );
157 audio_unlock();
158 }
159
160 VG_STATIC void audio_free(void)
161 {
162 /* TODO! */
163 vg_warn( "UNIMPLEMENTED: audio_free()\n" );
164 }
165
166 enum audio_sprite_type
167 {
168 k_audio_sprite_type_none,
169 k_audio_sprite_type_grass,
170 k_audio_sprite_type_water
171 };
172
173 VG_STATIC void audio_ambient_sprite_play( v3f co, audio_clip *clip )
174 {
175 audio_lock();
176 u32 channel_id = 31342352;
177 audio_channel *ch = audio_get_group_idle_channel( channel_id, 4 );
178
179 if( ch ){
180 audio_channel_init( ch, clip, AUDIO_FLAG_SPACIAL_3D );
181 audio_channel_group( ch, channel_id );
182 audio_channel_set_spacial( ch, co, 80.0f );
183 audio_channel_edit_volume( ch, 1.0f, 1 );
184 ch = audio_relinquish_channel( ch );
185 }
186 audio_unlock();
187 }
188
189 VG_STATIC
190 enum audio_sprite_type world_audio_sample_sprite_random(v3f origin, v3f output);
191 VG_STATIC void audio_ambient_sprites_update( world_instance *world, v3f co )
192 {
193 static float accum = 0.0f;
194 accum += vg.time_delta;
195
196 if( accum > 0.1f )
197 accum -= 0.1f;
198 else return;
199
200 v3f sprite_pos;
201 enum audio_sprite_type sprite_type =
202 world_audio_sample_sprite_random( co, sprite_pos );
203
204 if( sprite_type != k_audio_sprite_type_none ){
205 if( sprite_type == k_audio_sprite_type_grass ){
206 audio_ambient_sprite_play( sprite_pos, &audio_grass[vg_randu32()%4] );
207 }
208 else if( sprite_type == k_audio_sprite_type_water ){
209 if( world->water.enabled ){
210 audio_ambient_sprite_play( sprite_pos,
211 &audio_water[vg_randu32()%6] );
212 }
213 }
214 }
215 }
216
217 #endif /* AUDIO_H */