From 51dcc8fe07ac57070754a631eb63788cac9dc438 Mon Sep 17 00:00:00 2001 From: Chris Kiefer Date: Thu, 26 Jul 2012 18:02:23 +0100 Subject: copying changes back --- maximilian.cpp | 55 +++++++++++++++++++++++++++++++++---------------------- maximilian.h | 42 ++++++++++++++++++++++++------------------ 2 files changed, 57 insertions(+), 40 deletions(-) diff --git a/maximilian.cpp b/maximilian.cpp index ed2b1f6..b0f94a3 100644 --- a/maximilian.cpp +++ b/maximilian.cpp @@ -39,10 +39,12 @@ * Uncomment the following to include Sean Barrett's Ogg Vorbis decoder. * If you're on windows, make sure to add the files std_vorbis.c and std_vorbis.h to your project*/ -//#define VORBIS +#define VORBIS #ifdef VORBIS -#include "stb_vorbis.h" +extern "C" { + #include "stb_vorbis.h" +} #endif //This used to be important for dealing with multichannel playback @@ -372,13 +374,14 @@ bool maxiSample::load(string fileName, int channel) { return read(); } -bool maxiSample::loadOgg(char *fileName, int channel) { +bool maxiSample::loadOgg(string fileName, int channel) { #ifdef VORBIS bool result; - result=fileName; readChannel=channel; int channelx; - myDataSize = stb_vorbis_decode_filename(fileName, &channelx, &temp); + cout << fileName << endl; + myDataSize = stb_vorbis_decode_filename(const_cast(fileName.c_str()), &channelx, &temp); + result = myDataSize > 0; printf("\nchannels = %d\nlength = %d",channelx,myDataSize); printf("\n"); myChannels=(short)channelx; @@ -457,6 +460,7 @@ bool maxiSample::read() length=myDataSize*(0.5/myChannels); inFile.close(); // close the input file + cout << "Ch: " << myChannels << ", len: " << length << endl; if (myChannels>1) { int position=0; int channel=readChannel*2; @@ -468,6 +472,8 @@ bool maxiSample::read() } temp = (short*) malloc(myDataSize * sizeof(char)); memcpy(temp, myData, myDataSize * sizeof(char)); + + free(myData); }else { // cout << "ERROR: Could not load sample: " <threshold && attackphase!=1){ holdcount=0; releasephase=0; @@ -938,7 +948,7 @@ double maxiDyn::gate(double input, double threshold, long holdtime, double attac if (releasephase==1 && amplitude>0.) { output=input*(amplitude*=release); - + } return output; @@ -1012,7 +1022,7 @@ double maxiEnv::ar(double input, double attack, double release, long holdtime, i holdphase=0; releasephase=1; } - + if (releasephase==1 && amplitude>0.) { output=input*(amplitude*=release); @@ -1075,10 +1085,11 @@ double maxiEnv::adsr(double input, double attack, double decay, double sustain, } double convert::mtof(int midinote) { - + return mtofarray[midinote]; } + void maxiEnvelopeFollower::setAttack(double attackMS) { attack = pow( 0.01, 1.0 / ( attackMS * maxiSettings::sampleRate * 0.001 ) ); } diff --git a/maximilian.h b/maximilian.h index 5d79467..de07d9a 100755 --- a/maximilian.h +++ b/maximilian.h @@ -70,7 +70,7 @@ class maxiOsc { double endphase; double output; double tri; - + public: maxiOsc(); @@ -98,7 +98,7 @@ class maxiEnvelope { double currentval; double nextval; int isPlaying; - + public: double line(int numberofsegments,double segments[100]); void trigger(int index,double amp); @@ -120,7 +120,7 @@ public: maxiDelayline(); double dl(double input, int size, double feedback); double dl(double input, int size, double feedback, int position); - + }; @@ -136,6 +136,7 @@ class maxiFilter { double y;//pos double z;//pole double c;//filter coefficient + public: maxiFilter():x(0.0), y(0.0), z(0.0), c(0.0){}; double cutoff; @@ -224,7 +225,7 @@ public: short* temp; // get/set for the Path property - + ~maxiSample() { if (myData) free(myData); @@ -233,21 +234,21 @@ public: } - maxiSample():myData(NULL),position(0), recordPosition(0), myChannels(1), mySampleRate(maxiSettings::sampleRate) {}; + maxiSample():myData(NULL),temp(NULL),position(0), recordPosition(0), myChannels(1), mySampleRate(maxiSettings::sampleRate) {}; bool load(string fileName, int channel=0); - bool loadOgg(char *filename,int channel=0); + bool loadOgg(string filename,int channel=0); void trigger(); // read a wav file into this class bool read(); - - //read an ogg file into this class using stb_vorbis - bool readOgg(); - void loopRecord(double newSample, const bool recordEnabled, const double recordMix) { + //read an ogg file into this class using stb_vorbis + bool readOgg(); + + void loopRecord(double newSample, const bool recordEnabled, const double recordMix) { loopRecordLag.addSample(recordEnabled); if(recordEnabled) { double currentSample = ((short*)myData)[(unsigned long)recordPosition] / 32767.0; @@ -261,7 +262,8 @@ public: } void clear(); - + + void reset(); double play(); @@ -274,7 +276,7 @@ public: double play(double frequency, double start, double end, double &pos); double play(double frequency, double start, double end); - + double play4(double frequency, double start, double end); double bufferPlay(unsigned char &bufferin,long length); @@ -284,10 +286,13 @@ public: double bufferPlay(unsigned char &bufferin,double frequency, double start, double end); double bufferPlay4(unsigned char &bufferin,double frequency, double start, double end); - - bool save() + bool save() { + save(myPath); + } + + bool save(string filename) { - fstream myFile (myPath.c_str(), ios::out | ios::binary); + fstream myFile (filename.c_str(), ios::out | ios::binary); // write the wav file per the wav file format myFile.seekp (0, ios::beg); @@ -331,7 +336,7 @@ public: val = max(min(val, inMax), inMin); return pow((outMax / outMin), (val - inMin) / (inMax - inMin)) * outMin; } - + static double inline explin(double val, double inMin, double inMax, double outMin, double outMax) { //clipping val = max(min(val, inMax), inMin); @@ -348,7 +353,7 @@ public: class maxiDyn { - + public: double gate(double input, double threshold=0.9, long holdtime=1, double attack=1, double release=0.9995); @@ -386,7 +391,7 @@ public: }; class convert { - public: +public: double mtof(int midinote); }; @@ -485,6 +490,7 @@ public: env = release * (env - input) + input; return env; } + void reset() {env=0;} private: double attack, release, env; }; -- cgit v1.3