From: hgn Date: Tue, 14 Mar 2023 08:08:58 +0000 (+0000) Subject: birds X-Git-Url: https://skaterift.com/git/?a=commitdiff_plain;h=3d52e114a0f608e58bc99cfc6faaeb41cfcf84c7;p=vg.git birds --- diff --git a/projects/birds b/projects/birds index 339fe0c..9c38f4e 100755 Binary files a/projects/birds and b/projects/birds differ diff --git a/projects/birds.c b/projects/birds.c index 09de9f0..a015fe6 100644 --- a/projects/birds.c +++ b/projects/birds.c @@ -115,13 +115,14 @@ struct synth_bird { int harmonic_4[4], fm_oscillator; + float poly; int x,a,l,v, frame; int pattern_length; struct synth_bird_signature { - float c0, c1, c2, c3, length, pause; + float c0, c1, c2, c3, length, pause, h0, h1, h2, h3; int lfo_hz; float fm; /* lfo modulation depth (+/- hz) */ @@ -168,12 +169,15 @@ static void birdsynth_pattern_decode( struct synth_bird *bird, sig->pause = 0.1f; sig->lfo_hz = 30; sig->fm = 10.0f; + sig->h0 = 1.0f; + sig->h1 = 0.5f; + sig->h2 = 0.2f; + sig->h3 = 0.125f; -#if 0 - sscanf( c, "{%f,%f,%f,%f,%f,%f,%d,%f}", + sscanf( c, "{%f,%f,%f,%f,%d,%f,%f,%f,%f,%f,%f,%f}", &sig->c0, &sig->c1, &sig->c2, &sig->c3, - &sig->length, &sig->pause, &sig->lfo_hz, &sig->fm ); -#endif + &sig->lfo_hz, &sig->fm, &sig->length, &sig->pause, + &sig->h0, &sig->h1, &sig->h2, &sig->h3 ); } c ++; @@ -214,7 +218,7 @@ static void synthbird_generate_samples( struct synth_bird *bird, bird->x ++; if( bird->x >= bird->l ) { - if( bird->a ) + if( bird->a && (bird->pattern[bird->frame].pause!=0.0f) ) { bird->a = 0; bird->l = bird->pattern[ bird->frame ].pause * 44100.0f; @@ -240,20 +244,12 @@ static void synthbird_generate_samples( struct synth_bird *bird, } else { - bird->v -= 40; + bird->v -= 100; if( bird->v < 0 ) bird->v = 0; } struct synth_bird_signature *sig = &bird->pattern[ bird->frame ]; - sig->c0 = 3000.0f; - sig->c1 = -800.0f; - sig->c2 = 1500.0f; - sig->c3 = -860.0f; - sig->length = 0.5f; - sig->pause = 0.1f; - sig->lfo_hz = 30; - sig->fm = 10.0f; float level = bird->v; level *= (1.0f/44100.0f); @@ -270,17 +266,17 @@ static void synthbird_generate_samples( struct synth_bird *bird, float fm = sine_44100_1( bird->fm_oscillator ) * sig->fm; int freq = bird->poly + fm; - bird->harmonic_4[0] = WRAP1S( bird->harmonic_4[0] + freq*1 ); - bird->harmonic_4[1] = WRAP1S( bird->harmonic_4[1] + freq*2 ); - bird->harmonic_4[2] = WRAP1S( bird->harmonic_4[2] + freq*3 ); - bird->harmonic_4[3] = WRAP1S( bird->harmonic_4[3] + freq*4 ); + bird->harmonic_4[0] = WRAP1S( bird->harmonic_4[0] + (freq*1) ); + bird->harmonic_4[1] = WRAP1S( bird->harmonic_4[1] + (freq*6)/5 ); + bird->harmonic_4[2] = WRAP1S( bird->harmonic_4[2] + (freq*8)/7 ); + bird->harmonic_4[3] = WRAP1S( bird->harmonic_4[3] + (freq*13)/12 ); float v[4]; sine_44100_4( bird->harmonic_4, v ); - float s = v[0] + - v[1] * 0.5f + - v[2] * 0.25f + - v[3] * 0.125f; + float s = v[0] * sig->h0 + + v[1] * sig->h1 + + v[2] * sig->h2 + + v[3] * sig->h3 ; s *= level; @@ -378,15 +374,67 @@ int main( int argc, char *argv[] ) } #else - struct synth_bird *bird = birdsynth_malloc_create( "" ); - - for(int _=0;_<44100*60;_++){ + struct synth_bird *warbling_vireo = birdsynth_malloc_create( + "{4000,100,100,0,60,200,0.134,0.1}," /* 1 */ + "{4200,-500,1700,0,60,96,0.1,0.05}," /* 2 */ + "{2400,-1200,1000,1700,60,96,0.1,0.0}," /* 3 */ + "{3100,200,-10,-1100,60,90,0.06,0.04}," /* 4 */ + "{4600,-2000,0,1300,60,10,0.13,0.07}," /* 5 */ + "{2700,-300,700,800,60,10,0.05,0.0}," /* 6 */ + "{3600,-300,0,0,60,20,0.09,0.07}," /* 7 */ + "{4800,1240,300,0,60,20,0.05,0.07}," /* 8 */ + "{2700,-800,150,1000,60,160,0.08,0.02}," /* 9 */ + "{2700,-800,150,1000,60,160,0.12,0.08}," /* 10 */ + "{6300,-100,-3200,1000,60,100,0.1,0.04}," /* 11 */ + "{4260,-200,300,1100,60,20,0.16,3.0}," /* 12 */ + ); + + struct synth_bird *pied_monarch = birdsynth_malloc_create( + "{2200,700,-300,0,60,0,0.18,0.13, 0.6,0.05,0,0}," + "{2200,700,-300,0,60,0,0.17,0.12, 0.8,0.05,0,0}," + "{2200,700,-300,0,60,0,0.16,0.11, 0.9,0.05,0,0}," + "{2200,700,-300,0,60,0,0.14,0.09, 1,0.05,0,0}," + "{2200,700,-300,0,60,0,0.12,0.07, 1,0.05,0,0}," + "{2200,700,-300,0,60,0,0.11,0.06, 1,0.05,0,0}," + "{2200,700,-300,0,60,0,0.10,0.05, 1,0.05,0,0}," + "{2200,700,-300,0,60,0,0.10,0.05, 1,0.05,0,0}," + "{2200,700,-300,0,60,0,0.10,0.05, 1,0.05,0,0}," + "{2200,700,-300,0,60,0,0.10,0.05, 1,0.05,0,0}," + "{2200,700,-300,0,60,0,0.10,0.05, 1,0.05,0,0}," + "{2200,700,-300,0,60,0,0.10,6.05, 1,0.05,0,0}," + ); + + struct synth_bird *bridled_honeyeater = birdsynth_malloc_create( + "{2000,-1000,600,0,30,60,0.1,0.1, 1.0,0.0,0.0,0.0}," + "{4000,0,-200,-200,30,60,0.1,0.1, 0.8,0.25,0.25,0.25}," + "{4000,0,-700,-800,60,20,0.06,0.01, 0.9,0.1,0,0}," + "{3950,0,-700,-800,60,20,0.07,0.01, 0.9,0.1,0,0}," + "{3900,0,-700,-800,60,20,0.08,0.01, 0.9,0.1,0,0}," + "{3850,0,-700,-800,60,20,0.09,0.01, 0.9,0.1,0,0}," + "{3800,0,-700,-800,60,20,0.10,0.02, 0.9,0.2,0.1,0}," + "{3750,0,-700,-800,60,20,0.11,0.05, 0.9,0.4,0.2,0}," + "{3700,0,-700,-800,60,20,0.12,0.2, 0.3,0.1,0,0}," + "{2600,1300,600,0,60,20,0.1,4.0, 0.97,0.03,0,0}," + ); + + for(;;){ float stereo[2] = { 0.0f, 0.0f }; - - synthbird_generate_samples( bird, stereo, 1 ); -#if 0 + + float b[2]; + synthbird_generate_samples( pied_monarch, b, 1 ); + stereo[0] += b[0] * 0.4f; + stereo[1] += b[1] * 0.3f; + + synthbird_generate_samples( warbling_vireo, b, 1 ); + stereo[0] += b[0] * 0.5f; + stereo[1] += b[1] * 0.4f; + + synthbird_generate_samples( bridled_honeyeater, b, 1 ); + stereo[0] += b[0] * 0.6f; + stereo[1] += b[1] * 0.6f; + + vg_dsp_process( stereo, stereo ); -#endif int16_t l = stereo[0] * 10000.0f, r = stereo[1] * 10000.0f; @@ -498,7 +546,9 @@ static inline void dsp_process_schroeder( struct dsp_schroeder *sch, } /* temporary global design */ -static struct dsp_lpf __lpf_mud_free; +static struct dsp_lpf __lpf_mud_free, + __hpf_mud_free; + static struct dsp_delay __echos[8]; static struct dsp_lpf __echos_lpf[8]; static struct dsp_schroeder __diffusion_chain[8]; @@ -514,11 +564,12 @@ static void vg_dsp_init( void ) dsp_init_lpf( &__lpf_mud_free, 125.0f ); + dsp_init_lpf( &__hpf_mud_free, 500.0f ); float sizes[] = { 2.0f, 4.0f, 8.0f, 16.0f, 32.0f, 64.0f, 128.0f, 256.0f }; - float reflection_variance = 0.1f; + float reflection_variance = 0.04f; for( int i=0; i<8; i++ ) { @@ -538,7 +589,7 @@ static void vg_dsp_init( void ) for( int i=0; i<8; i++ ) { - dsp_init_schroeder( __diffusion_chain+i, diffusions[i]/1000.0f, 0.8f ); + dsp_init_schroeder( __diffusion_chain+i, diffusions[i]/1000.0f, 0.7f ); } } @@ -557,7 +608,7 @@ static void vg_dsp_process( float *stereo_in, float *stereo_out ) dsp_write_lpf( __echos_lpf+i, &echo ); dsp_read_lpf( __echos_lpf+i, &echo ); - recieved += echo * echo_tunings[i]*0.997; + recieved += echo * echo_tunings[i]*0.9; } float diffused = recieved; @@ -567,7 +618,10 @@ static void vg_dsp_process( float *stereo_in, float *stereo_out ) dsp_process_schroeder( __diffusion_chain+i, &diffused, &diffused ); } - float total = in_total + (diffused*0.1f + recieved*0.9f); + float total = in_total + (diffused*0.5f + recieved*0.5f); + + dsp_write_lpf( &__hpf_mud_free, &total ); + dsp_read_lpf( &__hpf_mud_free, &total ); float low_mud; dsp_write_lpf( &__lpf_mud_free, &total ); @@ -578,9 +632,9 @@ static void vg_dsp_process( float *stereo_in, float *stereo_out ) for( int i=0; i<8; i++ ) dsp_write_delay( __echos+i, &total ); - stereo_out[0] = stereo_in[0]*0.25f; - stereo_out[1] = stereo_in[1]*0.25f; - stereo_out[0] += diffused*0.5f+recieved*0.9f; - stereo_out[1] += diffused*0.5f+recieved*0.9f; + stereo_out[0] = stereo_in[0]*0.1f; + stereo_out[1] = stereo_in[1]*0.1f; + stereo_out[0] += diffused*0.4f+recieved*0.9f; + stereo_out[1] += diffused*0.4f+recieved*0.9f; }