Austin Suszek / Mbed 2 deprecated MIDISynthesizer

Dependencies:   mbed USBDevice PinDetect

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers KarplusStrong.h Source File

KarplusStrong.h

00001 
00002 /**
00003  * The processor used for teh implementation of Karplus strong.
00004  *
00005  * @author Austin Suszek
00006  */
00007 
00008 #ifndef AS_KARPLUS_STRONG_H
00009 #define AS_KARPLUS_STRONG_H
00010 
00011 #include <math.h>
00012 #include <stdlib.h>
00013 #include <time.h>
00014 
00015 #include "../Constants.h"
00016 
00017 class KarplusStrong {
00018 public:
00019     
00020     /**
00021      * Constructor
00022      */
00023     KarplusStrong();
00024     
00025     /**
00026      * Signal the start of a new note.
00027      *
00028      * @param key The integer representation of the note
00029      * @param velocity The float representation of the velocity (NOT int!)
00030      */
00031     void midiNoteOn(int key, float velocity);
00032     
00033     /**
00034      * Create the initial buffer sample for the specific index.
00035      *
00036      * @param bufferIndex The index to process
00037      * @return The new sample to save in the buffer
00038      */
00039     float fillBuffer(const int bufferIndex);
00040     
00041     /**
00042      * Process the existing buffer for the specific index.
00043      *
00044      * @param inputSample The sample to process from the buffer
00045      * @return The modified sample to save in the buffer
00046      */
00047     float processBuffer(const float inputSample);
00048     
00049 private:
00050 
00051     static void initializeNoiseSeed();
00052     static float getRand() {
00053         return float(rand()) / float(RAND_MAX);   
00054     };
00055     static float getRandSample() {
00056         return 1.0 - 2.0 * getRand();  
00057     };
00058     
00059     float lastOutput;
00060     float filterCoefficient;
00061     float nextFilterCoefficient;
00062     
00063     static const float pluckDampingVariationMin;
00064     static const float pluckDampingVariationDifference;
00065     float pluckDampingCoefficient;
00066     
00067     float lowpassFilter(const float output, const float input, const float smoothingFactor);
00068 
00069 };
00070 
00071 #endif