aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormick <mickgrierson@gmail.com>2012-06-15 19:45:16 +0100
committermick <mickgrierson@gmail.com>2012-06-15 19:45:16 +0100
commit3cdbccabbe8d58cf791a1c80939b43dc340bc735 (patch)
treee04430ebcc544ba93f1e2a1adc0dbdaf7e2ec9ae
parente44a45b9e2ca3f4e03338f4175023f91b5990ea3 (diff)
Small changes to maxisample
-rwxr-xr-xmain.cpp6
-rw-r--r--maximilian.cpp65
-rw-r--r--maximilianTest.xcodeproj/project.xcworkspace/xcuserdata/mickgrierson.xcuserdatad/UserInterfaceState.xcuserstatebin39740 -> 41779 bytes
3 files changed, 26 insertions, 45 deletions
diff --git a/main.cpp b/main.cpp
index 9a0c632..2177c9d 100755
--- a/main.cpp
+++ b/main.cpp
@@ -4,9 +4,9 @@ maxiSample beats; //We give our sample a name. It's called beats this time. We c
void setup() {//some inits
-// beats.loadOgg("/Users/mickgrierson/Documents/workspace/vorbis_test/ogg_test/thingy2.ogg");//load in your samples. Provide the full path to a wav file.
+// beats.loadOgg("/Users/mickgrierson/Documents/workspace/vorbis_test/ogg_test/thingy2.ogg");//load in your samples. Provide the full path to an ogg file if ogg enabled (uncomment #define VORBIS and add the stb_vorbis files).
- beats.load("/Users/mickgrierson/Documents/workspace/vorbis_test/ogg_test/thingy.wav");//load in your samples. Provide the full path to a wav file.
+ beats.load("/Users/mickgrierson/Documents/workspace/vorbis_test/ogg_test/thingy.wav");//load in your samples. Provide the full path to a wav file.
printf("Summary:\n%s", beats.getSummary());//get info on samples if you like.
@@ -15,7 +15,7 @@ void setup() {//some inits
void play(double *output) {//this is where the magic happens. Very slow magic.
// output[0]=beats.play();//just play the file. Looping is default for all play functions.
- output[0]=beats.play(0.5);//play the file with a speed setting. 1. is normal speed.
+ output[0]=beats.play(1.0);//play the file with a speed setting. 1. is normal speed.
// *output=beats.play(0.5,0,44100);//linear interpolationplay with a frequency input, start point and end point. Useful for syncing.
// *output=beats.play4(0.5,0,100000);//cubic interpolation play with a frequency input, start point and end point. Useful for syncing.
diff --git a/maximilian.cpp b/maximilian.cpp
index ea8775f..7bd05df 100644
--- a/maximilian.cpp
+++ b/maximilian.cpp
@@ -468,7 +468,6 @@ bool maxiSample::read()
}
}
temp = (short*) malloc(myDataSize * sizeof(char));
-// temp=(short*)myData;
memcpy(temp, myData, myDataSize * sizeof(char));
}else {
@@ -482,26 +481,20 @@ bool maxiSample::read()
}
double maxiSample::play() {
-// long length=myDataSize*(1./myChannels);
double remainder;
- //short* buffer = (short *)myData;
- short* buffer = temp;
position=(position+1);
remainder = position - (long) position;
if ((long) position>length) position=0;
output =
- (double) ((1-remainder) * buffer[1+ (long) position] + remainder * buffer[2+(long) position])/32767;//linear interpolation
+ (double) ((1-remainder) * temp[1+ (long) position] + remainder * temp[2+(long) position])/32767;//linear interpolation
return(output);
}
double maxiSample::playOnce() {
-// long length=myDataSize*(0.5/myChannels);
- // short* buffer = (short *)myData;
- short* buffer = temp;
position=(position+1);
double remainder = position - (long) position;
if ((long) position<length)
- output = (double) ((1-remainder) * buffer[1+ (long) position] + remainder * buffer[2+(long) position])/32767;//linear interpolation
+ output = (double) ((1-remainder) * temp[1+ (long) position] + remainder * temp[2+(long) position])/32767;//linear interpolation
else
output=0;
@@ -509,14 +502,10 @@ double maxiSample::playOnce() {
}
double maxiSample::playOnce(double speed) {
- //long a,b;
- // long length=myDataSize*0.5;
- // short* buffer = (short *)myData;
- short* buffer = temp;
position=position+((speed*chandiv)/(maxiSettings::sampleRate/mySampleRate));
double remainder = position - (long) position;
if ((long) position<length)
- output = (double) ((1-remainder) * buffer[1+ (long) position] + remainder * buffer[2+(long) position])/32767;//linear interpolation
+ output = (double) ((1-remainder) * temp[1+ (long) position] + remainder * temp[2+(long) position])/32767;//linear interpolation
else
output=0;
return(output);
@@ -525,8 +514,6 @@ double maxiSample::playOnce(double speed) {
double maxiSample::play(double speed) {
double remainder;
long a,b;
-// long length=myDataSize*0.5;
- short* buffer = temp;
position=position+((speed*chandiv)/(maxiSettings::sampleRate/mySampleRate));
if (speed >=0) {
@@ -547,7 +534,7 @@ double maxiSample::play(double speed) {
b=length-1;
}
- output = (double) ((1-remainder) * buffer[a] + remainder * buffer[b])/32767;//linear interpolation
+ output = (double) ((1-remainder) * temp[a] + remainder * temp[b])/32767;//linear interpolation
} else {
if ((long) position<0) position=length;
remainder = position - floor(position);
@@ -564,7 +551,7 @@ double maxiSample::play(double speed) {
else {
b=0;
}
- output = (double) ((-1-remainder) * buffer[a] + remainder * buffer[b])/32767;//linear interpolation
+ output = (double) ((-1-remainder) * temp[a] + remainder * temp[b])/32767;//linear interpolation
}
return(output);
}
@@ -575,12 +562,8 @@ double maxiSample::play(double frequency, double start, double end) {
double maxiSample::play(double frequency, double start, double end, double &pos) {
double remainder;
- // long length=myDataSize;
-
if (end>=length) end=length-1;
long a,b;
-// short* buffer = (short *)myData;
- short* buffer = temp;
if (frequency >0.) {
if (pos<start) {
@@ -605,8 +588,8 @@ double maxiSample::play(double frequency, double start, double end, double &pos)
b=length-1;
}
- output = (double) ((1-remainder) * buffer[a] +
- remainder * buffer[b])/32767;//linear interpolation
+ output = (double) ((1-remainder) * temp[a] +
+ remainder * temp[b])/32767;//linear interpolation
} else {
frequency=frequency-(frequency+frequency);
if ( pos <= start ) pos = end;
@@ -625,8 +608,8 @@ double maxiSample::play(double frequency, double start, double end, double &pos)
else {
b=0;
}
- output = (double) ((-1-remainder) * buffer[a] +
- remainder * buffer[b])/32767;//linear interpolation
+ output = (double) ((-1-remainder) * temp[a] +
+ remainder * temp[b])/32767;//linear interpolation
}
@@ -638,8 +621,6 @@ double maxiSample::play(double frequency, double start, double end, double &pos)
double maxiSample::play4(double frequency, double start, double end) {
double remainder;
double a,b,c,d,a1,a2,a3;
- // short* buffer = (short *)myData;
- short* buffer = temp;
if (frequency >0.) {
if (position<start) {
position=start;
@@ -648,26 +629,26 @@ double maxiSample::play4(double frequency, double start, double end) {
position += ((end-start)/(maxiSettings::sampleRate/(frequency*chandiv)));
remainder = position - floor(position);
if (position>0) {
- a=buffer[(int)(floor(position))-1];
+ a=temp[(int)(floor(position))-1];
} else {
- a=buffer[0];
+ a=temp[0];
}
- b=buffer[(long) position];
+ b=temp[(long) position];
if (position<end-2) {
- c=buffer[(long) position+1];
+ c=temp[(long) position+1];
} else {
- c=buffer[0];
+ c=temp[0];
}
if (position<end-3) {
- d=buffer[(long) position+2];
+ d=temp[(long) position+2];
} else {
- d=buffer[0];
+ d=temp[0];
}
a1 = 0.5f * (c - a);
a2 = a - 2.5 * b + 2.f * c - 0.5f * d;
@@ -680,26 +661,26 @@ double maxiSample::play4(double frequency, double start, double end) {
position -= ((end-start)/(maxiSettings::sampleRate/(frequency*chandiv)));
remainder = position - floor(position);
if (position>start && position < end-1) {
- a=buffer[(long) position+1];
+ a=temp[(long) position+1];
} else {
- a=buffer[0];
+ a=temp[0];
}
- b=buffer[(long) position];
+ b=temp[(long) position];
if (position>start) {
- c=buffer[(long) position-1];
+ c=temp[(long) position-1];
} else {
- c=buffer[0];
+ c=temp[0];
}
if (position>start+1) {
- d=buffer[(long) position-2];
+ d=temp[(long) position-2];
} else {
- d=buffer[0];
+ d=temp[0];
}
a1 = 0.5f * (c - a);
a2 = a - 2.5 * b + 2.f * c - 0.5f * d;
diff --git a/maximilianTest.xcodeproj/project.xcworkspace/xcuserdata/mickgrierson.xcuserdatad/UserInterfaceState.xcuserstate b/maximilianTest.xcodeproj/project.xcworkspace/xcuserdata/mickgrierson.xcuserdatad/UserInterfaceState.xcuserstate
index 314a90a..cc019f6 100644
--- a/maximilianTest.xcodeproj/project.xcworkspace/xcuserdata/mickgrierson.xcuserdatad/UserInterfaceState.xcuserstate
+++ b/maximilianTest.xcodeproj/project.xcworkspace/xcuserdata/mickgrierson.xcuserdatad/UserInterfaceState.xcuserstate
Binary files differ