-#ifndef AUDIO_H
-#define AUDIO_H
+/*
+ * Copyright (C) 2021-2022 Mt.ZERO Software, Harry Godden - All Rights Reserved
+ */
-#include "common.h"
-#include "world.h"
-
-static float audio_occlusion_current = 0.0f,
- k_audio_occlusion_rate = 1.0f;
-
-static int k_audio_debug_soundscape = 0;
-
-sfx_vol_control audio_vol_all = { .val = 1.0f, .name = "All" };
-
-sfx_set audio_board =
-{
- .sources = "sound/skate.ogg\0"
- "sound/wheel.ogg\0"
- "sound/slide.ogg\0"
- "sound/reverb.ogg\0"
-};
-
-sfx_system audio_player0 =
-{
- .vol = 0.0f,
- .ch = 1,
- .vol_src = &audio_vol_all,
- .name = "Player0",
- .flags = SFX_FLAG_REPEAT | SFX_FLAG_PERSISTENT
-};
-
-sfx_system audio_player1 =
-{
- .vol = 0.0f,
- .ch = 1,
- .vol_src = &audio_vol_all,
- .name = "Player1",
- .flags = SFX_FLAG_REPEAT | SFX_FLAG_PERSISTENT
-};
-
-sfx_system audio_player2 =
-{
- .vol = 0.0f,
- .ch = 1,
- .vol_src = &audio_vol_all,
- .name = "Player2",
- .flags = SFX_FLAG_REPEAT | SFX_FLAG_PERSISTENT
-};
-
-sfx_system audio_player3 =
-{
- .vol = 0.0f,
- .ch = 1,
- .vol_src = &audio_vol_all,
- .name = "Player3",
- .flags = SFX_FLAG_REPEAT | SFX_FLAG_PERSISTENT
-};
-
-static void audio_init(void)
-{
- sfx_set_init( &audio_board, NULL );
- sfx_set_play( &audio_board, &audio_player0, 0 );
- sfx_set_play( &audio_board, &audio_player1, 1 );
- sfx_set_play( &audio_board, &audio_player2, 2 );
- sfx_set_play( &audio_board, &audio_player3, 3 );
+#pragma once
- vg_convar_push( (struct vg_convar){
- .name = "aud_debug_soundscape",
- .data = &k_audio_debug_soundscape,
- .data_type = k_convar_dtype_i32,
- .opt_i32 = { .min=0, .max=1, .clamp=0 },
- .persistent = 1
- });
-
- vg_convar_push( (struct vg_convar){
- .name = "aud_occlusion_rate",
- .data = &k_audio_occlusion_rate,
- .data_type = k_convar_dtype_f32,
- .opt_f32 = { .clamp = 0 },
- .persistent = 1
- });
-}
-
-static void audio_free(void)
-{
- sfx_set_free( &audio_board );
-}
-
-static void audio_sample_occlusion( v3f origin )
-{
- float d = 0.0f,
- sample_dist = 880.0f;
-
- int sample_count = 8;
-
- for( int i=0; i<sample_count; i++ )
- {
- v3f dir;
- dir[0] = vg_randf();
- dir[1] = vg_randf();
- dir[2] = vg_randf();
-
- v3_muls( dir, 2.0f, dir );
- v3_sub( dir, (v3f){1.0f,1.0f,1.0f}, dir );
-
- v3_normalize( dir );
-
- ray_hit contact;
- contact.dist = 15.0f;
-
- if( ray_world( origin, dir, &contact ) )
- {
- d += contact.dist;
-
- vg_line( origin, contact.pos, 0xff0000ff );
- vg_line_pt3( contact.pos, 0.1f, 0xff0000ff );
- }
- else
- {
- v3f p1;
- v3_muladds( origin, dir, sample_dist, p1 );
- vg_line( origin, p1, 0xffcccccc );
-
- d += sample_dist;
- }
- }
-
- float occlusion = 1.0f - (d * (1.0f/(sample_dist*(float)sample_count))),
- rate = ktimestep * k_audio_occlusion_rate,
- target = powf( occlusion, 6.0f );
- audio_occlusion_current = vg_lerpf( audio_occlusion_current, target, rate );
-}
-
-static void audio_debug_soundscapes(void)
-{
- if( !k_audio_debug_soundscape ) return;
+#include "vg/vg_engine.h"
+#include "vg/vg_audio.h"
+#include "vg/vg_audio_dsp.h"
+#include "world.h"
- char buf[64];
- snprintf( buf, 31, "occlusion: %.5f", audio_occlusion_current );
+struct air_synth_data {
+ f32 speed;
- ui_global_ctx.cursor[0] = 10;
- ui_global_ctx.cursor[1] = 10;
- ui_global_ctx.cursor[2] = audio_occlusion_current * 200.0f;
- ui_global_ctx.cursor[3] = 20;
+ /* internal */
+ f32 t;
+ struct dsp_biquad lpf;
+ SDL_SpinLock sl;
- gui_fill_rect( ui_global_ctx.cursor, 0x55cccccc );
- gui_text( ui_global_ctx.cursor, buf, 1, 0 );
+ /* not used in locking */
+ audio_channel *channel;
}
-
-#endif /* AUDIO_H */
+extern air_audio_data;
+
+void audio_init(void);
+void audio_ambient_sprite_play( v3f co, audio_clip *clip );
+void audio_ambient_sprites_update( world_instance *world, v3f co );
+
+/* TODO(ASSETS):
+ * Have these as asignable ID's and not a bunch of different arrays.
+ */
+extern audio_clip audio_board[];
+extern audio_clip audio_taps[];
+extern audio_clip audio_flips[];
+extern audio_clip audio_hits[];
+extern audio_clip audio_splash;
+extern audio_clip audio_jumps[];
+extern audio_clip audio_footsteps[];
+extern audio_clip audio_footsteps_grass[];
+extern audio_clip audio_footsteps_wood[];
+extern audio_clip audio_lands[];
+extern audio_clip audio_water[];
+extern audio_clip audio_grass[];
+extern audio_clip audio_ambience[];
+extern audio_clip audio_gate_pass;
+extern audio_clip audio_gate_lap;
+extern audio_clip audio_gate_ambient;
+extern audio_clip audio_rewind[];
+extern audio_clip audio_ui[];
+extern audio_clip audio_challenge[];
+
+enum audio_sprite_type
+{
+ k_audio_sprite_type_none,
+ k_audio_sprite_type_grass,
+ k_audio_sprite_type_water
+};