Mercurial > hg > beaglert
changeset 233:18d03901f866 mergingClockSync
Turned gShouldStop into int
author | Giulio Moro <giuliomoro@yahoo.it> |
---|---|
date | Sun, 10 Apr 2016 03:20:52 +0200 |
parents | 600355cf4ed5 |
children | 99b4d81d9c95 |
files | .cproject core/IirFilter.cpp core/RTAudio.cpp include/BeagleRT.h include/IirFilter.h include/NetworkSend.h projects/d-box/logger.cpp projects/d-box/sensors.cpp |
diffstat | 8 files changed, 162 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/.cproject Sun Apr 10 03:14:33 2016 +0200 +++ b/.cproject Sun Apr 10 03:20:52 2016 +0200 @@ -178,7 +178,7 @@ <listOptionValue builtIn="false" value="/usr/local/linaro/arm-linux-gnueabihf/include/"/> </option> <option id="gnu.cpp.compiler.option.dialect.std.776548502" name="Language standard" superClass="gnu.cpp.compiler.option.dialect.std" value="gnu.cpp.compiler.dialect.default" valueType="enumerated"/> - <option id="gnu.cpp.compiler.option.other.other.398422461" name="Other flags" superClass="gnu.cpp.compiler.option.other.other" value="-c -fmessage-length=0 -U_FORTIFY_SOURCE" valueType="string"/> + <option id="gnu.cpp.compiler.option.other.other.398422461" name="Other flags" superClass="gnu.cpp.compiler.option.other.other" value="-c -fmessage-length=0 -U_FORTIFY_SOURCE -O3 -march=armv7-a -mtune=cortex-a8 -mfloat-abi=hard -mfpu=neon --fast-math -ftree-vectorize -ftree-vectorizer-verbose=10" valueType="string"/> <inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.601059736" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/> </tool> <tool command="arm-linux-gnueabihf-gcc" commandLinePattern="${COMMAND} ${FLAGS} ${OUTPUT_FLAG} ${OUTPUT_PREFIX}${OUTPUT} ${INPUTS}" id="cdt.managedbuild.tool.gnu.c.compiler.exe.release.1302828968" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.exe.release"> @@ -198,6 +198,7 @@ <option id="gnu.c.compiler.option.preprocessor.undef.symbol.980935416" name="Undefined symbols (-U)" superClass="gnu.c.compiler.option.preprocessor.undef.symbol" valueType="undefDefinedSymbols"> <listOptionValue builtIn="false" value="_FORTIFY_SOURCE"/> </option> + <option id="gnu.c.compiler.option.misc.other.1568308112" name="Other flags" superClass="gnu.c.compiler.option.misc.other" value="-c -fmessage-length=0 -O3 -march=armv7-a -mtune=cortex-a8 -mfloat-abi=hard -mfpu=neon --fast-math -ftree-vectorize -ftree-vectorizer-verbose=10" valueType="string"/> <inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.574072828" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/> </tool> <tool command="arm-linux-gnueabihf-g++ " id="cdt.managedbuild.tool.gnu.c.linker.exe.release.281634187" name="GCC C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.exe.release"/>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/core/IirFilter.cpp Sun Apr 10 03:20:52 2016 +0200 @@ -0,0 +1,69 @@ +/* + * IirFilter.cpp + * + * Created on: 17 Sep 2015 + * Author: giulio + */ +#include "IirFilter.h" + +IirFilterStage::IirFilterStage(){ + for(int n = 0; n < IIR_FILTER_STAGE_COEFFICIENTS; n++){ + coefficients[n] = 0; + } + for(int n = 0; n < IIR_FILTER_STAGE_STATES; n++){ + states[n]=0; + } +} +void IirFilterStage::setCoefficients(double* newCoefficients){ + for(int n = 0; n < IIR_FILTER_STAGE_COEFFICIENTS; n++){ + coefficients[n] = newCoefficients[n]; + } +} +void IirFilterStage::setStates(double* newStates){ + for(int n = 0; n < IIR_FILTER_STAGE_STATES; n++){ + states[n] = newStates[n]; + } +} + +/* struct IirFilterStage* stages; + int numberOfStages; +*/ +IirFilter::IirFilter(){ + stages=(IirFilterStage**)0; + setNumberOfStages(0); +} +IirFilter::IirFilter(int newNumberOfStages){ + setNumberOfStages(newNumberOfStages); +} +IirFilter::IirFilter(int newNumberOfStages, double* newCoefficients){ + setNumberOfStages(newNumberOfStages); + setCoefficients(newCoefficients); +} +void IirFilter::dealloc(){ + if( stages == 0 ) + return; + for(int n = 0; n < numberOfStages; n++){ + delete stages[n]; + } + delete stages; + stages = 0; + numberOfStages = 0; +} +void IirFilter::setCoefficients(double* newCoefficients){ + for(int n = 0; n < numberOfStages; n++){ + stages[n]->setCoefficients(newCoefficients); + } +}; +void IirFilter::setStates(double* newStates){ + for(int n = 0; n < numberOfStages; n++){ + stages[n]->setStates(newStates); + } +}; +void IirFilter::setNumberOfStages(int newNumberOfStages){ + dealloc(); + numberOfStages=newNumberOfStages; + stages = new IirFilterStage*[numberOfStages]; + for( int n = 0; n < numberOfStages; n++){ + stages[n] = new IirFilterStage; + } +}
--- a/core/RTAudio.cpp Sun Apr 10 03:14:33 2016 +0200 +++ b/core/RTAudio.cpp Sun Apr 10 03:20:52 2016 +0200 @@ -64,7 +64,7 @@ } // Flag which tells the audio task to stop -bool gShouldStop = false; +int gShouldStop = false; // general settings char gPRUFilename[MAX_PRU_FILENAME_LENGTH]; // Path to PRU binary file (internal code if empty)_
--- a/include/BeagleRT.h Sun Apr 10 03:14:33 2016 +0200 +++ b/include/BeagleRT.h Sun Apr 10 03:20:52 2016 +0200 @@ -271,7 +271,7 @@ * to indicate that audio processing should terminate. Calling BeagleRT_stopAudio() * has the effect of setting this to \c true. */ -extern bool gShouldStop; +extern int gShouldStop; // *** User-defined render functions ***
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/include/IirFilter.h Sun Apr 10 03:20:52 2016 +0200 @@ -0,0 +1,86 @@ +/* + * IirFilter.h + * + * Created on: 17 Sep 2015 + * Author: giulio + */ + +#ifndef IIRFILTER_H_ +#define IIRFILTER_H_ + +#define IIR_FILTER_STAGE_COEFFICIENTS (5) +#define IIR_FILTER_STAGE_STATES (IIR_FILTER_STAGE_COEFFICIENTS - 1) + +class IirFilterStage{ //TODO : to save (some) memory we should only store the coefficients pointers here, + //so that IirFilter can share them among multiple stages if needbe) +private: + double coefficients[IIR_FILTER_STAGE_COEFFICIENTS]; // these are b0,b1,b2,a1,a2 + double states[IIR_FILTER_STAGE_STATES]; // these are xprev, xprevprev, yprev, yprevprev +public: + IirFilterStage(); + void setCoefficients(double* newCoefficients); + void setStates(double* newStates); + // this is not meant to be efficient, just of practical use! + double process(double in){ + process(&in, 1); + return in; + } + + void process(double* inout, int length){ + // make variables explicit. A smart compiler will optimize these out, right? + double b0=coefficients[0]; + double b1=coefficients[1]; + double b2=coefficients[2]; + double a1=coefficients[3]; + double a2=coefficients[4]; + double x1 = states[0]; + double x2= states[1]; + double y1 = states[2]; + double y2 = states[3]; + for(int n = 0; n < length; n++){ + double x0 = inout[n]; + double y = x0 * b0 + x1 * b1 + x2 * b2 + + - y1 * a1 - y2 * a2; + inout[n] = y; + x2 = x1; + x1 = x0; + y2 = y1; + y1 = y; + } + states[0] = x1; + states[1] = x2; + states[2] = y1; + states[3] = y2; + } +}; + +class IirFilter{ +private: + struct IirFilterStage** stages; + int numberOfStages; + void dealloc(); +public: + IirFilter(); + IirFilter(int newNumberOfStages); + IirFilter(int newNumberOfStages, double *newCoefficients); + void setCoefficients(double* newCoefficients); + void setStates(double* newStates); + void setNumberOfStages(int newNumberOfStages); +// double process(double in); +// inline void process(double* inout, int length); +// inline void process(double* in, double* out, int length); + double process(double in){ + process(&in, 1); + return in; + }; + void process(double* inout, int length){ + for(int n = 0; n < numberOfStages && n < 8/* TODO: this "8" compensates for a memory corruption somewhere on the BBB*/; n++){ + stages[n]->process(inout, length); + } + } +}; + + +//void IirFilter::process(double* in, double* out, int length); + +#endif /* IIRFILTER_H_ */
--- a/include/NetworkSend.h Sun Apr 10 03:14:33 2016 +0200 +++ b/include/NetworkSend.h Sun Apr 10 03:20:52 2016 +0200 @@ -11,7 +11,7 @@ #include <UdpClient.h> #include <vector> #include <string> -extern bool gShouldStop; +extern int gShouldStop; #endif /* USE_JUCE */ #define NETWORK_AUDIO_BUFFER_SIZE 302
--- a/projects/d-box/logger.cpp Sun Apr 10 03:14:33 2016 +0200 +++ b/projects/d-box/logger.cpp Sun Apr 10 03:20:52 2016 +0200 @@ -8,7 +8,7 @@ #include "logger.h" // main extern vars -extern bool gShouldStop; +extern int gShouldStop; extern int gVerbose; // file nanme extern vars
--- a/projects/d-box/sensors.cpp Sun Apr 10 03:14:33 2016 +0200 +++ b/projects/d-box/sensors.cpp Sun Apr 10 03:20:52 2016 +0200 @@ -22,7 +22,7 @@ extern vector<OscillatorBank*> gOscBanks; extern int gCurrentOscBank; extern int gNextOscBank; -extern bool gShouldStop; +extern int gShouldStop; extern int gVerbose; float gSensor0LatestTouchPos = 0; // most recent pitch touch location [0-1] on sensor 0, used by render.cpp