Commit 2090a747 authored by Dr-Dan's avatar Dr-Dan
Browse files

binded more play functions to maxiSample, play4 is misbehaving

parent f808123b
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDESourceControlProjectFavoriteDictionaryKey</key>
<false/>
<key>IDESourceControlProjectIdentifier</key>
<string>60ED41D8-5A86-4A08-934A-D5D543E71DB5</string>
<key>IDESourceControlProjectName</key>
<string>project</string>
<key>IDESourceControlProjectOriginsDictionary</key>
<dict>
<key>2653DE3A5C3DAD65C1C716DDF72F2CEE601CF5A0</key>
<string>http://gitlab.doc.gold.ac.uk/dclar011/maxi-js-emscripten.git</string>
</dict>
<key>IDESourceControlProjectPath</key>
<string>Maxi_Emscripten/Maxi_Emscripten.xcodeproj/project.xcworkspace</string>
<key>IDESourceControlProjectRelativeInstallPathDictionary</key>
<dict>
<key>2653DE3A5C3DAD65C1C716DDF72F2CEE601CF5A0</key>
<string>../../..</string>
</dict>
<key>IDESourceControlProjectURL</key>
<string>http://gitlab.doc.gold.ac.uk/dclar011/maxi-js-emscripten.git</string>
<key>IDESourceControlProjectVersion</key>
<integer>111</integer>
<key>IDESourceControlProjectWCCIdentifier</key>
<string>2653DE3A5C3DAD65C1C716DDF72F2CEE601CF5A0</string>
<key>IDESourceControlProjectWCConfigurations</key>
<array>
<dict>
<key>IDESourceControlRepositoryExtensionIdentifierKey</key>
<string>public.vcs.git</string>
<key>IDESourceControlWCCIdentifierKey</key>
<string>2653DE3A5C3DAD65C1C716DDF72F2CEE601CF5A0</string>
<key>IDESourceControlWCCName</key>
<string>maximilian</string>
</dict>
</array>
</dict>
</plist>
...@@ -80,14 +80,21 @@ EMSCRIPTEN_BINDINGS(my_module) { ...@@ -80,14 +80,21 @@ EMSCRIPTEN_BINDINGS(my_module) {
class_<maxiSample>("maxiSample") class_<maxiSample>("maxiSample")
.constructor<>() .constructor<>()
.function("setSample", &maxiSample::setSample) .function("setSample", &maxiSample::setSample)
.function("getSummary", &maxiSample::getSummary) // .function("getSummary", &maxiSample::getSummary)
.function("play", &maxiSample::play)
.function("playOnce", &maxiSample::playOnce)
.function("play", select_overload<double()>(&maxiSample::play))
.function("play", select_overload<double(double)>(&maxiSample::play))
.function("play", select_overload<double(double, double, double)>(&maxiSample::play))
// .function("play", select_overload<double(double, double, double, double&)>(&maxiSample::play))
.function("play4", &maxiSample::play4)
.function("trigger", &maxiSample::trigger) .function("trigger", &maxiSample::trigger)
.function("clear", &maxiSample::clear) .function("clear", &maxiSample::clear)
// .function("load", &maxiSample::load) // .function("load", &maxiSample::load)
// .function("read", &maxiSample::read, allow_raw_pointers()) // .function("read", &maxiSample::read, allow_raw_pointers())
// .function("play", &maxiSample::play)
; ;
} }
#endif #endif
...@@ -540,26 +540,18 @@ bool maxiSample::read() ...@@ -540,26 +540,18 @@ bool maxiSample::read()
} }
*/ */
//This plays back at the correct speed. Always loops.
//double maxiSample::play() {
// position++;
// if ((long) position == length) position=0;
// output = (double) temp[(long)position]/32767.0;
// return output;
//}
// my version for easier use with js // my version for easier use with js
double maxiSample::play() { double maxiSample::play() {
position++; position++;
if ((int) position == length) position=0; if ((int) position == length) position=0;
output = (double)(myDataDC.at((int)position)); output = (double)(tempDC.at((int)position));
return output; return output;
} }
void maxiSample::setSample(vector<double>& temp){ void maxiSample::setSample(vector<double>& temp){
myDataDC = temp; tempDC = temp;
length = myDataDC.size(); length = tempDC.size();
} }
...@@ -576,15 +568,15 @@ void maxiSample::setSample(vector<double>& temp){ ...@@ -576,15 +568,15 @@ void maxiSample::setSample(vector<double>& temp){
//} //}
//Same as above but takes a speed value specified as a ratio, with 1.0 as original speed //Same as above but takes a speed value specified as a ratio, with 1.0 as original speed
//double maxiSample::playOnce(double speed) { double maxiSample::playOnce(double speed) {
// position=position+((speed*chandiv)/(maxiSettings::sampleRate/mySampleRate)); position=position+((speed*chandiv)/(maxiSettings::sampleRate/mySampleRate));
// double remainder = position - (long) position; double remainder = position - (long) position;
// if ((long) position<length) if ((long) position<length)
// output = (double) ((1-remainder) * temp[1+ (long) position] + remainder * temp[2+(long) position])/32767;//linear interpolation output = (double) ((1-remainder) * tempDC.at(1+ (long) position) + remainder * tempDC.at(2+(long) position));//linear interpolation
// else else
// output=0; output=0;
// return(output); return(output);
//} }
//As above but looping //As above but looping
double maxiSample::play(double speed) { double maxiSample::play(double speed) {
...@@ -604,41 +596,42 @@ double maxiSample::play(double speed) { ...@@ -604,41 +596,42 @@ double maxiSample::play(double speed) {
} }
if (position+2<length) if (position+2<length)
{ {
b=position+2; b=position+2;
} }
else { else {
b=length-1; b=length-1;
} }
output = (double) ((1-remainder) * temp[a] + remainder * temp[b])/32767;//linear interpolation output = (double) ((1-remainder) * tempDC.at(a) + remainder * tempDC.at(b));//linear interpolation
} else { } else {
if ((long) position<0) position=length; if ((long) position<0) position=length;
remainder = position - floor(position); remainder = position - floor(position);
if (position-1>=0) { if (position-1>=0) {
a=position-1; a=position-1;
} }
else { else {
a=0; a=0;
} }
if (position-2>=0) { if (position-2>=0) {
b=position-2; b=position-2;
} }
else { else {
b=0; b=0;
} }
output = (double) ((-1-remainder) * temp[a] + remainder * temp[b])/32767;//linear interpolation output = (double) ((-1-remainder) * tempDC.at(a) + remainder * tempDC.at(b));//linear interpolation
} }
return(output); return(output);
} }
/*
//placeholder //placeholder
double maxiSample::play(double frequency, double start, double end) { double maxiSample::play(double frequency, double start, double end) {
return play(frequency, start, end, position); return play(frequency, start, end, position);
} }
//This allows you to say how often a second you want a specific chunk of audio to play //This allows you to say how often a second you want a specific chunk of audio to play
double maxiSample::play(double frequency, double start, double end, double &pos) { double maxiSample::play(double frequency, double start, double end, double& pos) {
double remainder; double remainder;
if (end>=length) end=length-1; if (end>=length) end=length-1;
long a,b; long a,b;
...@@ -666,8 +659,8 @@ double maxiSample::play(double frequency, double start, double end, double &pos) ...@@ -666,8 +659,8 @@ double maxiSample::play(double frequency, double start, double end, double &pos)
b=length-1; b=length-1;
} }
output = (double) ((1-remainder) * temp[a] + output = (double) ((1-remainder) * tempDC.at(a) +
remainder * temp[b])/32767;//linear interpolation remainder * tempDC.at(b));//linear interpolation
} else { } else {
frequency=frequency-(frequency+frequency); frequency=frequency-(frequency+frequency);
if ( pos <= start ) pos = end; if ( pos <= start ) pos = end;
...@@ -686,8 +679,8 @@ double maxiSample::play(double frequency, double start, double end, double &pos) ...@@ -686,8 +679,8 @@ double maxiSample::play(double frequency, double start, double end, double &pos)
else { else {
b=0; b=0;
} }
output = (double) ((-1-remainder) * temp[a] + output = (double) ((-1-remainder) * tempDC.at(a) +
remainder * temp[b])/32767;//linear interpolation remainder * tempDC.at(b));//linear interpolation
} }
...@@ -696,42 +689,46 @@ double maxiSample::play(double frequency, double start, double end, double &pos) ...@@ -696,42 +689,46 @@ double maxiSample::play(double frequency, double start, double end, double &pos)
//Same as above. better cubic inerpolation. Cobbled together from various (pd externals, yehar, other places). //Same as above. better cubic inerpolation. Cobbled together from various (pd externals, yehar, other places).
// needs fixing for online version
double maxiSample::play4(double frequency, double start, double end) { double maxiSample::play4(double frequency, double start, double end) {
double remainder; double remainder;
double a,b,c,d,a1,a2,a3; double a,b,c,d,a1,a2,a3;
if (frequency >0.) {
if (frequency > 0.) {
if (position<start) { if (position<start) {
position=start; position=start;
} }
if ( position >= end ) position = start; if ( position >= end ) position = start;
position += ((end-start)/(maxiSettings::sampleRate/(frequency*chandiv))); position += ((end-start)/(maxiSettings::sampleRate/(frequency*chandiv)));
remainder = position - floor(position); remainder = position - floor(position);
if (position>0) { if (position>0) {
a=temp[(int)(floor(position))-1]; a=tempDC.at((long)(floor(position))-1);
} else { } else {
a=temp[0]; a=tempDC.at(0);
} }
b=temp[(long) position]; b=tempDC.at((long) position);
if (position<end-2) { if (position<end-2) {
c=temp[(long) position+1]; c=tempDC.at((long) position+1);
} else { } else {
c=temp[0]; c=tempDC.at(0);
} }
if (position<end-3) { if (position<end-3) {
d=temp[(long) position+2]; d=tempDC.at((long) position+2);
} else { } else {
d=temp[0]; d=tempDC.at(0);
} }
a1 = 0.5f * (c - a); a1 = 0.5f * (c - a);
a2 = a - 2.5 * b + 2.f * c - 0.5f * d; a2 = a - 2.5 * b + 2.f * c - 0.5f * d;
a3 = 0.5f * (d - a) + 1.5f * (b - c); a3 = 0.5f * (d - a) + 1.5f * (b - c);
output = (double) (((a3 * remainder + a2) * remainder + a1) * remainder + b) / 32767; output = (double) (((a3 * remainder + a2) * remainder + a1) * remainder + b);
} else { } else {
frequency=frequency-(frequency+frequency); frequency=frequency-(frequency+frequency);
...@@ -739,38 +736,38 @@ double maxiSample::play4(double frequency, double start, double end) { ...@@ -739,38 +736,38 @@ double maxiSample::play4(double frequency, double start, double end) {
position -= ((end-start)/(maxiSettings::sampleRate/(frequency*chandiv))); position -= ((end-start)/(maxiSettings::sampleRate/(frequency*chandiv)));
remainder = position - floor(position); remainder = position - floor(position);
if (position>start && position < end-1) { if (position>start && position < end-1) {
a=temp[(long) position+1]; a=tempDC.at((long) position+1);
} else { } else {
a=temp[0]; a=tempDC.at(0);
} }
b=temp[(long) position]; b=tempDC.at((long) position);
if (position>start) { if (position>start) {
c=temp[(long) position-1]; c=tempDC.at((long) position-1);
} else { } else {
c=temp[0]; c=tempDC.at(0);
} }
if (position>start+1) { if (position>start+1) {
d=temp[(long) position-2]; d=tempDC.at((long) position-2);
} else { } else {
d=temp[0]; d=tempDC.at(0);
} }
a1 = 0.5f * (c - a); a1 = 0.5f * (c - a);
a2 = a - 2.5 * b + 2.f * c - 0.5f * d; a2 = a - 2.5 * b + 2.f * c - 0.5f * d;
a3 = 0.5f * (d - a) + 1.5f * (b - c); a3 = 0.5f * (d - a) + 1.5f * (b - c);
output = (double) (((a3 * remainder + a2) * -remainder + a1) * -remainder + b) / 32767; output = (double) (((a3 * remainder + a2) * -remainder + a1) * -remainder + b);
} }
return(output); return(output);
} }
/*
//You don't need to worry about this stuff. //You don't need to worry about this stuff.
double maxiSample::bufferPlay(unsigned char &bufferin,long length) { double maxiSample::bufferPlay(unsigned char &bufferin,long length) {
double remainder; double remainder;
......
...@@ -226,7 +226,7 @@ class maxiSample { ...@@ -226,7 +226,7 @@ class maxiSample {
private: private:
string myPath; string myPath;
int myChunkSize; int myChunkSize;
int mySubChunk1Size; int mySubChunk1Size;
int readChannel; int readChannel;
short myFormat; short myFormat;
int myByteRate; int myByteRate;
...@@ -250,7 +250,7 @@ public: ...@@ -250,7 +250,7 @@ public:
short* temp; short* temp;
// different vars for use with js // different vars for use with js
vector<double> myDataDC; vector<double> tempDC;
// get/set for the Path property // get/set for the Path property
~maxiSample() ~maxiSample()
...@@ -300,21 +300,25 @@ public: ...@@ -300,21 +300,25 @@ public:
void setSample(vector<double>& temp); void setSample(vector<double>& temp);
double play(); double play();
void clear(){myDataDC.clear();} void clear(){tempDC.clear();}
// double play(vector<double>& temp, int length); // tester
// double playOnce(); // double playOnce();
// //
// double playOnce(double speed); double playOnce(double speed);
// //
double play(double speed); double play(double speed);
double play(double frequency, double start, double end);
// previously:
// double play(double frequency, double start, double end, double &pos);
// why this no work with bind? :
// non-const lvalue reference to type 'double' cannot bind to a temporary of type 'double'
double play(double frequency, double start, double end, double& pos);
//
//
double play4(double frequency, double start, double end);
// //
// 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); // double bufferPlay(unsigned char &bufferin,long length);
// //
// double bufferPlay(unsigned char &bufferin,double speed,long length); // double bufferPlay(unsigned char &bufferin,double speed,long length);
......
This diff is collapsed.
...@@ -48,7 +48,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ...@@ -48,7 +48,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
var samplePlayer = new Module.maxiSample(); var samplePlayer = new Module.maxiSample();
var mySine = new Module.maxiOsc();
function setup(){ function setup(){
// loadSample("test.mp3"); // loadSample("test.mp3");
// console.log(samplePlayer.load("Macintosh HD/Users/Dan/Documents/Programming/Emscripten/emsdk_portable/emscripten/tag-1.34.11/tests/maximilian/web/maximilian_examples_web/beat2.wav", 1)); // console.log(samplePlayer.load("Macintosh HD/Users/Dan/Documents/Programming/Emscripten/emsdk_portable/emscripten/tag-1.34.11/tests/maximilian/web/maximilian_examples_web/beat2.wav", 1));
...@@ -58,7 +58,10 @@ loadSample("./beat2.wav", samplePlayer); ...@@ -58,7 +58,10 @@ loadSample("./beat2.wav", samplePlayer);
} }
function play(){ function play(){
output = samplePlayer.play(); // output = samplePlayer.play();//just play the file. Looping is default for all play functions.
// output=samplePlayer.play(0.69);//play the file with a speed setting. 1. is normal speed.
output=samplePlayer.play(0.5,0,44100);//linear interpolationplay with a frequency input, start point and end point. Useful for syncing.
// output=samplePlayer.play4(0.5,0,44099);//cubic interpolation play with a frequency input, start point and end point. Useful for syncing.
} }
......
...@@ -59,7 +59,7 @@ function setup(){ ...@@ -59,7 +59,7 @@ function setup(){
myEnvelopeData.push_back(1); myEnvelopeData.push_back(1);
myEnvelopeData.push_back(0); myEnvelopeData.push_back(0);
myEnvelopeData.push_back(0); myEnvelopeData.push_back(0);
myEnvelopeData.push_back(500); myEnvelopeData.push_back(10);
myEnvelope.amplitude=myEnvelopeData.get(0); //initialise the envelope myEnvelope.amplitude=myEnvelopeData.get(0); //initialise the envelope
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment