shithub: leaf

Download patch

ref: ba8d069318626309a2f7175f5f0e2a68453c879e
parent: d958b11b5e9e34abdfdf29cf2c0b52f5e5ee1b1c
author: Jeff Snyder <jeff@snyderphonics.com>
date: Thu Dec 20 19:19:19 EST 2018

new hihat features, FM, harmonic stretch, if FM gets removed then pitch calculation wouldnt need to be happening inside tick, so if we get rid of it later we should move pitch calculation back into the set freq routine

--- a/LEAF/Inc/leaf-808.h
+++ b/LEAF/Inc/leaf-808.h
@@ -58,9 +58,13 @@
     tSVF bandpassStick;
     tEnvelope envGain;
     tEnvelope envStick;
+    tEnvelope noiseFMGain;
     tHighpass highpass;
     tNoise stick;
-    
+
+    float freq;
+    float stretch;
+    float FM_amount;
     float oscNoiseMix;
     
 } t808Hihat;
@@ -77,7 +81,8 @@
 void 		t808Hihat_setOscBandpassQ		(t808Hihat* const hihat, float Q);
 void        t808Hihat_setStickBandPassFreq  (t808Hihat* const, float freq);
 void        t808Hihat_setOscFreq         (t808Hihat* const, float freq);
-
+void 		t808Hihat_setStretch				(t808Hihat* const hihat, float stretch);
+void 		t808Hihat_setFM					(t808Hihat* const hihat, float FM_amount);
 
 // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
 
--- a/LEAF/Src/leaf-808.c
+++ b/LEAF/Src/leaf-808.c
@@ -108,6 +108,7 @@
 void t808Hihat_on(t808Hihat* const hihat, float vel) {
     
     tEnvelope_on(&hihat->envGain, vel);
+    tEnvelope_on(&hihat->noiseFMGain, vel);
     tEnvelope_on(&hihat->envStick, vel);
     
 }
@@ -123,6 +124,18 @@
     float sample = 0.0f;
     float gainScale = 0.3f;
     
+
+    float myNoise = tNoise_tick(&hihat->n);
+    //float FM_Noise = myNoise * tEnvelope_tick(&hihat->noiseFMGain);
+    float FM_Noise = myNoise;
+    //FM the hat with the noise
+	tSquare_setFreq(&hihat->p[0], (2.0f * hihat->freq + hihat->stretch) + (FM_Noise * hihat->FM_amount));
+	tSquare_setFreq(&hihat->p[1], (3.00f * hihat->freq + hihat->stretch) + (FM_Noise * hihat->FM_amount));
+	tSquare_setFreq(&hihat->p[2], (4.16f * hihat->freq + hihat->stretch) + (FM_Noise * hihat->FM_amount));
+	tSquare_setFreq(&hihat->p[3], (5.43f * hihat->freq + hihat->stretch) + (FM_Noise * hihat->FM_amount));
+	tSquare_setFreq(&hihat->p[4], (6.79f * hihat->freq + hihat->stretch) + (FM_Noise * hihat->FM_amount));
+	tSquare_setFreq(&hihat->p[5], (8.21f * hihat->freq + hihat->stretch) + (FM_Noise * hihat->FM_amount));
+
     for (int i = 0; i < 6; i++)
     {
         sample += tSquare_tick(&hihat->p[i]);
@@ -130,7 +143,7 @@
     
     sample *= gainScale;
     
-    sample = (hihat->oscNoiseMix * sample) + ((1.0f-hihat->oscNoiseMix) * (tNoise_tick(&hihat->n)));
+    sample = (hihat->oscNoiseMix * sample) + ((1.0f-hihat->oscNoiseMix) * myNoise);
     
     sample = tSVF_tick(&hihat->bandpassOsc, sample);
     
@@ -138,7 +151,7 @@
     sample *= (myGain*myGain);//square the output gain envelope
     sample = tHighpass_tick(&hihat->highpass, sample);
     sample += ((0.5f * tEnvelope_tick(&hihat->envStick)) * tSVF_tick(&hihat->bandpassStick, tNoise_tick(&hihat->stick)));
-
+    sample = tanhf(sample * 2.0f);
     return sample;
 }
 
@@ -145,6 +158,7 @@
 void t808Hihat_setDecay(t808Hihat* const hihat, float decay)
 {
     tEnvelope_setDecay(&hihat->envGain,decay);
+    tEnvelope_setDecay(&hihat->noiseFMGain,decay);
 }
 
 void t808Hihat_setHighpassFreq(t808Hihat* const hihat, float freq)
@@ -152,6 +166,16 @@
     tHighpass_setFreq(&hihat->highpass,freq);
 }
 
+void t808Hihat_setStretch(t808Hihat* const hihat, float stretch)
+{
+    hihat->stretch = stretch;
+}
+
+void t808Hihat_setFM(t808Hihat* const hihat, float FM_amount)
+{
+    hihat->FM_amount = FM_amount;
+}
+
 void t808Hihat_setOscBandpassFreq(t808Hihat* const hihat, float freq)
 {
     tSVF_setFreq(&hihat->bandpassOsc,freq);
@@ -170,12 +194,7 @@
 
 void t808Hihat_setOscFreq(t808Hihat* const hihat, float freq)
 {
-		tSquare_setFreq(&hihat->p[0], 2.0f * freq);
-		tSquare_setFreq(&hihat->p[1], 3.00f * freq);
-		tSquare_setFreq(&hihat->p[2], 4.16f * freq);
-		tSquare_setFreq(&hihat->p[3], 5.43f * freq);
-		tSquare_setFreq(&hihat->p[4], 6.79f * freq);
-		tSquare_setFreq(&hihat->p[5], 8.21f * freq);
+		hihat->freq = freq;
 }
 
 void t808Hihat_init(t808Hihat* const hihat)
@@ -193,18 +212,21 @@
     tSVF_init(&hihat->bandpassOsc, SVFTypeBandpass,3500,0.3f);
     
     tEnvelope_init(&hihat->envGain, 0.0f, 50.0f, OFALSE);
+    tEnvelope_init(&hihat->noiseFMGain, 0.0f, 500.0f, OFALSE);
     tEnvelope_init(&hihat->envStick, 0.0f, 4.0f, OFALSE);
     
     tHighpass_init(&hihat->highpass, 7000.0f);
     
-    float freq = 40.0f;
+    hihat->freq = 40.0f;
+    hihat->stretch = 0.0f;
+    hihat->FM_amount = 1000.0f;
     
-    tSquare_setFreq(&hihat->p[0], 2.0f * freq);
-    tSquare_setFreq(&hihat->p[1], 3.00f * freq);
-    tSquare_setFreq(&hihat->p[2], 4.16f * freq);
-    tSquare_setFreq(&hihat->p[3], 5.43f * freq);
-    tSquare_setFreq(&hihat->p[4], 6.79f * freq);
-    tSquare_setFreq(&hihat->p[5], 8.21f * freq);
+    tSquare_setFreq(&hihat->p[0], 2.0f * hihat->freq);
+    tSquare_setFreq(&hihat->p[1], 3.00f * hihat->freq);
+    tSquare_setFreq(&hihat->p[2], 4.16f * hihat->freq);
+    tSquare_setFreq(&hihat->p[3], 5.43f * hihat->freq);
+    tSquare_setFreq(&hihat->p[4], 6.79f * hihat->freq);
+    tSquare_setFreq(&hihat->p[5], 8.21f * hihat->freq);
 }
 
 void t808Snare_on(t808Snare* const snare, float vel)