aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Kiefer <chrisk13fer@gmail.com>2012-07-26 18:02:23 +0100
committerChris Kiefer <chrisk13fer@gmail.com>2012-07-26 18:02:23 +0100
commit51dcc8fe07ac57070754a631eb63788cac9dc438 (patch)
tree7017e3d55b2422facdf619638ccb69f0a780b922
parent684cd0eeefba34b54764bf0735f1ca0fbca1e885 (diff)
copying changes back
-rw-r--r--maximilian.cpp55
-rwxr-xr-xmaximilian.h42
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<char*>(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: " <<myPath << endl; //This line seems to be hated by windows
@@ -480,22 +486,21 @@ bool maxiSample::read()
}
double maxiSample::play() {
- short* buffer = (short *)myData;
position++;
if ((long) position == length) position=0;
- output = (double) buffer[(long)position]/32767.0;
+ output = (double) temp[(long)position]/32767.0;
return output;
}
double maxiSample::playOnce() {
- position=(position+1);
- double remainder = position - (long) position;
+ position++;
if ((long) position<length)
- output = (double) ((1-remainder) * temp[1+ (long) position] + remainder * temp[2+(long) position])/32767;//linear interpolation
- else
- output=0;
+ output = (double) temp[(long)position]/32767.0;
+ else {
+ output=0;
+ }
+ return output;
- return(output);
}
double maxiSample::playOnce(double speed) {
@@ -883,23 +888,28 @@ void maxiSample::getLength() {
}
void maxiSample::setLength(unsigned long numSamples) {
- char *newData = (char*) malloc(sizeof(short) * numSamples);
- if (NULL!=myData) {
+ cout << "Length: " << numSamples << endl;
+ short *newData = (short*) malloc(sizeof(short) * numSamples);
+ if (NULL!=temp) {
unsigned long copyLength = min((unsigned long)length, numSamples);
- memcpy(newData, myData, sizeof(short) * copyLength);
+ memcpy(newData, temp, sizeof(short) * copyLength);
}
- myData = newData;
+ temp = newData;
myDataSize = numSamples * 2;
length=numSamples;
position=0;
recordPosition=0;
-
}
void maxiSample::clear() {
memset(myData, 0, myDataSize);
}
+void maxiSample::reset() {
+ position=0;
+}
+
+
@@ -908,7 +918,7 @@ void maxiSample::clear() {
Annoyingly, a short attack is 0.1, and a short release is 0.99. I'll sort this out laters */
double maxiDyn::gate(double input, double threshold, long holdtime, double attack, double release) {
-
+
if (fabs(input)>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;
};