X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=audio.h;h=448906be07e9af05c101b3c07766578dc7612f4d;hb=refs%2Fheads%2Frigidbody;hp=d1fd1cc6277196453fcb3c8fad653457f127dc85;hpb=f99902f513b0ad606437bf32de47405dd4ea5f98;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/audio.h b/audio.h index d1fd1cc..448906b 100644 --- a/audio.h +++ b/audio.h @@ -30,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" }, @@ -126,12 +134,69 @@ 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_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" } +}; + +struct air_synth_data { + f32 speed; + + /* internal */ + f32 t; + struct dsp_biquad lpf; + SDL_SpinLock sl; +} +static air_data; + +static void audio_air_synth_get_samples( void *_data, f32 *buf, u32 count ){ + struct air_synth_data *data = _data; + + SDL_AtomicLock( &data->sl ); + f32 spd = data->speed; + SDL_AtomicUnlock( &data->sl ); + + 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; + + dsp_init_biquad_butterworth_lpf( &data->lpf, f ); + + for( u32 i=0; ilpf, v ); + + buf[i*2+0] = v; + buf[i*2+1] = v; + } + + data->t += (f32)(count)/44100.0f; +}; + +static audio_clip air_synth = { + .flags = k_audio_format_gen, + .size = 0, + .func = audio_air_synth_get_samples, + .data = &air_data }; -VG_STATIC void audio_init(void) +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_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 ); @@ -150,14 +215,20 @@ 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 ); + 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 ); + + 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" ); @@ -170,61 +241,15 @@ enum audio_sprite_type k_audio_sprite_type_water }; -/* - * 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 ); - - ray_hit contact; - contact.dist = vg_minf( 16.0f, pos[1] ); - - world_instance *world = get_active_world(); - - if( ray_world( world, pos, (v3f){0.0f,-1.0f,0.0f}, &contact ) ){ - struct world_surface *mat = ray_hit_surface( world, &contact ); - - if( mat->info.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; - } - } - - 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; -} - -VG_STATIC void audio_ambient_sprite_play( v3f co, audio_clip *clip ) +static void audio_ambient_sprite_play( v3f co, audio_clip *clip ) { audio_lock(); - u32 channel_id = 31342352; - audio_channel *ch = audio_get_group_idle_channel( channel_id, 4 ); + 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, channel_id ); + 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 ); @@ -232,10 +257,12 @@ VG_STATIC void audio_ambient_sprite_play( v3f co, audio_clip *clip ) audio_unlock(); } -VG_STATIC void audio_ambient_sprites_update( world_instance *world, v3f co ) +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 ) { static float accum = 0.0f; - accum += vg.frame_delta; + accum += vg.time_delta; if( accum > 0.1f ) accum -= 0.1f; @@ -243,15 +270,18 @@ VG_STATIC void audio_ambient_sprites_update( world_instance *world, v3f co ) v3f sprite_pos; enum audio_sprite_type sprite_type = - audio_sample_sprite_random( co, sprite_pos ); + 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[rand()%4] ); + 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[rand()%6] ); + if( world->water.enabled ){ + audio_ambient_sprite_play( sprite_pos, + &audio_water[vg_randu32(&vg.rand)%6] ); + } } } }