Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed USBDevice PinDetect
Diff: Audio/KarplusStrong.h
- Revision:
- 13:bb0ec927e458
- Child:
- 15:aa5a4c350251
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Audio/KarplusStrong.h Sun Apr 17 21:35:23 2016 +0000 @@ -0,0 +1,65 @@ + +/** + * The processor used for teh implementation of Karplus strong. + * + * @author Austin Suszek + */ + +#ifndef AS_KARPLUS_STRONG_H +#define AS_KARPLUS_STRONG_H + +#include <math.h> +#include <stdlib.h> +#include <time.h> + +#include "../Constants.h" + +class KarplusStrong { +public: + + /** + * Constructor + */ + KarplusStrong(); + + /** + * Signal the start of a new note. + * + * @param key The integer representation of the note + * @param velocity The float representation of the velocity (NOT int!) + */ + void midiNoteOn(int key, float velocity); + + /** + * Create the initial buffer sample for the specific index. + * + * @param bufferIndex The index to process + * @return The new sample to save in the buffer + */ + float fillBuffer(const int bufferIndex); + + /** + * Process the existing buffer for the specific index. + * + * @param inputSample The sample to process from the buffer + * @return The modified sample to save in the buffer + */ + float processBuffer(const float inputSample); + +private: + + static void initializeNoiseSeed(); + static float getRand() { + return float(rand()) / float(RAND_MAX); + }; + + float lastOutput; + float filterCoefficient; + float nextFilterCoefficient; + float velocity; + + float lowpassFilter(const float output, const float input, const float smoothingFactor); + +}; + +#endif \ No newline at end of file