X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=audio.h;h=d1fd1cc6277196453fcb3c8fad653457f127dc85;hb=f99902f513b0ad606437bf32de47405dd4ea5f98;hp=60ad27ef431bccbdbe113dbe5ed0cc099d2bc341;hpb=0cf7e0563088708f2749f7dacd26ffdf1391dccc;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/audio.h b/audio.h index 60ad27e..d1fd1cc 100644 --- a/audio.h +++ b/audio.h @@ -1,3 +1,7 @@ +/* + * Copyright (C) 2021-2022 Mt.ZERO Software, Harry Godden - All Rights Reserved + */ + #include "common.h" #ifndef AUDIO_H @@ -5,132 +9,251 @@ #include "world.h" -static float audio_occlusion_current = 0.0f, - k_audio_occlusion_rate = 1.0f; - -static int k_audio_debug_soundscape = 0; - - audio_clip audio_board[] = { - {.path="sound/skate.ogg", .source_mode=k_audio_source_mono_compressed }, - {.path="sound/wheel.ogg", .source_mode=k_audio_source_mono_compressed }, - {.path="sound/slide.ogg", .source_mode=k_audio_source_mono_compressed }, - {.path="sound/reverb.ogg",.source_mode=k_audio_source_mono_compressed } + { .path="sound/skate_hpf.ogg" }, + { .path="sound/wheel.ogg" }, + { .path="sound/slide.ogg" }, + { .path="sound/grind_enter.ogg" }, + { .path="sound/grind_exit.ogg" }, + { .path="sound/grind_loop.ogg" }, + { .path="sound/woodslide.ogg" }, + { .path="sound/metalscrape.ogg" }, + { .path="sound/slidetap.ogg" } }; -audio_player audio_player0 = +audio_clip audio_taps[] = { - .name = "Player0", + { .path="sound/tap0.ogg" }, + { .path="sound/tap1.ogg" }, + { .path="sound/tap2.ogg" }, + { .path="sound/tap3.ogg" } }; -audio_player audio_player1 = +audio_clip audio_hits[] = { - .name = "Player1", + { .path="sound/hit0.ogg" }, + { .path="sound/hit1.ogg" }, + { .path="sound/hit2.ogg" }, + { .path="sound/hit3.ogg" }, + { .path="sound/hit4.ogg" } }; -audio_player audio_player2 = -{ - .name = "Player2", +audio_clip audio_splash = +{ .path = "sound/splash.ogg" }; + +audio_clip audio_jumps[] = { + { .path = "sound/jump0.ogg" }, + { .path = "sound/jump1.ogg" }, }; -audio_player audio_player3 = -{ - .name = "Player3", +audio_clip audio_footsteps[] = { + {.path = "sound/step_concrete0.ogg" }, + {.path = "sound/step_concrete1.ogg" }, + {.path = "sound/step_concrete2.ogg" }, + {.path = "sound/step_concrete3.ogg" } +}; + +audio_clip audio_footsteps_grass[] = { + {.path = "sound/step_bush0.ogg" }, + {.path = "sound/step_bush1.ogg" }, + {.path = "sound/step_bush2.ogg" }, + {.path = "sound/step_bush3.ogg" }, + {.path = "sound/step_bush4.ogg" }, + {.path = "sound/step_bush5.ogg" } +}; + +audio_clip audio_footsteps_wood[] = { + {.path = "sound/step_wood0.ogg" }, + {.path = "sound/step_wood1.ogg" }, + {.path = "sound/step_wood2.ogg" }, + {.path = "sound/step_wood3.ogg" }, + {.path = "sound/step_wood4.ogg" }, + {.path = "sound/step_wood5.ogg" } }; -static void audio_init(void) +audio_clip audio_lands[] = { + { .path = "sound/land0.ogg" }, + { .path = "sound/land1.ogg" }, + { .path = "sound/land2.ogg" }, + { .path = "sound/landsk0.ogg" }, + { .path = "sound/landsk1.ogg" }, + { .path = "sound/onto.ogg" }, + { .path = "sound/outo.ogg" }, +}; + +audio_clip audio_water[] = { + { .path = "sound/wave0.ogg" }, + { .path = "sound/wave1.ogg" }, + { .path = "sound/wave2.ogg" }, + { .path = "sound/wave3.ogg" }, + { .path = "sound/wave4.ogg" }, + { .path = "sound/wave5.ogg" } +}; + +audio_clip audio_grass[] = { + { .path = "sound/grass0.ogg" }, + { .path = "sound/grass1.ogg" }, + { .path = "sound/grass2.ogg" }, + { .path = "sound/grass3.ogg" }, +}; + +audio_clip audio_ambience[] = { - audio_clip_loadn( audio_board, vg_list_size(audio_board) ); + { .path="sound/town_generic.ogg" } +}; - audio_lock(); - u32 flags = AUDIO_FLAG_LOOP|AUDIO_FLAG_SPACIAL_3D; +audio_clip audio_gate_pass = { + .path = "sound/gate_pass.ogg" +}; + +audio_clip audio_gate_lap = { + .path = "sound/gate_lap.ogg" +}; - audio_player_set_flags( &audio_player0, flags ); - audio_player_set_flags( &audio_player1, flags ); - audio_player_set_flags( &audio_player2, flags ); - audio_player_set_flags( &audio_player3, AUDIO_FLAG_LOOP ); +audio_clip audio_gate_ambient = { +.path = "sound/gate_ambient.ogg" +}; - audio_player_playclip( &audio_player0, &audio_board[0] ); - audio_player_playclip( &audio_player1, &audio_board[1] ); - audio_player_playclip( &audio_player2, &audio_board[2] ); - audio_player_playclip( &audio_player3, &audio_board[3] ); +audio_clip audio_rewind[] = { +{ .path = "sound/rewind_start.ogg" }, +{ .path = "sound/rewind_end_1.5.ogg" }, +{ .path = "sound/rewind_end_2.5.ogg" }, +{ .path = "sound/rewind_end_6.5.ogg" }, +{ .path = "sound/rewind_clack.ogg" }, +}; - audio_unlock(); +audio_clip audio_ui[] = { + { .path = "sound/ui_click.ogg" }, + { .path = "sound/ui_ding.ogg" }, +}; + +VG_STATIC void audio_init(void) +{ + audio_clip_loadn( audio_board, vg_list_size(audio_board), NULL ); + audio_clip_loadn( audio_taps, vg_list_size(audio_taps), NULL ); + audio_clip_loadn( audio_hits, vg_list_size(audio_hits), NULL ); + audio_clip_loadn( audio_ambience, vg_list_size(audio_ambience), NULL ); + audio_clip_loadn( &audio_splash, 1, NULL ); + audio_clip_loadn( &audio_gate_pass, 1, NULL ); + audio_clip_loadn( &audio_gate_lap, 1, NULL ); + audio_clip_loadn( &audio_gate_ambient, 1, NULL ); - 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 - }); + audio_clip_loadn( audio_jumps, vg_list_size(audio_jumps), NULL ); + audio_clip_loadn( audio_lands, vg_list_size(audio_lands), NULL ); + audio_clip_loadn( audio_water, vg_list_size(audio_water), NULL ); + audio_clip_loadn( audio_grass, vg_list_size(audio_grass), NULL ); + audio_clip_loadn( audio_footsteps, vg_list_size(audio_footsteps), NULL ); + audio_clip_loadn( audio_footsteps_grass, + vg_list_size(audio_footsteps_grass), NULL ); + audio_clip_loadn( audio_footsteps_wood, + vg_list_size(audio_footsteps_wood), NULL ); + audio_clip_loadn( audio_rewind, vg_list_size(audio_rewind), NULL ); + audio_clip_loadn( audio_ui, vg_list_size(audio_ui), NULL ); + + audio_lock(); + audio_set_lfo_wave( 0, k_lfo_polynomial_bipolar, 80.0f ); + audio_set_lfo_frequency( 0, 20.0f ); + audio_unlock(); } -static void audio_free(void) +VG_STATIC void audio_free(void) { + /* TODO! */ + vg_warn( "UNIMPLEMENTED: audio_free()\n" ); } -static void audio_sample_occlusion( v3f origin ) +enum audio_sprite_type { - float d = 0.0f, - sample_dist = 880.0f; + k_audio_sprite_type_none, + k_audio_sprite_type_grass, + k_audio_sprite_type_water +}; - int sample_count = 8; +/* + * Trace out a random point, near the player to try and determine water areas + */ +VG_STATIC enum audio_sprite_type audio_sample_sprite_random( v3f origin, + v3f output ) +{ + v3f chance = { (vg_randf()-0.5f) * 30.0f, + 8.0f, + (vg_randf()-0.5f) * 30.0f }; + + v3f pos; + v3_add( chance, origin, pos ); - for( int i=0; iinfo.surface_prop == k_surface_prop_grass){ + v3_copy( contact.pos, output ); + return k_audio_sprite_type_grass; } - else - { - v3f p1; - v3_muladds( origin, dir, sample_dist, p1 ); - vg_line( origin, p1, 0xffcccccc ); - - d += sample_dist; + else{ +#if 0 + vg_line( pos, contact.pos, 0xff0000ff ); + vg_line_pt3( contact.pos, 0.3f, 0xff0000ff ); +#endif + return k_audio_sprite_type_none; } } - 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 ); + output[0] = pos[0]; + output[1] = 0.0f; + output[2] = pos[2]; + + float dist = fabsf(output[1] - origin[1]); + + if( world->water.enabled && dist<=40.0f ) + return k_audio_sprite_type_water; + else + return k_audio_sprite_type_none; } -static void audio_debug_soundscapes(void) +VG_STATIC void audio_ambient_sprite_play( v3f co, audio_clip *clip ) { - if( !k_audio_debug_soundscape ) return; + audio_lock(); + u32 channel_id = 31342352; + audio_channel *ch = audio_get_group_idle_channel( channel_id, 4 ); - char buf[64]; - snprintf( buf, 31, "occlusion: %.5f", audio_occlusion_current ); + if( ch ){ + audio_channel_init( ch, clip, AUDIO_FLAG_SPACIAL_3D ); + audio_channel_group( ch, channel_id ); + audio_channel_set_spacial( ch, co, 80.0f ); + audio_channel_edit_volume( ch, 1.0f, 1 ); + ch = audio_relinquish_channel( ch ); + } + audio_unlock(); +} - ui_global_ctx.cursor[0] = 450; - ui_global_ctx.cursor[1] = 10; - ui_global_ctx.cursor[2] = audio_occlusion_current * 200.0f; - ui_global_ctx.cursor[3] = 20; +VG_STATIC void audio_ambient_sprites_update( world_instance *world, v3f co ) +{ + static float accum = 0.0f; + accum += vg.frame_delta; + + if( accum > 0.1f ) + accum -= 0.1f; + else return; - gui_fill_rect( ui_global_ctx.cursor, 0x55cccccc ); - gui_text( ui_global_ctx.cursor, buf, 1, 0 ); + v3f sprite_pos; + enum audio_sprite_type sprite_type = + audio_sample_sprite_random( co, sprite_pos ); + + if( sprite_type != k_audio_sprite_type_none ){ + if( sprite_type == k_audio_sprite_type_grass ){ + audio_ambient_sprite_play( sprite_pos, &audio_grass[rand()%4] ); + } + else if( sprite_type == k_audio_sprite_type_water ){ + if( world->water.enabled ) + audio_ambient_sprite_play( sprite_pos, &audio_water[rand()%6] ); + } + } } #endif /* AUDIO_H */