Commit 19015c6f authored by Dr-Dan's avatar Dr-Dan
Browse files

all examples done

parent fc26f9bb
...@@ -14,15 +14,13 @@ ...@@ -14,15 +14,13 @@
startingColumnNumber = "9223372036854775807" startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807"
startingLineNumber = "415" startingLineNumber = "415"
endingLineNumber = "415" endingLineNumber = "415">
landmarkName = "maxiMix::stereo(double input,vector<double>& two,double x)"
landmarkType = "5">
</BreakpointContent> </BreakpointContent>
</BreakpointProxy> </BreakpointProxy>
<BreakpointProxy <BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint"> BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent <BreakpointContent
shouldBeEnabled = "Yes" shouldBeEnabled = "No"
ignoreCount = "0" ignoreCount = "0"
continueAfterRunningActions = "No" continueAfterRunningActions = "No"
filePath = "Maxi_Emscripten/maxi_embind.h" filePath = "Maxi_Emscripten/maxi_embind.h"
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
#define Maxi_Emscripten_maxi_embind_h #define Maxi_Emscripten_maxi_embind_h
#include <emscripten.h> #include <emscripten.h>
#include <bind.h> #include <emscripten/bind.h>
class vectorTools { class vectorTools {
public: public:
...@@ -41,6 +41,11 @@ EMSCRIPTEN_BINDINGS(my_module) { ...@@ -41,6 +41,11 @@ EMSCRIPTEN_BINDINGS(my_module) {
// MAXI OSC // MAXI OSC
class_<maxiOsc>("maxiOsc") class_<maxiOsc>("maxiOsc")
.constructor<>() .constructor<>()
/*
Using a smart_ptr_constructor ensures lifetime management on the js side
by returning a smart_ptr when a constructor is used
*/
// .smart_ptr_constructor("shared_ptr<maxiOsc>",&std::make_shared<maxiOsc>)
.function("sinewave", &maxiOsc::sinewave) .function("sinewave", &maxiOsc::sinewave)
.function("coswave", &maxiOsc::coswave) .function("coswave", &maxiOsc::coswave)
.function("phasor", select_overload<double(double)>(&maxiOsc::phasor)) .function("phasor", select_overload<double(double)>(&maxiOsc::phasor))
...@@ -60,6 +65,8 @@ EMSCRIPTEN_BINDINGS(my_module) { ...@@ -60,6 +65,8 @@ EMSCRIPTEN_BINDINGS(my_module) {
// MAXI ENVELOPE // MAXI ENVELOPE
class_<maxiEnvelope>("maxiEnvelope") class_<maxiEnvelope>("maxiEnvelope")
.constructor<>() .constructor<>()
// .smart_ptr_constructor("shared_ptr<maxiEnvelope>",&std::make_shared<maxiEnvelope>)
.function("line", &maxiEnvelope::line) .function("line", &maxiEnvelope::line)
// .function("line", &maxiEnvelope::line, allow_raw_pointers()) // if using array version // .function("line", &maxiEnvelope::line, allow_raw_pointers()) // if using array version
.function("trigger", &maxiEnvelope::trigger) .function("trigger", &maxiEnvelope::trigger)
...@@ -68,7 +75,8 @@ EMSCRIPTEN_BINDINGS(my_module) { ...@@ -68,7 +75,8 @@ EMSCRIPTEN_BINDINGS(my_module) {
// MAXI DELAYLINE // MAXI DELAYLINE
class_<maxiDelayline>("maxiDelayline") class_<maxiDelayline>("maxiDelayline")
.constructor<>() // .constructor<>()
.smart_ptr_constructor("shared_ptr<maxiDelayline>",&std::make_shared<maxiDelayline>)
.function("dl", select_overload<double(double, int, double)>(&maxiDelayline::dl)) .function("dl", select_overload<double(double, int, double)>(&maxiDelayline::dl))
.function("dl", select_overload<double(double, int, double, int)>(&maxiDelayline::dl)) .function("dl", select_overload<double(double, int, double, int)>(&maxiDelayline::dl))
; ;
...@@ -77,6 +85,7 @@ EMSCRIPTEN_BINDINGS(my_module) { ...@@ -77,6 +85,7 @@ EMSCRIPTEN_BINDINGS(my_module) {
// MAXI FILTER // MAXI FILTER
class_<maxiFilter>("maxiFilter") class_<maxiFilter>("maxiFilter")
.constructor<>() .constructor<>()
// .smart_ptr_constructor("shared_ptr<maxiFilter>",&std::make_shared<maxiFilter>)
.function("lores", &maxiFilter::lores) .function("lores", &maxiFilter::lores)
.function("hires", &maxiFilter::hires) .function("hires", &maxiFilter::hires)
.function("bandpass", &maxiFilter::bandpass) .function("bandpass", &maxiFilter::bandpass)
...@@ -87,6 +96,7 @@ EMSCRIPTEN_BINDINGS(my_module) { ...@@ -87,6 +96,7 @@ EMSCRIPTEN_BINDINGS(my_module) {
// MAXI MIX // MAXI MIX
class_<maxiMix>("maxiMix") class_<maxiMix>("maxiMix")
.constructor<>() .constructor<>()
// .smart_ptr_constructor("shared_ptr<maxiMix>",&std::make_shared<maxiMix>)
.function("stereo", &maxiMix::stereo, allow_raw_pointers()) .function("stereo", &maxiMix::stereo, allow_raw_pointers())
.function("quad", &maxiMix::quad, allow_raw_pointers()) .function("quad", &maxiMix::quad, allow_raw_pointers())
.function("ambisonic", &maxiMix::ambisonic, allow_raw_pointers()) .function("ambisonic", &maxiMix::ambisonic, allow_raw_pointers())
...@@ -95,14 +105,21 @@ EMSCRIPTEN_BINDINGS(my_module) { ...@@ -95,14 +105,21 @@ EMSCRIPTEN_BINDINGS(my_module) {
// MAXI SAMPLE // MAXI SAMPLE
class_<maxiSample>("maxiSample") class_<maxiSample>("maxiSample")
.constructor<>() .constructor<>()
// .property("length", &maxiSample::getLength, &maxiSample::setLength)
// makes some problems in browser?
// .smart_ptr_constructor("shared_ptr<maxiSample>",&std::make_shared<maxiSample>)
.function("getLength", &maxiSample::getLength)
.function("setSample", &maxiSample::setSample) .function("setSample", &maxiSample::setSample)
// .function("getSummary", &maxiSample::getSummary) // .function("getSummary", &maxiSample::getSummary)
.function("isReady", &maxiSample::isReady)
.function("playOnce", &maxiSample::playOnce)
.function("playOnce", select_overload<double()>(&maxiSample::playOnce))
.function("playOnce", select_overload<double(double)>(&maxiSample::playOnce))
.function("play", select_overload<double()>(&maxiSample::play)) .function("play", select_overload<double()>(&maxiSample::play))
.function("play", select_overload<double(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)>(&maxiSample::play))
// .function("play", select_overload<double(double, double, double, double&)>(&maxiSample::play))
.function("play4", &maxiSample::play4) .function("play4", &maxiSample::play4)
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include "maxi_emscr.h" #include "maxi_emscr.h"
#include "maxi_embind.h" #include "maxi_embind.h"
#include "big_arrays.h" #include "big_arrays.h"
#include "emscripten/val.h"
//#include "math.h" //#include "math.h"
...@@ -111,7 +112,6 @@ double maxiOsc::sinebuf4(double frequency) { ...@@ -111,7 +112,6 @@ double maxiOsc::sinebuf4(double frequency) {
b=sineBuffer[(long) phase]; b=sineBuffer[(long) phase];
c=sineBuffer[(long) phase+1]; c=sineBuffer[(long) phase+1];
d=sineBuffer[(long) phase+2]; d=sineBuffer[(long) phase+2];
} }
a1 = 0.5f * (c - a); a1 = 0.5f * (c - a);
...@@ -186,7 +186,6 @@ double maxiOsc::saw(double frequency) { ...@@ -186,7 +186,6 @@ double maxiOsc::saw(double frequency) {
if ( phase >= 1.0 ) phase -= 2.0; if ( phase >= 1.0 ) phase -= 2.0;
phase += (1./(maxiSettings::sampleRate/(frequency))); phase += (1./(maxiSettings::sampleRate/(frequency)));
return(output); return(output);
} }
double maxiOsc::sawn(double frequency) { double maxiOsc::sawn(double frequency) {
...@@ -223,7 +222,6 @@ double maxiOsc::triangle(double frequency) { ...@@ -223,7 +222,6 @@ double maxiOsc::triangle(double frequency) {
output =((1.0-phase) - 0.25) * 4; output =((1.0-phase) - 0.25) * 4;
} }
return(output); return(output);
} }
// -------------------------------------------------------------------------------- // --------------------------------------------------------------------------------
...@@ -255,7 +253,7 @@ double maxiEnvelope::line(int numberofsegments, std::vector<double>& segments) ...@@ -255,7 +253,7 @@ double maxiEnvelope::line(int numberofsegments, std::vector<double>& segments)
output=0; output=0;
} }
return(output); return output;
} }
//and this //and this
...@@ -264,7 +262,6 @@ void maxiEnvelope::trigger(int index, double amp) { ...@@ -264,7 +262,6 @@ void maxiEnvelope::trigger(int index, double amp) {
valindex=index; valindex=index;
SetAmplitude(amp); SetAmplitude(amp);
// amplitude=amp; // amplitude=amp;
} }
// -------------------------------------------------------------------------------- // --------------------------------------------------------------------------------
...@@ -294,7 +291,6 @@ double maxiDelayline::dl(double input, int size, double feedback, int position) ...@@ -294,7 +291,6 @@ double maxiDelayline::dl(double input, int size, double feedback, int position)
memory[phase]=(memory[phase]*feedback)+(input*feedback)*chandiv; memory[phase]=(memory[phase]*feedback)+(input*feedback)*chandiv;
phase+=1; phase+=1;
return(output); return(output);
} }
...@@ -362,10 +358,6 @@ double maxiFilter::bandpass(double input,double cutoff1, double resonance) { ...@@ -362,10 +358,6 @@ double maxiFilter::bandpass(double input,double cutoff1, double resonance) {
return(output); return(output);
} }
// -------------------------------------------------------------------------------- // --------------------------------------------------------------------------------
// MAXI MIX // MAXI MIX
/* /*
...@@ -493,6 +485,7 @@ bool maxiSample::loadOgg(string fileName, int channel) { ...@@ -493,6 +485,7 @@ bool maxiSample::loadOgg(string fileName, int channel) {
return 0; return 0;
} }
*/ */
//This sets the playback position to the start of a sample //This sets the playback position to the start of a sample
void maxiSample::trigger() { void maxiSample::trigger() {
position = 0; position = 0;
...@@ -574,40 +567,46 @@ bool maxiSample::read() ...@@ -574,40 +567,46 @@ bool maxiSample::read()
}else { }else {
// cout << "ERROR: Could not load sample: " <<myPath << endl; //This line seems to be hated by windows // cout << "ERROR: Could not load sample: " <<myPath << endl; //This line seems to be hated by windows
printf("ERROR: Could not load sample."); printf("ERROR: Could not load sample.");
} }
return result; // this should probably be something more descriptive return result; // this should probably be something more descriptive
} }
bool maxiSample::isReady(){
if(length > 0){
return true;
}
return false;
}
void maxiSample::setSample(vector<double>& temp){
tempVec = temp;
length = temp.size();
}
// 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 >= tempVec.size()) position=0;
// if((int)position < tempVec.size()){
output = (double)(tempVec.at((int)position)); output = (double)(tempVec.at((int)position));
// }
return output; return output;
} }
void maxiSample::setSample(vector<double>& temp){
tempVec = temp;
length = tempVec.size();
}
//This plays back at the correct speed. Only plays once. To retrigger, you have to manually reset the position //This plays back at the correct speed. Only plays once. To retrigger, you have to manually reset the position
//double maxiSample::playOnce() { double maxiSample::playOnce() {
// position++; position++;
// if ((long) position<length) if ((long) position<length)
// output = (double) temp[(long)position]/32767.0; output = (double) tempVec.at((long)position);
// else { else {
// output=0; output=0;
// } }
// return output; return output;
//
//} }
//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) {
...@@ -744,12 +743,12 @@ double maxiSample::play4(double frequency, double start, double end) { ...@@ -744,12 +743,12 @@ double maxiSample::play4(double frequency, double start, double end) {
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) { // this may not always work
a=tempVec.at((long)(floor(position))-1); if (position>=1) {
a=tempVec.at((long)(floor(position))-1); // what if larger than 1 and floor of position is 0?
} else { } else {
a=tempVec.at(0); a=tempVec.at(0);
} }
b=tempVec.at((long) position); b=tempVec.at((long) position);
...@@ -758,8 +757,8 @@ double maxiSample::play4(double frequency, double start, double end) { ...@@ -758,8 +757,8 @@ double maxiSample::play4(double frequency, double start, double end) {
} else { } else {
c=tempVec.at(0); c=tempVec.at(0);
} }
if (position<end-3) { if (position<end-3) {
d=tempVec.at((long) position+2); d=tempVec.at((long) position+2);
...@@ -779,20 +778,17 @@ double maxiSample::play4(double frequency, double start, double end) { ...@@ -779,20 +778,17 @@ double maxiSample::play4(double frequency, double start, double end) {
remainder = position - floor(position); remainder = position - floor(position);
if (position>start && position < end-1) { if (position>start && position < end-1) {
a=tempVec.at((long) position+1); a=tempVec.at((long) position+1);
} else { } else {
a=tempVec.at(0); a=tempVec.at(0);
} }
b=tempVec.at((long) position); b=tempVec.at((long) position);
if (position>start) { if (position>start) {
c=tempVec.at((long) position-1); c=tempVec.at((long) position-1);
} else { } else {
c=tempVec.at(0); c=tempVec.at(0);
} }
if (position>start+1) { if (position>start+1) {
d=tempVec.at((long) position-2); d=tempVec.at((long) position-2);
...@@ -809,7 +805,7 @@ double maxiSample::play4(double frequency, double start, double end) { ...@@ -809,7 +805,7 @@ double maxiSample::play4(double frequency, double start, double end) {
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;
...@@ -817,10 +813,11 @@ double maxiSample::bufferPlay(unsigned char &bufferin,long length) { ...@@ -817,10 +813,11 @@ double maxiSample::bufferPlay(unsigned char &bufferin,long length) {
position=(position+1); position=(position+1);
remainder = position - (long) position; remainder = position - (long) position;
if ((long) position>length) position=0; if ((long) position>length) position=0;
output = (double) ((1-remainder) * buffer[1+ (long) position] + remainder * buffer[2+(long) position])/32767;//linear interpolation output = (double) ((1-remainder) * buffer[1+ (long) position] + remainder * buffer[2+(long) position]);//linear interpolation
return(output); return(output);
} }
/*
double maxiSample::bufferPlay(unsigned char &bufferin,double speed,long length) { double maxiSample::bufferPlay(unsigned char &bufferin,double speed,long length) {
double remainder; double remainder;
long a,b; long a,b;
...@@ -999,25 +996,40 @@ double maxiSample::bufferPlay4(unsigned char &bufferin,double frequency, double ...@@ -999,25 +996,40 @@ double maxiSample::bufferPlay4(unsigned char &bufferin,double frequency, double
return(output); return(output);
} }
// doesn't return length ???
void maxiSample::getLength() { void maxiSample::getLength() {
length=myDataSize*0.5; length=myDataSize*0.5;
} }
void maxiSample::setLength(unsigned long numSamples) { void maxiSample::setLength(unsigned long numSamples) {
cout << "Length: " << numSamples << endl; // cout << "Length: " << numSamples << endl; // why do this ?
short *newData = (short*) malloc(sizeof(short) * numSamples); short *newData = (short*) malloc(sizeof(short) * numSamples);
if (NULL!=temp) { if (NULL!=temp) {
unsigned long copyLength = min((unsigned long)length, numSamples); unsigned long copyLength = min((unsigned long)length, numSamples);
memcpy(newData, temp, sizeof(short) * copyLength); memcpy(newData, temp, sizeof(short) * copyLength);
} }
temp = newData; temp = newData;
myDataSize = numSamples * 2; myDataSize = (int)numSamples * 2; // added int conversion
length=numSamples; length=numSamples;
position=0; position=0;
recordPosition=0; recordPosition=0;
} }
*/
long maxiSample::getLength(){
return length;
}
void maxiSample::setLength(unsigned long numSamples){
myDataSize = (int)numSamples * 2; // added int conversion. does this work with vector data size?
tempVec.resize(numSamples); // is this right?
length = numSamples;
position=0;
recordPosition=0;
}
/*
void maxiSample::clear() { void maxiSample::clear() {
memset(myData, 0, myDataSize); memset(myData, 0, myDataSize);
} }
......
...@@ -177,10 +177,7 @@ class maxiMix { ...@@ -177,10 +177,7 @@ class maxiMix {
// double two[2]; // double two[2];
// double four[4]; // double four[4];
// double eight[8]; // double eight[8];
// vector<double> two;
// vector<double> four[4];
// vector<double> eight[8];
public: public:
// double x; // double x;
// double y; // double y;
...@@ -255,7 +252,8 @@ public: ...@@ -255,7 +252,8 @@ public:
short myChannels; short myChannels;
int mySampleRate; int mySampleRate;
long length; long length;
void getLength(); // void getLength(); // ???
long getLength();
void setLength(unsigned long numSamples); void setLength(unsigned long numSamples);
...@@ -275,8 +273,12 @@ public: ...@@ -275,8 +273,12 @@ public:
maxiSample():myData(NULL),temp(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 load(string fileName, int channel=0);
bool isReady();
// bool loadOgg(string filename,int channel=0); // bool loadOgg(string filename,int channel=0);
// //
void trigger(); void trigger();
...@@ -314,7 +316,7 @@ public: ...@@ -314,7 +316,7 @@ public:
double play(); double play();
void clear(){tempVec.clear();} void clear(){tempVec.clear();}
// double playOnce(); double playOnce();
// //
double playOnce(double speed); double playOnce(double speed);
// //
...@@ -329,7 +331,7 @@ public: ...@@ -329,7 +331,7 @@ public:
// //
double play4(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);
// //
......
...@@ -2,5 +2,5 @@ ...@@ -2,5 +2,5 @@
# My example bash script # My example bash script
# echo "Hello World" # echo "Hello World"
../../emcc --bind -o web/maxiLib.js Maxi_Emscripten/Maxi_Emscripten/maxi_emscr.cpp ../../emcc -O1 -std=c++11 -g4 --bind -o web/maxiLib.js Maxi_Emscripten/Maxi_Emscripten/maxi_emscr.cpp
# --preload-file "test.wav" # --preload-file "test.wav"
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
...@@ -23,7 +23,7 @@ window.onload = init; ...