wind rushing sound
authorhgn <hgodden00@gmail.com>
Sun, 10 Dec 2023 19:56:59 +0000 (19:56 +0000)
committerhgn <hgodden00@gmail.com>
Sun, 10 Dec 2023 19:56:59 +0000 (19:56 +0000)
audio.h
player.c
skaterift.h

diff --git a/audio.h b/audio.h
index 917b8ec8732ab6c6a8be7b374ec7f2112df8eac3..448906be07e9af05c101b3c07766578dc7612f4d 100644 (file)
--- a/audio.h
+++ b/audio.h
@@ -147,6 +147,51 @@ audio_clip audio_challenge[] = {
    { .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; i<count; i ++ ){
+      f32 v = (vg_randf64(&vg_dsp.rand) * 2.0f - 1.0f) * vol;
+      v = dsp_biquad_process( &data->lpf, 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
+};
+
 static void audio_init(void)
 {
    audio_clip_loadn( audio_board, vg_list_size(audio_board), NULL );
@@ -175,6 +220,11 @@ static void audio_init(void)
    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();
 }
 
index 2e4bb6fb02ca9c822479759513ceebb705fc2b4c..1d95c8b852e90ac00726d94df4dff9e0fa9586d7 100644 (file)
--- a/player.c
+++ b/player.c
@@ -117,6 +117,10 @@ static void player__update(void){
 static void player__post_update(void){
    if( player_subsystems[ localplayer.subsystem ]->post_update )
       player_subsystems[ localplayer.subsystem ]->post_update();
+
+   SDL_AtomicLock( &air_data.sl );
+   air_data.speed = v3_length( localplayer.rb.v );
+   SDL_AtomicUnlock( &air_data.sl );
 }
 
 /*
index b7fa44c78ec7561491f0c9171ca54fe2c0e99759..f96d17c61b470fae836be8a9cdb2bf592d58bd90 100644 (file)
@@ -66,6 +66,8 @@ struct{
 
    u32 achievements;
    int demo_mode;
+
+   audio_channel *aud_air;
 }
 static skaterift = { 
    .op = k_async_op_clientloading, .time_rate = 1.0f, .demo_mode = 1 };