shithub: leaf

Download patch

ref: 90488e6e75171c337eb6b0511f5b1efa24889fe8
parent: 3253e4223bb7576dc120953e7e223d840bbb3a4b
author: Jeff Snyder <jeff@snyderphonics.com>
date: Tue Dec 18 19:06:46 EST 2018

improved 808 sounds and solved bug in antialiased oscillators that would cause hard fault on H7

--- a/LEAF/Inc/leaf-math.h
+++ b/LEAF/Inc/leaf-math.h
@@ -70,7 +70,7 @@
 #define TWO_TO_31		2147483648.0f
 #define INV_TWO_TO_31	0.000000000465661f
 
-// Erbe shaper
+// Jones shaper
 float LEAF_shaper     (float input, float m_drive);
 float LEAF_reedTable  (float input, float offset, float slope);
 
--- a/LEAF/Inc/leaf-wavetables.h
+++ b/LEAF/Inc/leaf-wavetables.h
@@ -46,7 +46,7 @@
     TableNameNil
 } TableName;
 
-// mtof lookup table based on input range [0.0,1.0) in 4096 increments - midi frequency values scaled between m25 and m134 (as done in previous code)
+// mtof lookup table based on input range [0.0,1.0) in 4096 increments - midi frequency values scaled between m25 and m134 (from the Snyderphonics DrumBox code)
 
 extern const float exp_decay[EXP_DECAY_TABLE_SIZE];
 extern const float attack_decay_inc[ATTACK_DECAY_INC_TABLE_SIZE];
--- a/LEAF/Src/leaf-808.c
+++ b/LEAF/Src/leaf-808.c
@@ -121,7 +121,7 @@
 float t808Hihat_tick(t808Hihat* const hihat) {
     
     float sample = 0.0f;
-    float gainScale = 0.1666f;
+    float gainScale = 0.3f;
     
     for (int i = 0; i < 6; i++)
     {
@@ -130,16 +130,14 @@
     
     sample *= gainScale;
     
-    sample = (hihat->oscNoiseMix * sample) + ((1.0f-hihat->oscNoiseMix) * (0.8f * tNoise_tick(&hihat->n)));
+    sample = (hihat->oscNoiseMix * sample) + ((1.0f-hihat->oscNoiseMix) * (tNoise_tick(&hihat->n)));
     
     sample = tSVF_tick(&hihat->bandpassOsc, sample);
     
-    sample *= tEnvelope_tick(&hihat->envGain);
-    
-    sample = 0.85f * LEAF_clip(0.0f, tHighpass_tick(&hihat->highpass, sample), 1.0f);
-    
-    sample += 0.15f * tEnvelope_tick(&hihat->envStick) * tSVF_tick(&hihat->bandpassStick, tNoise_tick(&hihat->stick));
-    
+    float myGain = tEnvelope_tick(&hihat->envGain);
+    sample *= myGain*myGain;//square the output
+    sample = tHighpass_tick(&hihat->highpass, sample);
+    sample += ((0.5f * tEnvelope_tick(&hihat->envStick)) * tSVF_tick(&hihat->bandpassStick, tNoise_tick(&hihat->stick)));
     return sample;
 }
 
@@ -158,16 +156,23 @@
     tSVF_setFreq(&hihat->bandpassOsc,freq);
 }
 
+void t808Hihat_setStickBandPassFreq(t808Hihat* const hihat, float freq)
+{
+    tSVF_setFreq(&hihat->bandpassStick,freq);
+}
 
+
 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);
-    
+	//if (freq < 5600.0f) //to avoid aliasing (for some reason high frequency settings here cause hard faults)
+	{
+		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);
+	}
 }
 
 void t808Hihat_init(t808Hihat* const hihat)
@@ -181,11 +186,11 @@
     tNoise_init(&hihat->n, WhiteNoise);
     
     // need to fix SVF to be generic
-    tSVF_init(&hihat->bandpassStick, SVFTypeBandpass,2500.0,1.5f);
-    tSVF_init(&hihat->bandpassOsc, SVFTypeBandpass,3500,0.5f);
+    tSVF_init(&hihat->bandpassStick, SVFTypeBandpass,2500.0,1.2f);
+    tSVF_init(&hihat->bandpassOsc, SVFTypeBandpass,3500,0.3f);
     
-    tEnvelope_init(&hihat->envGain, 5.0f, 50.0f, OFALSE);
-    tEnvelope_init(&hihat->envStick, 5.0f, 15.0f, OFALSE);
+    tEnvelope_init(&hihat->envGain, 0.0f, 50.0f, OFALSE);
+    tEnvelope_init(&hihat->envStick, 0.0f, 4.0f, OFALSE);
     
     tHighpass_init(&hihat->highpass, 7000.0f);
     
--- a/LEAF/Src/leaf-oscillator.c
+++ b/LEAF/Src/leaf-oscillator.c
@@ -328,7 +328,7 @@
     float out = 0.0f;
     float w;
     
-    int idx = (int)(c->phase * TRI_TABLE_SIZE);
+    int idx = (int)(c->phase * SAW_TABLE_SIZE);
     
     // Wavetable synthesis
     
@@ -386,7 +386,7 @@
         w = ((20480.0f - c->freq) * INV_10240);
         out = (sawtooth[T10240][idx] * w) + (sawtooth[T20480][idx] * (1.0f - w));
     }
-    else
+    else if (c->freq <= 24000.0f)
     {
         out = sawtooth[T20480][idx];
     }
@@ -493,7 +493,7 @@
         w = ((20480.0f - c->freq) * INV_10240);
         out = (triangle[T10240][idx] * w) + (triangle[T20480][idx] * (1.0f - w));
     }
-    else
+    else if (c->freq <= 24000.0f)
     {
         out = triangle[T20480][idx];
     }
@@ -536,7 +536,7 @@
     
     float out = 0.0f;
     float w = 0.0f;
-    int idx = (int)(c->phase * TRI_TABLE_SIZE);
+    int idx = (int)(c->phase * SQR_TABLE_SIZE);
     
     // Wavetable synthesis
     
@@ -594,7 +594,7 @@
         w = ((20480.0f - c->freq) * INV_10240);
         out = (squarewave[T10240][idx] * w) + (squarewave[T20480][idx] * (1.0f - w));
     }
-    else
+    else if (c->freq <= 24000.0f)
     {
         out = squarewave[T20480][idx];
     }
--- a/LEAF/Src/leaf-utilities.c
+++ b/LEAF/Src/leaf-utilities.c
@@ -330,8 +330,8 @@
 {
     int32_t decayIndex;
     
-    if (decay < 0.0f) {
-        decayIndex = 0.0f;
+    if (decay <= 1.0f) {
+        decayIndex = 1;
     } else if (decay < 8192.0f) {
         decayIndex = ((int32_t)(decay * 8.0f)) - 1;
     } else {