shithub: leaf

Download patch

ref: d7ef6d68c8b7531dfa7ec0a07ad9ad28e8c188bf
parent: cf2bb37de5abc56a3981784f89fe781146bf76f3
parent: 0a94befb8e1a04a9ebda2d1b1960d3c4ed50e1f0
author: mulshine <mulshine@princeton.edu>
date: Wed Dec 19 09:05:35 EST 2018

Resolved merge.

--- 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 @@
     NUM_TABLES
 } 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,15 @@
     
     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 gain envelope
+    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 +157,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 +187,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
@@ -427,7 +427,7 @@
         w = ((20480.0f - c->freq) * INV_10240);
         out = (c->table[T10240][idx] * w) + (c->table[T20480][idx] * (1.0f - w));
     }
-    else
+    else if (c->freq <= 24000.0f)
     {
         out = c->table[T20480][idx];
     }
@@ -557,7 +557,7 @@
         w = ((20480.0f - c->freq) * INV_10240);
         out = (c->table[T10240][idx] * w) + (c->table[T20480][idx] * (1.0f - w));
     }
-    else
+    else if (c->freq <= 24000.0f)
     {
         out = c->table[T20480][idx];
     }
@@ -622,8 +622,9 @@
     
     float out = 0.0f;
     float w = 0.0f;
+
     int idx = (int)(c->phase * c->tsize);
-    
+
     // Wavetable synthesis
     
     if (c->freq <= 20.0f)
@@ -680,7 +681,7 @@
         w = ((20480.0f - c->freq) * INV_10240);
         out = (c->table[T10240][idx] * w) + (c->table[T20480][idx] * (1.0f - w));
     }
-    else
+    else if (c->freq <= 24000.0f)
     {
         out = c->table[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 {
--- a/README.md
+++ b/README.md
@@ -3,12 +3,12 @@
 
 The library consists of a set of high-level audio synthesis components (Oscillators, Filters, Envelopes, Delays, Reverbs, and other Utilities).
 
-Our primary use case is embedded audio computing on 32-bit ARM microcontrollers that can run "bare-metal" (without an OS), such as the STM32f4 and STM32f7. The code, however, is general enough to be used in many other situations as well. We have included a JUCE VST/AU generating template to test the library (2), and the python script we use to generate wavetables. 
+Our primary use case is embedded audio computing on 32-bit ARM microcontrollers that can run "bare-metal" (without an OS), such as the STM32f4, STM32f7, and STM32H7. The code, however, is general enough to be used in many other situations as well. We have included a JUCE VST/AU generating template to test the library (2), and the python script we use to generate wavetables. 
 
 Most of these algorithms are sourced from other projects, especially the STK (Sound Toolkit) library and various discussions on the music-DSP mailing list. We also owe a lot to open source computer programming languages, such as C-sound, ChucK, PureData, and Supercollider. 
 
 Other interesting projects to check out that similarly target embedded applicatons are: TeensyAudio (C++), Hoxton Owl (C++), Axoloti (C), and Mutable Instruments (C++). 
 
-(1) Dynamic allocation is avoided to meet the needs of a larger number of embedded applications. Embedded developers often utilize architectures that don't fully support stdlib memory allocation functions like calloc, malloc, and free.
+(1) Use of standard malloc and calloc are avoided, and a custom memory pool implementation is included instead, allowing dynamic memory allocation/deallocation within a fixed block size.
 
 (2) The template features an easily reconfigurable UI and simple block and tick setup to test the library components. Of course, if you intend to use the provided JUCE plugin project, you need to get JUCE and the Projucer ( https://www.juce.com/get-juce ). Check out the first tutorial to get started - it's fun an easy! If you intend to include the LEAF framework in your own C++ project using JUCE or other platforms, you will probably need to rename each source file from .c to .cpp. This should be straightforward. Contact the developer if you have any troubles (mrmulshine@gmail.com).