shithub: leaf

Download patch

ref: c84e0daafc6d83b0b44a2575bcafe27cf85f1109
parent: 738fd333b9a5a40175a6e6a8b3488cd6aeee7789
author: mulshine <mulshine@princeton.edu>
date: Wed Jan 23 13:53:55 EST 2019

Made tSample and tSamplePlayer classes. Loop sampler (a la groove~) close to working. Needs crossfade.

--- a/LEAF/Inc/leaf-808.h
+++ b/LEAF/Inc/leaf-808.h
@@ -1,19 +1,20 @@
-/*
-  ==============================================================================
+/*==============================================================================
 
     leaf_808.h
     Created: 30 Nov 2018 10:24:44am
     Author:  airship
 
-  ==============================================================================
-*/
-
-// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
+==============================================================================*/
 
+#ifndef LEAF_808_H_INCLUDED
+#define LEAF_808_H_INCLUDED
+
 #ifdef __cplusplus
 extern "C" {
-#endif
-
+#endif
+
+//==============================================================================
+    
 #include "leaf-globals.h"
 #include "leaf-math.h"
 
@@ -21,10 +22,8 @@
 #include "leaf-utilities.h"
 #include "leaf-filter.h"
 
-
-
-// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
-
+//==============================================================================
+    
 // 808 Cowbell
 typedef struct _t808Cowbell {
     
@@ -51,9 +50,8 @@
 void    t808Cowbell_setFreq          (t808Cowbell* const, float freq);
 void    t808Cowbell_setOscMix        (t808Cowbell* const, float oscMix);
 
-
-// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
-
+//==============================================================================
+    
 // 808 Hihat
 typedef struct _t808Hihat {
     
@@ -90,9 +88,9 @@
 void        t808Hihat_setOscFreq         (t808Hihat* const, float freq);
 void 		t808Hihat_setStretch				(t808Hihat* const hihat, float stretch);
 void 		t808Hihat_setFM					(t808Hihat* const hihat, float FM_amount);
-
-// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
-
+
+//==============================================================================
+    
 // 808 Snare
 typedef struct _t808Snare {
     
@@ -133,8 +131,8 @@
 void        t808Snare_setNoiseFilterFreq    (t808Snare* const, float noiseFilterFreq);
 void        t808Snare_setNoiseFilterQ       (t808Snare* const, float noiseFilterQ);
 
-// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
-
+//==============================================================================
+    
 // 808 Kick
 typedef struct _t808Kick {
 
@@ -173,9 +171,14 @@
 void        t808Kick_setNoiseFilterFreq    (t808Kick* const, float noiseFilterFreq);
 void        t808Kick_setNoiseFilterQ       (t808Kick* const, float noiseFilterQ);
     
+//==============================================================================
+    
 #ifdef __cplusplus
 }
-#endif
+#endif
+
+#endif // LEAF_808_H_INCLUDED
+
+//==============================================================================
 
-// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
 
--- a/LEAF/Inc/leaf-delay.h
+++ b/LEAF/Inc/leaf-delay.h
@@ -1,27 +1,25 @@
-/*
-  ==============================================================================
+/*==============================================================================
 
     LEAFDelay.h
     Created: 20 Jan 2017 12:01:24pm
     Author:  Michael R Mulshine
 
-  ==============================================================================
-*/
+==============================================================================*/
 
-#ifndef LEAFDELAY_H_INCLUDED
-#define LEAFDELAY_H_INCLUDED
+#ifndef LEAF_DELAY_H_INCLUDED
+#define LEAF_DELAY_H_INCLUDED
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
-
+//==============================================================================
+    
 #include "leaf-globals.h"
 #include "leaf-math.h"
 
-// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
-
+//==============================================================================
+    
 /* Non-interpolating delay, reimplemented from STK (Cook and Scavone). */
 typedef struct _tDelay
 {
@@ -48,9 +46,8 @@
 float       tDelay_getLastOut   (tDelay*  const);
 float       tDelay_getLastIn    (tDelay*  const);
 
-
-// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
-
+//==============================================================================
+    
 /* Linearly-interpolating delay, reimplemented from STK (Cook and Scavone). */
 typedef struct _tDelayL
 {
@@ -81,8 +78,8 @@
 float       tDelayL_getLastOut  (tDelayL*  const);
 float       tDelayL_getLastIn   (tDelayL*  const);
 
-// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
-
+//==============================================================================
+    
 /* Allpass-interpolating delay, reimplemented from STK (Cook and Scavone). */
 typedef struct _tDelayA
 {
@@ -115,8 +112,8 @@
 float       tDelayA_getLastOut  (tDelayA*  const);
 float       tDelayA_getLastIn   (tDelayA*  const);
 
-// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
-
+//==============================================================================
+    
 /* Linear interpolating delay with fixed read and write pointers, variable rate. */
 typedef struct _tTapeDelay
 {
@@ -147,8 +144,12 @@
 float       tTapeDelay_getLastOut  (tTapeDelay*  const);
 float       tTapeDelay_getLastIn   (tTapeDelay*  const);
     
+//==============================================================================
+    
 #ifdef __cplusplus
 }
 #endif
 
-#endif  // LEAFDELAY_H_INCLUDED
+#endif  // LEAF_DELAY_H_INCLUDED
+
+//==============================================================================
--- a/LEAF/Inc/leaf-filter.h
+++ b/LEAF/Inc/leaf-filter.h
@@ -1,22 +1,20 @@
-/*
-  ==============================================================================
+/*==============================================================================
 
     LEAFFilter.h
     Created: 20 Jan 2017 12:01:10pm
     Author:  Michael R Mulshine
 
-  ==============================================================================
-*/
+==============================================================================*/
 
-#ifndef LEAFFILTER_H_INCLUDED
-#define LEAFFILTER_H_INCLUDED
+#ifndef LEAF_FILTER_H_INCLUDED
+#define LEAF_FILTER_H_INCLUDED
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
-
+//==============================================================================
+    
 #include "leaf-globals.h"
 #include "leaf-math.h"
 
@@ -24,8 +22,8 @@
 
 #include "leaf-wavetables.h"
 
-// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
-
+//==============================================================================
+    
 /* tAllpass: Schroeder allpass. Comb-filter with feedforward and feedback. */
 typedef struct _tAllpass
 {
@@ -45,8 +43,8 @@
 void        tAllpass_setDelay       (tAllpass* const f, float delay);
 
 
-// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
-
+//==============================================================================
+    
 /* tOnePole: OnePole filter, reimplemented from STK (Cook and Scavone). */
 typedef struct _tOnePole
 {
@@ -73,9 +71,8 @@
 void        tOnePole_setCoefficients(tOnePole* const, float b0, float a1);
 void        tOnePole_setGain        (tOnePole* const, float gain);
 
-
-// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
-
+//==============================================================================
+    
 /* TwoPole filter, reimplemented from STK (Cook and Scavone). */
 typedef struct _tTwoPole
 {
@@ -100,10 +97,9 @@
 void        tTwoPole_setResonance   (tTwoPole*  const, float freq, float radius, oBool normalize);
 void        tTwoPole_setCoefficients(tTwoPole*  const, float b0, float a1, float a2);
 void        tTwoPole_setGain        (tTwoPole*  const, float gain);
-
 
-// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
-
+//==============================================================================
+    
 /* OneZero filter, reimplemented from STK (Cook and Scavone). */
 typedef struct _tOneZero
 {
@@ -123,9 +119,8 @@
 void        tOneZero_setGain        (tOneZero*  const, float gain);
 float       tOneZero_getPhaseDelay(tOneZero *f, float frequency );
 
-
-// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
-
+//==============================================================================
+    
 /* TwoZero filter, reimplemented from STK (Cook and Scavone). */
 typedef struct _tTwoZero
 {
@@ -149,9 +144,8 @@
 void        tTwoZero_setCoefficients(tTwoZero*  const, float b0, float b1, float b2);
 void        tTwoZero_setGain        (tTwoZero*  const, float gain);
 
-
-// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
-
+//==============================================================================
+    
 /* PoleZero filter, reimplemented from STK (Cook and Scavone). */
 typedef struct _tPoleZero
 {
@@ -175,9 +169,8 @@
 void        tPoleZero_setBlockZero      (tPoleZero*  const, float thePole);
 void        tPoleZero_setGain           (tPoleZero*  const, float gain);
 
-
-// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
-
+//==============================================================================
+    
 /* BiQuad filter, reimplemented from STK (Cook and Scavone). */
 typedef struct _tBiQuad
 {
@@ -206,9 +199,8 @@
 void        tBiQuad_setCoefficients(tBiQuad*  const, float b0, float b1, float b2, float a1, float a2);
 void        tBiQuad_setGain        (tBiQuad*  const, float gain);
 
-
-// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
-
+//==============================================================================
+    
 /* State Variable Filter, algorithm from Andy Simper. */
 typedef enum SVFType
 {
@@ -235,9 +227,8 @@
 int         tSVF_setFreq    (tSVF*  const, float freq);
 int         tSVF_setQ       (tSVF*  const, float Q);
 
-
-// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
-
+//==============================================================================
+    
 /* Efficient State Variable Filter for 14-bit control input, [0, 4096). */
 typedef struct _tSVFE
 {
@@ -255,9 +246,8 @@
 int         tSVFE_setFreq   (tSVFE*  const, uint16_t controlFreq);
 int         tSVFE_setQ      (tSVFE*  const, float Q);
 
-
-// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
-
+//==============================================================================
+    
 /* Simple Highpass filter. */
 typedef struct _tHighpass
 {
@@ -273,9 +263,8 @@
 void        tHighpass_setFreq   (tHighpass*  const, float freq);
 float       tHighpass_getFreq   (tHighpass*  const);
 
-
-// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
-
+//==============================================================================
+    
 // Butterworth Filter
 #define NUM_SVF_BW 16
 typedef struct _tButterworth
@@ -299,10 +288,12 @@
 void        tButterworth_setF2      (tButterworth* const, float in);
 void        tButterworth_setFreqs   (tButterworth* const, float f1, float f2);
 
-// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
+//==============================================================================
     
 #ifdef __cplusplus
 }
 #endif
 
-#endif  // LEAFFILTER_H_INCLUDED
+#endif  // LEAF_FILTER_H_INCLUDED
+
+//==============================================================================
--- a/LEAF/Inc/leaf-formant.h
+++ b/LEAF/Inc/leaf-formant.h
@@ -1,24 +1,25 @@
-/*
-  ==============================================================================
+/*==============================================================================
 
     leaf-formant.h
     Created: 30 Nov 2018 11:03:37am
     Author:  airship
 
-  ==============================================================================
-*/
+==============================================================================*/
 
+#ifndef LEAF_FORMANT_H_INCLUDED
+#define LEAF_FORMANT_H_INCLUDED
+
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
-
+//==============================================================================
+    
 #include "leaf-globals.h"
 #include "leaf-math.h"
 
-// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
-
+//==============================================================================
+    
 #define FORD 7
 #define FORMANT_BUFFER_SIZE 2048
 
@@ -51,11 +52,15 @@
 float       tFormantShifter_tick            (tFormantShifter* const, float input, float fwarp);
 float       tFormantShifter_remove          (tFormantShifter* const, float input);
 float       tFormantShifter_add             (tFormantShifter* const, float input, float fwarp);
-void        tFormantShifter_ioSamples       (tFormantShifter* const, float* in, float* out, int size, float fwarp);
-
-// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
+void        tFormantShifter_ioSamples       (tFormantShifter* const, float* in, float* out, int size, float fwarp);
+    
+//==============================================================================
     
 #ifdef __cplusplus
 }
-#endif
+#endif
+
+#endif // LEAF_FORMANT_H_INCLUDED
+
+//==============================================================================
 
--- a/LEAF/Inc/leaf-globals.h
+++ b/LEAF/Inc/leaf-globals.h
@@ -1,29 +1,23 @@
-/*
-  ==============================================================================
+/*==============================================================================
 
     leaf-globals.h
     Created: 23 Jan 2017 10:34:10pm
     Author:  Michael R Mulshine
 
-  ==============================================================================
-*/
+==============================================================================*/
 
-#ifndef OPPSGLOBALS_H_INCLUDED
-#define OPPSGLOBALS_H_INCLUDED
-
-/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- *                                                                                                       *
- * If your application requires use of many instances of one component or is facing memory limitations,  *
- * use this set of defines to increase or limit the number of instances of each component. The library   *
- * will pre-allocate only the number of instances defined here.                                          *
- *                                                                                                       *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
-#include "leaf-mempool.h"
+#ifndef LEAF_GLOBALS_H_INCLUDED
+#define LEAF_GLOBALS_H_INCLUDED
 
 #ifdef __cplusplus
 extern "C" {
 #endif
+    
+//==============================================================================
+
+#include "leaf-mempool.h"
+    
+//==============================================================================
     
 typedef struct _LEAF
 {
@@ -30,11 +24,22 @@
     float   sampleRate;
     float   invSampleRate;
     int     blockSize;
-    
+    
+    /*
+    float*  sinewave;
+    float*  sawtooth[11];
+    float*  square[11];
+    float*  triangle[11];
+     */
+
     float   (*random)(void);
-} LEAF;
+} LEAF;
+    
+//==============================================================================
 
-extern LEAF leaf;
+extern LEAF leaf; // The global instance of LEAF.
+    
+//==============================================================================
 
 #define SHAPER1_TABLE_SIZE 65536
 extern const float shaper1[SHAPER1_TABLE_SIZE];
@@ -54,8 +59,13 @@
 
 #define TALKBOX_BUFFER_LENGTH   1600    // Every talkbox instance introduces 5 buffers of this size
 
+    
+//==============================================================================
+    
 #ifdef __cplusplus
 }
 #endif
     
-#endif  // OPPSGLOBALS_H_INCLUDED
+#endif  // LEAF_GLOBALS_H_INCLUDED
+
+//==============================================================================
--- a/LEAF/Inc/leaf-math.h
+++ b/LEAF/Inc/leaf-math.h
@@ -1,23 +1,23 @@
-/*
-  ==============================================================================
+/*==============================================================================
 
     LEAFMath.h
     Created: 22 Jan 2017 7:02:56pm
     Author:  Michael R Mulshine
 
-  ==============================================================================
-*/
+==============================================================================*/
 
-#ifndef LEAFMATH_H_INCLUDED
-#define LEAFMATH_H_INCLUDED
+#ifndef LEAF_MATH_H_INCLUDED
+#define LEAF_MATH_H_INCLUDED
+
+#ifdef __cplusplus
+extern "C" {
+#endif
 
 #include "math.h"
 #include "stdint.h"
 #include "stdlib.h"
 
-#ifdef __cplusplus
-extern "C" {
-#endif
+//==============================================================================
 
 typedef enum oBool
 {
@@ -78,8 +78,9 @@
 float LEAF_shaper     (float input, float m_drive);
 float LEAF_reedTable  (float input, float offset, float slope);
 
-float       LEAF_clip               (float min, float val, float max);
-float   	LEAF_softClip						(float val, float thresh);
+float       LEAF_clip               (float min, float val, float max);
+int         LEAF_clipInt            (int min, int val, int max);
+float   	LEAF_softClip		    (float val, float thresh);
 oBool       LEAF_isPrime            (uint64_t number );
 
 float       LEAF_midiToFrequency    (float f);
@@ -110,9 +111,12 @@
 // REQUIRES: 32 bit floats
 float fastabs(float f);
 
+//==============================================================================
     
 #ifdef __cplusplus
 }
 #endif
 
-#endif  // LEAFMATH_H_INCLUDED
+#endif  // LEAF_MATH_H_INCLUDED
+
+//==============================================================================
--- a/LEAF/Inc/leaf-mempool.h
+++ b/LEAF/Inc/leaf-mempool.h
@@ -1,4 +1,5 @@
-/**
+/*==============================================================================
+ 
    In short, mpool is distributed under so called "BSD license",
    
    Copyright (c) 2009-2010 Tatsuhiko Kubo <cubicdaiya@gmail.com>
@@ -28,25 +29,29 @@
    PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
    LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
    NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
+   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ 
+   written by C99 style
+==============================================================================*/
 
-/* written by C99 style */
+#ifndef LEAF_MPOOL_H_INCLUDED
+#define LEAF_MPOOL_H_INCLUDED
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+    
+//==============================================================================
 
-#ifndef MPOOL_H
-#define MPOOL_H
-
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <stdbool.h>
+#include <stdbool.h>
+    
+//==============================================================================
 
-#define MPOOL_POOL_SIZE   500000
+#define MPOOL_POOL_SIZE   1000000
 #define MPOOL_ALIGN_SIZE (8)
-
-#ifdef __cplusplus
-extern "C" {
-#endif
 
 //#define size_t unsigned long
       
@@ -68,7 +73,6 @@
     int next;
 } mpool_t;
 
-
 void mpool_create (size_t size, mpool_t* pool);
 
 void *mpool_alloc(size_t size, mpool_t* pool);
@@ -86,12 +90,16 @@
 size_t leaf_pool_get_size(void);
 size_t leaf_pool_get_used(void);
 
-void* leaf_pool_get_pool(void);
+void* leaf_pool_get_pool(void);
+    
+//==============================================================================
 
 #ifdef __cplusplus
 }
 #endif
 
-#endif
+#endif // LEAF_MPOOL_H
+
+//==============================================================================
 
 
--- a/LEAF/Inc/leaf-midi.h
+++ b/LEAF/Inc/leaf-midi.h
@@ -1,26 +1,27 @@
-/*
-  ==============================================================================
+/*==============================================================================
 
     leaf-midi.h
     Created: 30 Nov 2018 11:29:26am
     Author:  airship
 
-  ==============================================================================
-*/
+==============================================================================*/
+
+#ifndef LEAF_MIDI_H_INCLUDED
+#define LEAF_MIDI_H_INCLUDED
 
 #ifdef __cplusplus
 extern "C" {
 #endif
     
-// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
-
+//==============================================================================
+    
 #include "leaf-globals.h"
 #include "leaf-math.h"
 
 #include "leaf-utilities.h"
 
-// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
-
+//==============================================================================
+    
 typedef struct _tMidiNote
 {
     uint8_t pitch;
@@ -38,8 +39,8 @@
     
 } tMidiNode;
 
-// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
-
+//==============================================================================
+    
 /* Polyphonic Handler */
 typedef struct _tPoly
 {
@@ -56,8 +57,8 @@
 void        tPoly_noteOn(tPoly* poly, int midiNoteNumber, float velocity);
 void        tPoly_noteOff(tPoly* poly, int midiNoteNumber);
 
-// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
-
+//==============================================================================
+    
 /* tMPoly */
 typedef struct _tMPoly
 {
@@ -110,9 +111,13 @@
 int     tMPoly_getVelocity(tMPoly* const, uint8_t voice);
 int     tMPoly_isOn(tMPoly* const, uint8_t voice);
 
-// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
+//==============================================================================
     
 #ifdef __cplusplus
 }
-#endif
+#endif
+
+#endif // LEAF_MIDI_H_INCLUDED
+
+//==============================================================================
 
--- a/LEAF/Inc/leaf-oscillator.h
+++ b/LEAF/Inc/leaf-oscillator.h
@@ -1,21 +1,19 @@
-/*
-  ==============================================================================
+/*==============================================================================
 
     LEAFOscillator.h
     Created: 20 Jan 2017 12:00:58pm
     Author:  Michael R Mulshine
 
-  ==============================================================================
-*/
+==============================================================================*/
 
-#ifndef LEAFOSCILLATOR_H_INCLUDED
-#define LEAFOSCILLATOR_H_INCLUDED
+#ifndef LEAF_OSCILLATOR_H_INCLUDED
+#define LEAF_OSCILLATOR_H_INCLUDED
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
+//==============================================================================
 
 #include "leaf-globals.h"
 #include "leaf-math.h"
@@ -22,7 +20,7 @@
 
 #include "leaf-filter.h"
 
-// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
+//==============================================================================
 
 /* tNeuron */
 typedef enum NeuronMode
@@ -66,7 +64,7 @@
 void        tNeuron_setV3       (tNeuron* const, float V3);
 void        tNeuron_setTimeStep (tNeuron* const, float timestep);
 
-// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
+//==============================================================================
 
 /* tPhasor: Aliasing phasor [0.0, 1.0) */
 typedef struct _tPhasor
@@ -82,7 +80,7 @@
 float       tPhasor_tick        (tPhasor*  const);
 int         tPhasor_setFreq     (tPhasor*  const, float freq);
 
-// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
+//==============================================================================
 
 /* tCycle: Cycle/Sine waveform. Wavetable synthesis.*/
 typedef struct _tCycle
@@ -99,7 +97,7 @@
 float       tCycle_tick         (tCycle*  const);
 int         tCycle_setFreq      (tCycle*  const, float freq);
 
-// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
+//==============================================================================
 
 /* tSawtooth: Anti-aliased Sawtooth waveform using wavetable interpolation. Wavetables constructed from sine components. */
 typedef struct _tSawtooth
@@ -116,7 +114,7 @@
 float       tSawtooth_tick      (tSawtooth*  const);
 int         tSawtooth_setFreq   (tSawtooth*  const, float freq);
 
-// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
+//==============================================================================
 
 /* tTriangle: Anti-aliased Triangle waveform using wavetable interpolation. Wavetables constructed from sine components. */
 typedef struct _tTriangle
@@ -133,7 +131,7 @@
 float       tTriangle_tick      (tTriangle*  const);
 int         tTriangle_setFreq   (tTriangle*  const, float freq);
 
-// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
+//==============================================================================
 
 /* tSquare: Anti-aliased Square waveform using wavetable interpolation. Wavetables constructed from sine components. */
 typedef struct _tSquare
@@ -150,7 +148,7 @@
 float       tSquare_tick        (tSquare*  const);
 int         tSquare_setFreq     (tSquare*  const, float freq);
 
-// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
+//==============================================================================
 
 /* tNoise. WhiteNoise, PinkNoise. */
 typedef enum NoiseType
@@ -173,10 +171,12 @@
 
 float       tNoise_tick          (tNoise*  const);
 
-// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
+//==============================================================================
     
 #ifdef __cplusplus
 }
 #endif
         
-#endif  // LEAFOSCILLATOR_H_INCLUDED
+#endif  // LEAF_OSCILLATOR_H_INCLUDED
+
+//==============================================================================
--- a/LEAF/Inc/leaf-pitch.h
+++ b/LEAF/Inc/leaf-pitch.h
@@ -8,11 +8,14 @@
   ==============================================================================
 */
 
+#ifndef LEAF_PITCH_H_INCLUDED
+#define LEAF_PITCH_H_INCLUDED
+
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
+//==============================================================================
 
 #include "leaf-globals.h"
 #include "leaf-math.h"
@@ -20,8 +23,8 @@
 #include "leaf-filter.h"
 #include "leaf-utilities.h"
 
-// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
-
+//==============================================================================
+    
 #define DEFPITCHRATIO 2.0f
 #define DEFTIMECONSTANT 100.0f
 #define DEFHOPSIZE 64
@@ -29,8 +32,8 @@
 #define FBA 20
 #define HPFREQ 40.0f
 
-// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
-
+//==============================================================================
+    
 /* tSOLAD : pitch shifting algorithm that underlies tPitchShifter etc */
 #define LOOPSIZE (2048*2)      // (4096*2) // loop size must be power of two
 #define LOOPMASK (LOOPSIZE - 1)
@@ -72,8 +75,8 @@
 // reset state variables
 void    tSOLAD_resetState       (tSOLAD *w);
 
-// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
-
+//==============================================================================
+    
 // tSNAC: period detector
 #define SNAC_FRAME_SIZE 1024           // default analysis framesize // should be the same as (or smaller than?) PS_FRAME_SIZE
 #define DEFOVERLAP 1                // default overlap
@@ -112,8 +115,8 @@
 float   tSNAC_getPeriod     (tSNAC *s);
 float   tSNAC_getfidelity   (tSNAC *s);
 
-// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
-
+//==============================================================================
+    
 // Pitch shifter 
 typedef struct _tPitchShifter
 {
@@ -159,8 +162,8 @@
 void        tPitchShifter_setWindowSize     (tPitchShifter* const, int ws);
 float       tPitchShifter_getPeriod         (tPitchShifter* const);
 
-// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
-
+//==============================================================================
+    
 // Period detection
 typedef struct _tPeriod
 {
@@ -198,8 +201,8 @@
 void        tPeriod_setHopSize              (tPeriod* p, int hs);
 void        tPeriod_setWindowSize           (tPeriod* p, int ws);
 
-// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
-
+//==============================================================================
+    
 // Pitch shift
 typedef struct _tPitchShift
 {
@@ -229,8 +232,12 @@
 float       tPitchShift_shiftToFreq         (tPitchShift* const, float freq);
 void        tPitchShift_setPitchFactor      (tPitchShift* const, float pf);
 
-// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
+//==============================================================================
     
 #ifdef __cplusplus
 }
-#endif
+#endif
+
+#endif // LEAF_PITCH_H_INCLUDED
+
+//==============================================================================
--- a/LEAF/Inc/leaf-reverb.h
+++ b/LEAF/Inc/leaf-reverb.h
@@ -1,22 +1,20 @@
-/*
-  ==============================================================================
+/*==============================================================================
 
     LEAFReverb.h
     Created: 20 Jan 2017 12:02:04pm
     Author:  Michael R Mulshine
 
-  ==============================================================================
-*/
+==============================================================================*/
 
-#ifndef LEAFREVERB_H_INCLUDED
-#define LEAFREVERB_H_INCLUDED
+#ifndef LEAF_REVERB_H_INCLUDED
+#define LEAF_REVERB_H_INCLUDED
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
-
+//==============================================================================
+    
 #include "leaf-globals.h"
 #include "leaf-math.h"
 
@@ -24,7 +22,7 @@
 #include "leaf-filter.h"
 #include "leaf-oscillator.h"
 
-// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
+//==============================================================================
 
 /* PRCRev: Reverb, reimplemented from STK (Cook and Scavone). */
 typedef struct _tPRCRev
@@ -53,7 +51,7 @@
 // Set mix between dry input and wet output signal.
 void    tPRCRev_setMix  (tPRCRev* const, float mix);
 
-// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
+//==============================================================================
 
 /* NRev: Reverb, reimplemented from STK (Cook and Scavone). */
 typedef struct _tNRev
@@ -83,7 +81,7 @@
 // Set mix between dry input and wet output signal.
 void    tNRev_setMix    (tNRev*  const, float mix);
 
-// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
+//==============================================================================
 
 typedef struct _tDattorro
 {
@@ -145,4 +143,6 @@
 }
 #endif
 
-#endif  // LEAFREVERB_H_INCLUDED
+#endif  // LEAF_REVERB_H_INCLUDED
+
+//==============================================================================
--- /dev/null
+++ b/LEAF/Inc/leaf-sample.h
@@ -1,0 +1,114 @@
+/*==============================================================================
+
+    leaf-sample.h
+    Created: 23 Jan 2019 11:22:09am
+    Author:  Mike Mulshine
+
+==============================================================================*/
+
+
+#ifndef LEAF_SAMPLE_H_INCLUDED
+#define LEAF_SAMPLE_H_INCLUDED
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+    
+//==============================================================================
+ 
+#include "leaf-globals.h"
+#include "leaf-math.h"
+    
+//==============================================================================
+    
+    typedef enum RecordMode
+    {
+        RecordOneShot = 0,
+        RecordLoop,
+        RecordModeNil
+    } RecordMode;
+    
+    typedef struct _tSample
+    {
+        float* buff;
+        
+        uint32_t idx;
+        uint32_t length;
+        
+        RecordMode mode;
+        
+        int active;
+        
+    } tSample;
+
+    void  tSample_init (tSample* const, uint32_t length);
+    void  tSample_free (tSample* const);
+    
+    void  tSample_tick (tSample* const, float sample);
+    
+    void  tSample_read(tSample* const, float* buff, uint32_t len);
+    
+    float tSample_get (tSample* const, int idx);
+    
+    void  tSample_start (tSample* const);
+    void  tSample_stop (tSample* const);
+    
+    void  tSample_setRecordMode (tSample* const, RecordMode mode);
+    
+    void  tSample_clear (tSample* const);
+    
+//==============================================================================
+    
+    typedef enum Mode
+    {
+        Normal,
+        Loop,
+        BackAndForth,
+        ModeNil
+    } Mode;
+    
+    typedef struct _tSamplePlayer
+    {
+        tSample* samp;
+        
+        float idx;
+        float inc;
+        int dir;
+        
+        int32_t start;
+        int32_t end;
+        uint32_t len;
+    
+        Mode mode;
+        
+        int active;
+        
+        float gain;
+    } tSamplePlayer;
+    
+    void    tSamplePlayer_init      (tSamplePlayer* const, tSample* s);
+    void    tSamplePlayer_free      (tSamplePlayer* const);
+    
+    float   tSamplePlayer_tick      (tSamplePlayer* const);
+
+    void    tSamplePlayer_setSample (tSamplePlayer* const, tSample* s);
+    
+    void    tSamplePlayer_setMode   (tSamplePlayer* const, Mode mode);
+    
+    void    tSamplePlayer_play      (tSamplePlayer* const);
+    void    tSamplePlayer_stop      (tSamplePlayer* const);
+    
+    void    tSamplePlayer_setStart  (tSamplePlayer* const, int32_t start);
+    void    tSamplePlayer_setEnd    (tSamplePlayer* const, int32_t end);
+    
+    void    tSamplePlayer_setRate   (tSamplePlayer* const, float rate);
+    
+//==============================================================================
+    
+#ifdef __cplusplus
+}
+#endif
+
+#endif // LEAF_SAMPLE_H_INCLUDED
+
+//==============================================================================
--- a/LEAF/Inc/leaf-string.h
+++ b/LEAF/Inc/leaf-string.h
@@ -8,11 +8,14 @@
   ==============================================================================
 */
 
+#ifndef LEAF_STRING_H_INCLUDED
+#define LEAF_STRING_H_INCLUDED
+
 #ifdef __cplusplus
 extern "C" {
 #endif
     
-// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
+//==============================================================================
 
 #include "leaf-globals.h"
 #include "leaf-math.h"
@@ -21,7 +24,7 @@
 #include "leaf-filter.h"
 #include "leaf-oscillator.h"
 
-// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
+//==============================================================================
 
 /* Karplus Strong model */
 typedef struct _tPluck
@@ -62,9 +65,8 @@
 // tPluck Utilities.
 float       tPluck_getLastOut    (tPluck*  const);
 
-
-// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
-
+//==============================================================================
+    
 /* Stif Karplus Strong model */
 typedef struct _tStifKarp
 {
@@ -130,8 +132,12 @@
 // tStifKarp utilities.
 float       tStifKarp_getLastOut         (tStifKarp*  const);
 
-// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
+//==============================================================================
     
 #ifdef __cplusplus
 }
-#endif
+#endif
+
+#endif // LEAF_STRING_H_INCLUDED
+
+//==============================================================================
--- a/LEAF/Inc/leaf-utilities.h
+++ b/LEAF/Inc/leaf-utilities.h
@@ -1,26 +1,24 @@
-/*
-  ==============================================================================
+/*==============================================================================
 
     LEAFUtilities.h
     Created: 20 Jan 2017 12:02:17pm
     Author:  Michael R Mulshine
 
-  ==============================================================================
-*/
+==============================================================================*/
 
-#ifndef LEAFUTILITIES_H_INCLUDED
-#define LEAFUTILITIES_H_INCLUDED
+#ifndef LEAF_UTILITIES_H_INCLUDED
+#define LEAF_UTILITIES_H_INCLUDED
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
+//==============================================================================
 
 #include "leaf-globals.h"
 #include "leaf-math.h"
 
-// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
+//==============================================================================
 
 // STACK implementation (fixed size)
 #define STACK_SIZE 128
@@ -48,7 +46,7 @@
 int     tStack_next                 (tStack* const);
 int     tStack_get                  (tStack* const, int which);
 
-// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
+//==============================================================================
 
 /* Ramp */
 typedef struct _tRamp {
@@ -70,7 +68,7 @@
 int     tRamp_setDest   (tRamp* const, float dest);
 int     tRamp_setVal    (tRamp* const, float val);
 
-// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
+//==============================================================================
 
 /* Compressor */
 typedef struct _tCompressor
@@ -88,7 +86,7 @@
 void    tCompressor_free    (tCompressor* const);
 float   tCompressor_tick    (tCompressor* const, float input);
 
-// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
+//==============================================================================
 
 /* Attack-Decay envelope */
 typedef struct _tEnvelope {
@@ -120,7 +118,7 @@
 int     tEnvelope_loop      (tEnvelope*  const, oBool loop);
 int     tEnvelope_on        (tEnvelope*  const, float velocity);
 
-// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
+//==============================================================================
 
 /* ADSR */
 typedef struct _tADSR
@@ -152,7 +150,7 @@
 int     tADSR_on        (tADSR*  const, float velocity);
 int     tADSR_off       (tADSR*  const);
 
-// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
+//==============================================================================
 
 /* Envelope Follower */
 typedef struct _tEnvelopeFollower
@@ -170,7 +168,7 @@
 int     tEnvelopeFollower_decayCoeff     (tEnvelopeFollower*  const, float decayCoeff);
 int     tEnvelopeFollower_attackThresh   (tEnvelopeFollower*  const, float attackThresh);
 
-// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
+//==============================================================================
 
 /* tAtkDtk */
 #define DEFBLOCKSIZE 1024
@@ -221,7 +219,7 @@
 // find largest transient in input block, return index of attack
 int     tAtkDtk_detect          (tAtkDtk* const, float *in);
 
-// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
+//==============================================================================
 
 // ENV~ from PD, modified for LEAF
 #define MAXOVERLAP 32
@@ -246,12 +244,14 @@
 float   tEnv_tick           (tEnv* const);
 void    tEnv_processBlock   (tEnv* const, float* in);
 
-// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
+//==============================================================================
     
 #ifdef __cplusplus
 }
 #endif
 
-#endif  // LEAFUTILITIES_H_INCLUDED
+#endif  // LEAF_UTILITIES_H_INCLUDED
+
+//==============================================================================
 
 
--- a/LEAF/Inc/leaf-vocoder.h
+++ b/LEAF/Inc/leaf-vocoder.h
@@ -1,26 +1,24 @@
-/*
-  ==============================================================================
+/*==============================================================================
 
     LEAFInstrument.h
     Created: 20 Jan 2017 12:01:54pm
     Author:  Michael R Mulshine
 
-  ==============================================================================
-*/
+==============================================================================*/
 
-#ifndef LEAFINSTRUMENT_H_INCLUDED
-#define LEAFINSTRUMENT_H_INCLUDED
+#ifndef LEAF_VOCODER_H_INCLUDED
+#define LEAF_VOCODER_H_INCLUDED
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
+//==============================================================================
 
 #include "leaf-globals.h"
 #include "leaf-math.h"
 
-// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
+//==============================================================================
 
 /* tTalkbox */
 #define NUM_TALKBOX_PARAM 4
@@ -52,7 +50,7 @@
 void        tTalkbox_lpc         (float *buf, float *car, int32_t n, int32_t o);
 void		tTalkbox_setQuality  (tTalkbox* const, float quality);
 
-// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
+//==============================================================================
 
 /* tVocoder */
 #define NUM_VOCODER_PARAM 8
@@ -79,10 +77,12 @@
 void        tVocoder_update      (tVocoder* const);
 void        tVocoder_suspend     (tVocoder* const);
 
-// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
+//==============================================================================
 
 #ifdef __cplusplus
 }
 #endif
         
-#endif  // LEAFINSTRUMENT_H_INCLUDED
+#endif  // LEAF_VOCODER_H_INCLUDED
+
+//==============================================================================
--- a/LEAF/Inc/leaf-wavefolder.h
+++ b/LEAF/Inc/leaf-wavefolder.h
@@ -1,23 +1,25 @@
-/*
-  ==============================================================================
+/*==============================================================================
 
     leaf-wavefolder.h
     Created: 30 Nov 2018 11:57:05am
     Author:  airship
 
-  ==============================================================================
-*/
+==============================================================================*/
 
+#ifndef LEAF_WAVEFOLDER_H_INCLUDED
+#define LEAF_WAVEFOLDER_H_INCLUDED
+
+
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
+//==============================================================================
 
 #include "leaf-globals.h"
 #include "leaf-math.h"
 
-// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
+//==============================================================================
 
 /* tLockhartWavefolder */
 #define THRESH 10e-10
@@ -45,7 +47,12 @@
 float   tLockhartWavefolder_tick    (tLockhartWavefolder* const, float samp);
 
     
+//==============================================================================
+    
 #ifdef __cplusplus
 }
-#endif
-// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
+#endif
+
+#endif // LEAF_WAVEFOLDER_H_INCLUDED
+
+//==============================================================================
--- a/LEAF/Inc/leaf-wavetables.h
+++ b/LEAF/Inc/leaf-wavetables.h
@@ -1,26 +1,24 @@
-/*
-  ==============================================================================
+/*==============================================================================
 
     LEAFWavetables.h
     Created: 4 Dec 2016 9:42:41pm
     Author:  Michael R Mulshine
 
-  ==============================================================================
-*/
+==============================================================================*/
 
-#ifndef WAVETABLES_H_INCLUDED
-#define WAVETABLES_H_INCLUDED
+#ifndef LEAF_WAVETABLES_H_INCLUDED
+#define LEAF_WAVETABLES_H_INCLUDED
 
 #ifdef __cplusplus
 extern "C" {
-#endif
+#endif
+    
+//==============================================================================
 
-// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
-
 #include "leaf-globals.h"
 #include "leaf-math.h"
 
-// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
+//==============================================================================
 
 
 #define SINE_TABLE_SIZE 2048
@@ -62,7 +60,7 @@
 
 extern const float tanh1[TANH1_TABLE_SIZE];
 
-// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
+//==============================================================================
 
 /* Sine wave table ripped from http://aquaticus.info/pwm-sine-wave. */
 extern const float sinewave[SINE_TABLE_SIZE];
@@ -73,10 +71,12 @@
 
 extern const float squarewave[11][SQR_TABLE_SIZE];
 
-// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
+//==============================================================================
     
 #ifdef __cplusplus
 }
 #endif
 
-#endif  // WAVETABLES_H_INCLUDED
+#endif  // LEAF_WAVETABLES_H_INCLUDED
+
+//==============================================================================
--- a/LEAF/Src/leaf-math.c
+++ b/LEAF/Src/leaf-math.c
@@ -159,7 +159,19 @@
     } else {
         return val;
     }
-}
+}
+
+int   LEAF_clipInt(int min, int val, int max)
+{
+    if (val < min) {
+        return min;
+    } else if (val > max) {
+        return max;
+    } else {
+        return val;
+    }
+}
+
 
 oBool     LEAF_isPrime(uint64_t number )
 {
--- /dev/null
+++ b/LEAF/Src/leaf-sample.c
@@ -1,0 +1,244 @@
+/*
+  ==============================================================================
+
+    LEAFUtilities.c
+    Created: 20 Jan 2017 12:02:17pm
+    Author:  Michael R Mulshine
+
+  ==============================================================================
+*/
+
+
+#if _WIN32 || _WIN64
+
+#include "..\Inc\leaf-sample.h"
+#include "..\leaf.h"
+
+#else
+
+#include "../Inc/leaf-sample.h"
+#include "../leaf.h"
+
+#endif
+
+//==============================================================================
+
+void  tSample_init (tSample* const s, uint32_t length)
+{
+    s->buff = (float*) leaf_alloc( sizeof(float) * length);
+    
+    
+    s->length = length;
+    s->active = 0;
+    s->idx = 0;
+    s->mode = RecordOneShot;
+    
+    tSample_clear(s);
+}
+
+void  tSample_free (tSample* const s)
+{
+    leaf_free(s->buff);
+    leaf_free(s);
+}
+
+void tSample_tick (tSample* const s, float sample)
+{
+    if (s->active == 1)
+    {
+        s->buff[s->idx] = sample;
+        
+        s->idx += 1;
+        
+        if (s->idx >= s->length)
+        {
+            if (s->mode == RecordOneShot)
+            {
+                tSample_stop(s);
+            }
+            else if (s->mode == RecordLoop)
+            {
+                s->idx = 0;
+            }
+        }
+    }
+}
+
+void  tSample_read(tSample* const s, float* buff, uint32_t len)
+{
+    for (int i = 0; i < s->length; i++)
+    {
+        if (i < len)    s->buff[i] = buff[i];
+        else            s->buff[i] = 0.f;
+    }
+}
+
+float tSample_get (tSample* const s, int idx)
+{
+    if ((idx < 0) || (idx >= s->length)) return 0.f;
+    
+    return s->buff[idx];
+}
+
+void  tSample_start(tSample* const s)
+{
+    s->active = 1;
+    s->idx = 0;
+}
+
+void  tSample_stop(tSample* const s)
+{
+    s->active = 0;
+}
+
+void  tSample_setRecordMode (tSample* const s, RecordMode mode)
+{
+    s->mode = mode;
+}
+
+void  tSample_clear (tSample* const s)
+{
+    for (int i = 0; i < s->length; i++)
+    {
+        s->buff[i] = 0.f;
+    }
+}
+
+//==============================================================================
+
+void tSamplePlayer_init         (tSamplePlayer* const p, tSample* s)
+{
+    p->samp = s;
+    
+    p->active = 0;
+    
+    p->start = 0;
+    p->end = p->samp->length - 1;
+    
+    p->len = p->end - p->start;
+    
+    p->idx = 0.f;
+    p->inc = 1.f;
+    
+    p->mode = Normal;
+
+    p->gain = 1.;
+}
+
+void tSamplePlayer_free         (tSamplePlayer* const p)
+{
+    leaf_free(p->samp);
+    leaf_free(p);
+}
+
+float tSamplePlayer_tick        (tSamplePlayer* const p)
+{
+    if (p->active == 0 || (p->len < 4)) return 0.f;
+    
+    float sample = 0.f;
+    
+    float* buff = p->samp->buff;
+    
+    int idx =  (int) p->idx;
+    float alpha = p->idx - idx;
+    
+    int i1 = idx-1;
+    int i3 = idx+1;
+    int i4 = idx+2;
+    
+    if (i1 < p->start)  i1 += p->len;
+    if (i3 > p->end)    i3 -= p->len;
+    if (i4 > p->end)    i4 -= p->len;
+    
+    sample =     LEAF_interpolate_hermite (buff[i1],
+                                           buff[idx],
+                                           buff[i3],
+                                           buff[i4],
+                                           alpha);
+    
+    p->idx += (p->dir * p->inc);
+    
+    if (p->mode == Normal)
+    {
+        // FIX THIS: NORMAL MODE NOT IMPLEMENTED YET
+        if ((p->dir == 1) && (idx > p->end))
+        {
+            p->active = 0;
+        }
+    }
+    else if (p->mode == Loop)
+    {
+        if (idx < p->start) p->idx += (float)(p->len);
+        
+        if (idx > p->end)   p->idx -= (float)(p->len);
+    }
+    else if (p->mode == BackAndForth)
+    {
+        if ((idx < p->start) || (idx > p->end))
+        {
+            p->dir = -p->dir;
+            p->idx += (2*p->inc);
+        }
+    }
+    
+    
+    return sample * p->gain;
+}
+
+void tSamplePlayer_setSample    (tSamplePlayer* const p, tSample* s)
+{
+    p->samp = s;
+}
+
+void tSamplePlayer_setMode      (tSamplePlayer* const p, Mode mode)
+{
+    p->mode = mode;
+}
+
+void tSamplePlayer_play         (tSamplePlayer* const p)
+{
+    p->active = 1;
+}
+
+void tSamplePlayer_stop         (tSamplePlayer* const p)
+{
+    p->active = 0;
+}
+
+void tSamplePlayer_setStart     (tSamplePlayer* const p, int32_t start)
+{
+    p->start = LEAF_clipInt(0, start, (p->samp->length - 1));
+    
+    p->len = abs(p->end - p->start);
+    
+    if (p->start > p->end)  p->dir = -1;
+    else                    p->dir = 1;
+}
+
+void tSamplePlayer_setEnd       (tSamplePlayer* const p, int32_t end)
+{
+    p->end = LEAF_clipInt(0, end, (p->samp->length - 1));
+
+    p->len = abs(p->end - p->start);
+    
+    if (p->start > p->end)  p->dir = -1;
+    else                    p->dir = 1;
+}
+
+void tSamplePlayer_setRate      (tSamplePlayer* const p, float rate)
+{
+    if (rate < 0.f)
+    {
+        rate = -rate;
+        p->dir = -1;
+    }
+    else
+    {
+        p->dir = 1;
+    }
+    
+    p->inc = LEAF_clip(0.f, rate, 8.0f);
+}
+
+
+//==============================================================================
--- a/LEAF/leaf.h
+++ b/LEAF/leaf.h
@@ -31,7 +31,8 @@
 #include ".\Inc\leaf-string.h"
 #include ".\Inc\leaf-pitch.h"
 #include ".\Inc\leaf-formant.h"
-#include ".\Inc\leaf-midi.h"
+#include ".\Inc\leaf-midi.h"
+#include ".\Inc\leaf-sample.h"
 #include ".\Inc\leaf-wavefolder.h"
 #include ".\Inc\leaf-wavetables.h"
 
@@ -49,7 +50,8 @@
 #include "./Inc/leaf-string.h"
 #include "./Inc/leaf-pitch.h"
 #include "./Inc/leaf-formant.h"
-#include "./Inc/leaf-midi.h"
+#include "./Inc/leaf-midi.h"
+#include "./Inc/leaf-sample.h"
 #include "./Inc/leaf-wavefolder.h"
 #include "./Inc/leaf-wavetables.h"
 
--- a/LEAF_JUCEPlugin/LEAF.jucer
+++ b/LEAF_JUCEPlugin/LEAF.jucer
@@ -39,6 +39,7 @@
           <FILE id="OS2D83" name="leaf-utilities.h" compile="0" resource="0"
                 file="../LEAF/Inc/leaf-utilities.h"/>
           <FILE id="Szb5LP" name="leaf-vocoder.h" compile="0" resource="0" file="../LEAF/Inc/leaf-vocoder.h"/>
+          <FILE id="T6KXi7" name="leaf-sample.h" compile="0" resource="0" file="../LEAF/Inc/leaf-sample.h"/>
           <FILE id="PRkOp2" name="leaf-wavefolder.h" compile="0" resource="0"
                 file="../LEAF/Inc/leaf-wavefolder.h"/>
           <FILE id="KpGzKv" name="leaf-wavetables.h" compile="0" resource="0"
@@ -60,6 +61,7 @@
           <FILE id="uKHzgz" name="leaf-utilities.c" compile="1" resource="0"
                 file="../LEAF/Src/leaf-utilities.c"/>
           <FILE id="u1aLLR" name="leaf-vocoder.c" compile="1" resource="0" file="../LEAF/Src/leaf-vocoder.c"/>
+          <FILE id="nmtoFJ" name="leaf-sample.c" compile="1" resource="0" file="../LEAF/Src/leaf-sample.c"/>
           <FILE id="LVoaGm" name="leaf-wavefolder.c" compile="1" resource="0"
                 file="../LEAF/Src/leaf-wavefolder.c"/>
           <FILE id="HRk07h" name="leaf-wavetables.c" compile="1" resource="0"
--- a/LEAF_JUCEPlugin/Source/LEAFLink.cpp
+++ b/LEAF_JUCEPlugin/Source/LEAFLink.cpp
@@ -15,17 +15,14 @@
 
 std::vector<juce::String> cButtonNames =  std::vector<juce::String>
 {
-    
+    "sample"
 };
 
 std::vector<juce::String> cSliderNames =  std::vector<juce::String>
 {
-    "mix",
-    "predelay",
-    "input filter",
-    "feedback filter",
-    "feedback gain",
-    "size"
+    "rate",
+    "start",
+    "end"
 };
 
 std::vector<juce::String> cComboBoxNames =  std::vector<juce::String>
--- a/LEAF_JUCEPlugin/Source/MyTest.cpp
+++ b/LEAF_JUCEPlugin/Source/MyTest.cpp
@@ -16,91 +16,67 @@
 static void leaf_pool_dump(void);
 static void run_pool_test(void);
 
-tDattorro reverb;
+tSample sample;
 
-
-tTapeDelay delay;
-
-float size;
-tRamp dtime;
-
+tSamplePlayer player;
 
 void    LEAFTest_init            (float sampleRate, int blockSize)
 {
     LEAF_init(sampleRate, blockSize, &randomNumberGenerator);
 
-    tDattorro_init(&reverb);
-
-    //tTapeDelay_init(&delay, 0.5f * leaf.sampleRate, leaf.sampleRate);
+    tSample_init(&sample, leaf.sampleRate * 4);
     
-    tRamp_init(&dtime, 500.0f, 1);
+    tSamplePlayer_init(&player, &sample);
+    tSamplePlayer_setMode(&player, Loop);
     
-
-    setSliderValue("mix", reverb.mix);
-    setSliderValue("predelay", reverb.predelay / 200.0f);
-    setSliderValue("input filter", reverb.input_filter / 20000.0f);
-    setSliderValue("feedback filter", reverb.feedback_filter / 20000.0f);
-    setSliderValue("feedback gain", reverb.feedback_gain);
-    setSliderValue("size", reverb.size / 4.0f);
+    leaf_pool_report();
     
-    
-    leaf_pool_report();
+    tSample_start(&sample);
 }
 
 int timer = 0;
-
-
-#define CLICK 0
 
 float   LEAFTest_tick            (float input)
 {
-#if CLICK
-    input = 0.0f;
+    tSample_tick(&sample, input);
     
     timer++;
-    if (timer == (1 * leaf.sampleRate))
+    
+    if (timer >= leaf.sampleRate * 4)
     {
-        timer = 0;
-        
-        input = 1.0f;
+        tSamplePlayer_play(&player);
     }
-#endif
-    //tTapeDelay_setDelay(&delay, tRamp_tick(&dtime));
     
-    //return tTapeDelay_tick(&delay, input);
-    
-    
-    tDattorro_setSize(&reverb, tRamp_tick(&dtime));
-    
-    return tDattorro_tick(&reverb, input);
-    
+    return tSamplePlayer_tick(&player);
 }
-
+
+bool lastState = false;
 void    LEAFTest_block           (void)
 {
-  
-    float val = getSliderValue("mix");
-    tDattorro_setMix(&reverb, val);
+    float val = getSliderValue("rate");
     
-    val = getSliderValue("predelay");
-    tDattorro_setInputDelay(&reverb, val * 200.0f);
+    tSamplePlayer_setRate(&player, val * 16.0f - 8.0f);
     
-    val = getSliderValue("input filter");
-    tDattorro_setInputFilter(&reverb, val * 20000.0f);
+    val = getSliderValue("start");
+    float start = val * sample.length;
+    tSamplePlayer_setStart(&player,  start);
+    DBG("start: " + String(start));
     
-    val = getSliderValue("feedback filter");
-    tDattorro_setFeedbackFilter(&reverb, val * 20000.0f);
+    val = getSliderValue("end");
+    float end = val * sample.length;
+    tSamplePlayer_setEnd(&player, end);
+    DBG("end: " + String(end));
     
-    val = getSliderValue("feedback gain");
-    tDattorro_setFeedbackGain(&reverb, val);
+    bool state = getButtonState("sample");
     
-    val = getSliderValue("size");
-    tRamp_setDest(&dtime, val * reverb.size_max);
+    if (state && !lastState)
+    {
+        timer = 0;
+        tSamplePlayer_stop(&player);
+        tSample_start(&sample);
+    }
     
-    
-    //float val = getSliderValue("size");
-    //tRamp_setDest(&dtime, val * leaf.sampleRate + 1);
-    
+    lastState = state;
 }
 
 void    LEAFTest_controllerInput (int cnum, float cval)
--- a/LEAF_JUCEPlugin/Source/UIComponent.cpp
+++ b/LEAF_JUCEPlugin/Source/UIComponent.cpp
@@ -144,9 +144,9 @@
     setSliderValue(s->getName(), s->getValue());
 }
 
-void UIComponent::buttonClicked (Button* b)
+void UIComponent::buttonStateChanged (Button* b)
 {
-    setButtonState(b->getName(), true);
+    setButtonState(b->getName(), b->getState());
 }
 
 void UIComponent::comboBoxChanged (ComboBox* cb)
--- a/LEAF_JUCEPlugin/Source/UIComponent.h
+++ b/LEAF_JUCEPlugin/Source/UIComponent.h
@@ -35,7 +35,8 @@
     
     void sliderValueChanged(Slider* s) override;
     
-    void buttonClicked (Button* b) override;
+    void buttonClicked(Button*b) override {};
+    void buttonStateChanged(Button* b) override;
     
     void textEditorTextChanged (TextEditor&) override;