X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=audio.h;h=448906be07e9af05c101b3c07766578dc7612f4d;hb=refs%2Fheads%2Frigidbody;hp=b3640bda8a386dc3cdf88bde89468ddbd3bfc073;hpb=620beae94b362ae4d4c42e5ba3329a6211d67a8f;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/audio.h b/audio.h index b3640bd..448906b 100644 --- a/audio.h +++ b/audio.h @@ -9,11 +9,6 @@ #include "world.h" -VG_STATIC float audio_occlusion_current = 0.0f, - k_audio_occlusion_rate = 1.0f; - -VG_STATIC int k_audio_debug_soundscape = 0; - audio_clip audio_board[] = { { .path="sound/skate_hpf.ogg" }, @@ -35,6 +30,14 @@ audio_clip audio_taps[] = { .path="sound/tap3.ogg" } }; +audio_clip audio_flips[] = +{ + { .path="sound/lf0.ogg" }, + { .path="sound/lf1.ogg" }, + { .path="sound/lf2.ogg" }, + { .path="sound/lf3.ogg" }, +}; + audio_clip audio_hits[] = { { .path="sound/hit0.ogg" }, @@ -120,18 +123,6 @@ audio_clip audio_gate_ambient = { .path = "sound/gate_ambient.ogg" }; -#if 0 -audio_player ambient_player = -{ - .name = "Ambience" -}; - -audio_player audio_rewind_player = -{ - .name = "Rewind" -}; -#endif - audio_clip audio_rewind[] = { { .path = "sound/rewind_start.ogg" }, { .path = "sound/rewind_end_1.5.ogg" }, @@ -143,85 +134,75 @@ audio_clip audio_rewind[] = { audio_clip audio_ui[] = { { .path = "sound/ui_click.ogg" }, { .path = "sound/ui_ding.ogg" }, + { .path = "sound/teleport.ogg" } }; -audio_clip audio_music[] = { - { .path = "sound/song.ogg", .flags = k_audio_format_vorbis }, - { .path = "sound/skate.ogg", .flags = k_audio_format_vorbis }, +audio_clip audio_challenge[] = { + { .path = "sound/objective0.ogg" }, + { .path = "sound/objective1.ogg" }, + { .path = "sound/objective_win.ogg" }, + { .path = "sound/ui_good.ogg" }, + { .path = "sound/ui_inf.ogg" }, + { .path = "sound/ui_ok.ogg" }, + { .path = "sound/objective_fail.ogg" } }; -#if 0 -audio_player ambient_sprites[4] = -{ - { .name = "Ambient Sprites 0" }, - { .name = "Ambient Sprites 1" }, - { .name = "Ambient Sprites 2" }, - { .name = "Ambient Sprites 3" }, -}; +struct air_synth_data { + f32 speed; -audio_player audio_player0 = -{ - .name = "Player0", -}; + /* internal */ + f32 t; + struct dsp_biquad lpf; + SDL_SpinLock sl; +} +static air_data; -audio_player audio_player1 = -{ - .name = "Player1", -}; +static void audio_air_synth_get_samples( void *_data, f32 *buf, u32 count ){ + struct air_synth_data *data = _data; -audio_player audio_player2 = -{ - .name = "Player2", -}; + SDL_AtomicLock( &data->sl ); + f32 spd = data->speed; + SDL_AtomicUnlock( &data->sl ); -audio_player audio_player3 = -{ - .name = "Player3", -}; + f32 s0 = sinf(data->t*2.0f), + s1 = sinf(data->t*0.43f), + s2 = sinf(data->t*1.333f), + sm = vg_clampf( data->speed / 45.0f, 0, 1 ), + ft = (s0*s1*s2)*0.5f+0.5f, + f = vg_lerpf( 200.0f, 1200.0f, sm*0.7f + ft*0.3f ), + vol = 0.25f * sm; -audio_player audio_player4 = -{ - .name = "Player4", -}; + dsp_init_biquad_butterworth_lpf( &data->lpf, f ); -audio_player audio_player_extra = -{ - .name = "PlayerInst" + for( u32 i=0; ilpf, v ); + + buf[i*2+0] = v; + buf[i*2+1] = v; + } + + data->t += (f32)(count)/44100.0f; }; -audio_player audio_player_gate = -{ - .name = "Gate" +static audio_clip air_synth = { + .flags = k_audio_format_gen, + .size = 0, + .func = audio_air_synth_get_samples, + .data = &air_data }; -#endif -VG_STATIC void audio_init(void) +static void audio_init(void) { -#if 0 - audio_player_init( &audio_player0 ); - audio_player_init( &audio_player1 ); - audio_player_init( &audio_player2 ); - audio_player_init( &audio_player3 ); - audio_player_init( &audio_player4 ); - audio_player_init( &audio_player_gate ); - audio_player_init( &ambient_player ); - audio_player_init( &ambient_sprites[0] ); - audio_player_init( &ambient_sprites[1] ); - audio_player_init( &ambient_sprites[2] ); - audio_player_init( &ambient_sprites[3] ); - audio_player_init( &audio_player_extra ); - audio_player_init( &audio_rewind_player ); -#endif - 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_flips, vg_list_size(audio_flips), 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 ); - audio_clip_loadn( audio_music, vg_list_size(audio_music), NULL ); audio_clip_loadn( audio_jumps, vg_list_size(audio_jumps), NULL ); audio_clip_loadn( audio_lands, vg_list_size(audio_lands), NULL ); @@ -234,152 +215,25 @@ VG_STATIC void audio_init(void) 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 ); - -#if 0 - audio_lock(); - u32 flags = AUDIO_FLAG_LOOP|AUDIO_FLAG_SPACIAL_3D; - - 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_player4, flags ); - audio_player_set_flags( &audio_player_gate, flags ); - audio_player_set_flags( &audio_player3, AUDIO_FLAG_LOOP ); - audio_player_set_flags( &ambient_player, AUDIO_FLAG_LOOP ); - audio_player_set_flags( &ambient_sprites[0], AUDIO_FLAG_SPACIAL_3D ); - audio_player_set_flags( &ambient_sprites[1], AUDIO_FLAG_SPACIAL_3D ); - audio_player_set_flags( &ambient_sprites[2], AUDIO_FLAG_SPACIAL_3D ); - audio_player_set_flags( &ambient_sprites[3], AUDIO_FLAG_SPACIAL_3D ); - - audio_player_set_vol( &ambient_player, 1.0f ); - audio_player_set_vol( &audio_player_gate, 0.0f ); - audio_player_set_vol( &audio_player_extra, 1.0f ); - audio_player_set_vol( &audio_rewind_player, 0.2f ); - audio_player_set_flags( &audio_rewind_player, 0x00 ); - - 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_player_playclip( &audio_player4, &audio_board[4] ); - audio_player_playclip( &ambient_player, &audio_ambience[0] ); - audio_player_playclip( &audio_player_gate, &audio_gate_ambient ); - - audio_unlock(); -#endif - - vg_var_push( (struct vg_var){ - .name = "aud_debug_soundscape", - .data = &k_audio_debug_soundscape, - .data_type = k_var_dtype_i32, - .opt_i32 = { .min=0, .max=1, .clamp=0 }, - .persistent = 1 - }); - - vg_var_push( (struct vg_var){ - .name = "aud_occlusion_rate", - .data = &k_audio_occlusion_rate, - .data_type = k_var_dtype_f32, - .opt_f32 = { .clamp = 0 }, - .persistent = 1 - }); + audio_clip_loadn( audio_challenge, vg_list_size(audio_challenge), NULL ); audio_lock(); audio_set_lfo_wave( 0, k_lfo_polynomial_bipolar, 80.0f ); audio_set_lfo_frequency( 0, 20.0f ); - audio_unlock(); -} -VG_STATIC void audio_update(void) -{ -#if 0 - static u32 flapflop = 0x00; - static audio_channel *channel = NULL; - - u32 next = floorf( vg.time / 0.1f ); - - if( flapflop != next ) - { - flapflop = next; - - audio_lock(); - channel = audio_channel_crossfade( channel, - &audio_music[ next & 0x1 ], 0.05f, - AUDIO_FLAG_LOOP|AUDIO_FLAG_SPACIAL_3D - ); - channel = audio_channel_set_spacial( channel, - (v3f){ -22.3f, 60.1f, -52.7f }, - 50.0f ); - - audio_channel_sidechain_lfo( channel, 0, 1.0f ); - audio_unlock(); - } -#endif + skaterift.aud_air = audio_get_first_idle_channel(); + if( skaterift.aud_air ) + audio_channel_init( skaterift.aud_air, &air_synth, 0 ); + + audio_unlock(); } -VG_STATIC void audio_free(void) +static void audio_free(void) { /* TODO! */ vg_warn( "UNIMPLEMENTED: audio_free()\n" ); } -VG_STATIC void audio_sample_occlusion( v3f origin ) -{ - float d = 0.0f, - sample_dist = 880.0f; - - int sample_count = 8; - - int lv = 0; - v3f last; - v3_zero(last); - - world_instance *world = get_active_world(); - - for( int i=0; iinfo.surface_prop == k_surface_prop_grass){ - v3_copy( contact.pos, output ); - return k_audio_sprite_type_grass; - } - else{ -#if 0 - vg_line( pos, contact.pos, 0xff0000ff ); - vg_line_pt3( contact.pos, 0.3f, 0xff0000ff ); -#endif - return k_audio_sprite_type_none; - } + audio_lock(); + u16 group_id = 0xfff0; + audio_channel *ch = audio_get_group_idle_channel( group_id, 4 ); + + if( ch ){ + audio_channel_init( ch, clip, AUDIO_FLAG_SPACIAL_3D ); + audio_channel_group( ch, group_id ); + audio_channel_set_spacial( ch, co, 80.0f ); + audio_channel_edit_volume( ch, 1.0f, 1 ); + ch = audio_relinquish_channel( ch ); } - - output[0] = pos[0]; - output[1] = 0.0f; - output[2] = pos[2]; - - if( world->water.enabled ) - return k_audio_sprite_type_water; - else - return k_audio_sprite_type_none; + audio_unlock(); } -VG_STATIC void audio_debug_soundscapes(void) +static +enum audio_sprite_type world_audio_sample_sprite_random(v3f origin, v3f output); +static void audio_ambient_sprites_update( world_instance *world, v3f co ) { - if( !k_audio_debug_soundscape ) return; - - char buf[64]; - snprintf( buf, 31, "occlusion: %.5f", audio_occlusion_current ); + static float accum = 0.0f; + accum += vg.time_delta; - vg_uictx.cursor[0] = 450; - vg_uictx.cursor[1] = 10; - vg_uictx.cursor[2] = audio_occlusion_current * 200.0f; - vg_uictx.cursor[3] = 20; + if( accum > 0.1f ) + accum -= 0.1f; + else return; - ui_fill_rect( vg_uictx.cursor, 0x55cccccc ); - ui_text( vg_uictx.cursor, buf, 1, 0 ); + v3f sprite_pos; + enum audio_sprite_type sprite_type = + world_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[vg_randu32(&vg.rand)%4] ); + } + else if( sprite_type == k_audio_sprite_type_water ){ + if( world->water.enabled ){ + audio_ambient_sprite_play( sprite_pos, + &audio_water[vg_randu32(&vg.rand)%6] ); + } + } + } } #endif /* AUDIO_H */