Commit eb0818dc authored by Dr-Dan's avatar Dr-Dan
Browse files

maxi_webAudio file now compiles into maxiLib.js. All examples updated to use...

maxi_webAudio file now compiles into maxiLib.js. All examples updated to use maximJs instead of Module
parent 19015c6f
...@@ -7,14 +7,14 @@ ...@@ -7,14 +7,14 @@
<key>IDESourceControlProjectIdentifier</key> <key>IDESourceControlProjectIdentifier</key>
<string>60ED41D8-5A86-4A08-934A-D5D543E71DB5</string> <string>60ED41D8-5A86-4A08-934A-D5D543E71DB5</string>
<key>IDESourceControlProjectName</key> <key>IDESourceControlProjectName</key>
<string>project</string> <string>Maxi_Emscripten</string>
<key>IDESourceControlProjectOriginsDictionary</key> <key>IDESourceControlProjectOriginsDictionary</key>
<dict> <dict>
<key>2653DE3A5C3DAD65C1C716DDF72F2CEE601CF5A0</key> <key>2653DE3A5C3DAD65C1C716DDF72F2CEE601CF5A0</key>
<string>http://gitlab.doc.gold.ac.uk/dclar011/maxi-js-emscripten.git</string> <string>http://gitlab.doc.gold.ac.uk/dclar011/maxi-js-emscripten.git</string>
</dict> </dict>
<key>IDESourceControlProjectPath</key> <key>IDESourceControlProjectPath</key>
<string>Maxi_Emscripten/Maxi_Emscripten.xcodeproj/project.xcworkspace</string> <string>Maxi_Emscripten/Maxi_Emscripten.xcodeproj</string>
<key>IDESourceControlProjectRelativeInstallPathDictionary</key> <key>IDESourceControlProjectRelativeInstallPathDictionary</key>
<dict> <dict>
<key>2653DE3A5C3DAD65C1C716DDF72F2CEE601CF5A0</key> <key>2653DE3A5C3DAD65C1C716DDF72F2CEE601CF5A0</key>
......
...@@ -26,12 +26,12 @@ EMSCRIPTEN_BINDINGS(my_module) { ...@@ -26,12 +26,12 @@ EMSCRIPTEN_BINDINGS(my_module) {
register_vector<int>("VectorInt"); register_vector<int>("VectorInt");
register_vector<double>("VectorDouble"); register_vector<double>("VectorDouble");
// register_vector<float>("VectorFloat"); // register_vector<float>("VectorFloat");
class_<vectorTools>("vectorTools") class_<vectorTools>("vectorTools")
.constructor<>() .constructor<>()
.class_function("clearVectorDbl", &vectorTools::clearVectorDbl) .class_function("clearVectorDbl", &vectorTools::clearVectorDbl)
; ;
class_<maxiSettings>("maxiSettings") class_<maxiSettings>("maxiSettings")
.constructor<>() .constructor<>()
.class_function("setup", &maxiSettings::setup) .class_function("setup", &maxiSettings::setup)
...@@ -40,12 +40,12 @@ EMSCRIPTEN_BINDINGS(my_module) { ...@@ -40,12 +40,12 @@ 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 Using a smart_ptr_constructor ensures lifetime management on the js side
by returning a smart_ptr when a constructor is used by returning a smart_ptr when a constructor is used
*/ */
// .smart_ptr_constructor("shared_ptr<maxiOsc>",&std::make_shared<maxiOsc>) .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))
...@@ -64,9 +64,9 @@ EMSCRIPTEN_BINDINGS(my_module) { ...@@ -64,9 +64,9 @@ 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>) .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)
...@@ -75,17 +75,17 @@ EMSCRIPTEN_BINDINGS(my_module) { ...@@ -75,17 +75,17 @@ 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>) .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))
; ;
// MAXI FILTER // MAXI FILTER
class_<maxiFilter>("maxiFilter") class_<maxiFilter>("maxiFilter")
.constructor<>() // .constructor<>()
// .smart_ptr_constructor("shared_ptr<maxiFilter>",&std::make_shared<maxiFilter>) .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)
...@@ -95,44 +95,61 @@ EMSCRIPTEN_BINDINGS(my_module) { ...@@ -95,44 +95,61 @@ 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>) .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())
; ;
// class_<TemplateClass<int>>("IntTemplateClass")
// .constructor<int, int, int>()
// .function("getMember", &TemplateClass<int>::getMember)
// ;
class_<maxiLagExp<double>>("maxiLagExp")
// .constructor<>()
// .constructor<double, double>()
.smart_ptr_constructor("shared_ptr<maxiLagExp<double>>",&std::make_shared<maxiLagExp<double>>, allow_raw_pointers()) // not sure how to override constructors with smart_ptr
// .smart_ptr_constructor("shared_ptr<maxiLagExp<double>>",&std::make_shared<maxiLagExp<double>>)
.function("init", &maxiLagExp<double>::init)
.function("addSample", &maxiLagExp<double>::addSample)
.function("value", &maxiLagExp<double>::value)
;
// MAXI SAMPLE // MAXI SAMPLE
class_<maxiSample>("maxiSample") class_<maxiSample>("maxiSample")
.constructor<>() // .constructor<>()
// .property("length", &maxiSample::getLength, &maxiSample::setLength) .smart_ptr_constructor("shared_ptr<maxiSample>",&std::make_shared<maxiSample>)
// makes some problems in browser? // .property("length", &maxiSample::getLength, &maxiSample::setLength) // no work???
// .smart_ptr_constructor("shared_ptr<maxiSample>",&std::make_shared<maxiSample>)
.function("getLength", &maxiSample::getLength) .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("isReady", &maxiSample::isReady)
.function("playOnce", select_overload<double()>(&maxiSample::playOnce)) .function("playOnce", select_overload<double()>(&maxiSample::playOnce))
.function("playOnce", select_overload<double(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("play4", &maxiSample::play4) .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())
; ;
// MAXI MAP // MAXI MAP
class_<maxiMap>("maxiMap") class_<maxiMap>("maxiMap")
.constructor<>() // .constructor<>()
.smart_ptr_constructor("shared_ptr<maxiMap>",&std::make_shared<maxiMap>)
.function("linlin", &maxiMap::linlin) .function("linlin", &maxiMap::linlin)
.function("linexp", &maxiMap::linexp) .function("linexp", &maxiMap::linexp)
.function("explin", &maxiMap::explin) .function("explin", &maxiMap::explin)
...@@ -141,27 +158,33 @@ EMSCRIPTEN_BINDINGS(my_module) { ...@@ -141,27 +158,33 @@ EMSCRIPTEN_BINDINGS(my_module) {
// MAXI DYN // MAXI DYN
class_<maxiDyn>("maxiDyn") class_<maxiDyn>("maxiDyn")
.constructor<>() // .constructor<>()
.smart_ptr_constructor("shared_ptr<maxiDyn>",&std::make_shared<maxiDyn>)
.function("gate", &maxiDyn::gate) .function("gate", &maxiDyn::gate)
.function("compressor", &maxiDyn::compressor) .function("compressor", &maxiDyn::compressor)
; ;
// MAXI ENV // MAXI ENV
class_<maxiEnv>("maxiEnv") class_<maxiEnv>("maxiEnv")
.constructor<>() // .constructor<>()
.smart_ptr_constructor("shared_ptr<maxiEnv>",&std::make_shared<maxiEnv>)
.function("ar", &maxiEnv::ar) .function("ar", &maxiEnv::ar)
.function("adsr", &maxiEnv::adsr) .function("adsr", &maxiEnv::adsr)
; ;
// CONVERT // CONVERT
class_<convert>("convert") class_<convert>("convert")
.constructor<>() // .constructor<>()
.smart_ptr_constructor("shared_ptr<convert>",&std::make_shared<convert>)
.function("mtof", &convert::mtof) .function("mtof", &convert::mtof)
// .class_function("mtof", &convert::mtof)
; ;
// MAXI DISTORTION // MAXI DISTORTION
class_<maxiDistortion>("maxiDistortion") class_<maxiDistortion>("maxiDistortion")
.constructor<>() // .constructor<>()
.smart_ptr_constructor("shared_ptr<maxiDistortion>",&std::make_shared<maxiDistortion>)
.function("fastAtan", &maxiDistortion::fastatan) .function("fastAtan", &maxiDistortion::fastatan)
.function("atanDist", &maxiDistortion::atanDist) .function("atanDist", &maxiDistortion::atanDist)
.function("fastAtanDist", &maxiDistortion::fastAtanDist) .function("fastAtanDist", &maxiDistortion::fastAtanDist)
...@@ -169,19 +192,22 @@ EMSCRIPTEN_BINDINGS(my_module) { ...@@ -169,19 +192,22 @@ EMSCRIPTEN_BINDINGS(my_module) {
// MAXI FLANGER // MAXI FLANGER
class_<maxiFlanger>("maxiFlanger") class_<maxiFlanger>("maxiFlanger")
.constructor<>() // .constructor<>()
.smart_ptr_constructor("shared_ptr<maxiFlanger>",&std::make_shared<maxiFlanger>)
.function("flange", &maxiFlanger::flange) .function("flange", &maxiFlanger::flange)
; ;
// MAXI CHORUS // MAXI CHORUS
class_<maxiChorus>("maxiChorus") class_<maxiChorus>("maxiChorus")
.constructor<>() // .constructor<>()
.smart_ptr_constructor("shared_ptr<maxiChorus>",&std::make_shared<maxiChorus>)
.function("chorus", &maxiChorus::chorus) .function("chorus", &maxiChorus::chorus)
; ;
// MAXI ENVELOPE FOLLOWER // MAXI ENVELOPE FOLLOWER
class_<maxiEnvelopeFollower>("maxiEnvelopeFollower") class_<maxiEnvelopeFollower>("maxiEnvelopeFollower")
.constructor<>() // .constructor<>()
.smart_ptr_constructor("shared_ptr<maxiEnvelopeFollower>",&std::make_shared<maxiEnvelopeFollower>)
.function("setAttack", &maxiEnvelopeFollower::setAttack) .function("setAttack", &maxiEnvelopeFollower::setAttack)
.function("setRelease", &maxiEnvelopeFollower::setRelease) .function("setRelease", &maxiEnvelopeFollower::setRelease)
.function("play", &maxiEnvelopeFollower::play) .function("play", &maxiEnvelopeFollower::play)
......
...@@ -1216,8 +1216,7 @@ double maxiEnv::adsr(double input, double attack, double decay, double sustain, ...@@ -1216,8 +1216,7 @@ double maxiEnv::adsr(double input, double attack, double decay, double sustain,
return output; return output;
} }
double convert::mtof(int midinote) { double convert::mtof(int midinote) {
return mtofarray[midinote]; return mtofarray[midinote];
} }
......
...@@ -190,11 +190,13 @@ public: ...@@ -190,11 +190,13 @@ public:
// double *quad(double input,double four[4], double x,double y); // double *quad(double input,double four[4], double x,double y);
// double *ambisonic(double input,double eight[8],double x,double y, double z); // double *ambisonic(double input,double eight[8],double x,double y, double z);
// as no variables are used, perhaps these should be static also?
void stereo(double input,vector<double>& two,double x); void stereo(double input,vector<double>& two,double x);
void quad(double input,vector<double>& four, double x,double y); void quad(double input,vector<double>& four, double x,double y);
void ambisonic(double input,vector<double>& eight, double x,double y, double z); void ambisonic(double input,vector<double>& eight, double x,double y, double z);
}; };
/*
//lagging with an exponential moving average //lagging with an exponential moving average
//a lower alpha value gives a slower lag //a lower alpha value gives a slower lag
template <class T> template <class T>
...@@ -206,29 +208,59 @@ public: ...@@ -206,29 +208,59 @@ public:
maxiLagExp() { maxiLagExp() {
init(0.5, 0.0); init(0.5, 0.0);
}; };
maxiLagExp(T initAlpha, T initVal) { // haven't worked out how to do this (override) with smart_ptr_constructor?!
init(initAlpha, initVal); // maxiLagExp(T initAlpha, T initVal) {
} // init(initAlpha, initVal);
// }
void init(T initAlpha, T initVal) { void init(T initAlpha, T initVal) {
alpha = initAlpha; alpha = initAlpha;
alphaReciprocal = 1.0 - alpha; alphaReciprocal = 1.0 - alpha;
val = initVal; val = initVal;
} }
// no need for inline if declared/defined in .h file
inline void addSample(T newVal) { void addSample(T newVal) {
val = (alpha * newVal) + (alphaReciprocal * val); val = (alpha * newVal) + (alphaReciprocal * val);
} }
inline T value() { T value() {
return val; return val;
} }
}; };
*/
//lagging with an exponential moving average
//a lower alpha value gives a slower lag
//template <class T>
//class maxiLagExp{
//public:
// double alpha, alphaReciprocal;
// double val;
//
// maxiLagExp() {
// init(0.5, 0.0);
// };
//
//
// maxiLagExp(double initAlpha, double initVal) {
// init(initAlpha, initVal);
// }
//
// void init(double initAlpha, double initVal) {
// alpha = initAlpha;
// alphaReciprocal = 1.0 - alpha;
// val = initVal;
// }
// // no need for inline if declared/defined in .h file
// void addSample(double newVal) {
// val = (alpha * newVal) + (alphaReciprocal * val);
// }
//
// double value() {
// return val;
// }
//};
class maxiSample { class maxiSample {
...@@ -273,8 +305,6 @@ public: ...@@ -273,8 +305,6 @@ 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 isReady();
...@@ -455,6 +485,7 @@ public: ...@@ -455,6 +485,7 @@ public:
class convert { class convert {
public: public:
double mtof(int midinote); double mtof(int midinote);
// static double mtof(int midinote); // should be static really
}; };
......
#!/bin/bash #!/bin/bash
# My example bash script
# echo "Hello World"
../../emcc -O1 -std=c++11 -g4 --bind -o web/maxiLib.js Maxi_Emscripten/Maxi_Emscripten/maxi_emscr.cpp # emscr compiler frontend:
# --preload-file "test.wav" # https://kripken.github.io/emscripten-site/docs/tools_reference/emcc.html
\ No newline at end of file ../../em++ -O2 -s DISABLE_EXCEPTION_CATCHING=0 --memory-init-file 0 --post-js "maxi_webAudio.js" --bind -o web/maxiLib.js Maxi_Emscripten/Maxi_Emscripten/maxi_emscr.cpp
// give Module more appropriate name?
var maximJs = Module;
// reassign to remove neew for Module - REMOVE THIS!
// var maxiSettings = Module.maxiSettings;
// var maxiOsc = Module.maxiOsc;
// var maxiEnvelope = Module.maxiEnvelope;
// var maxiDelayline = Module.maxiDelayline;
// var maxiFilter = Module.maxiFilter;
// var maxiMix = Module.maxiMix;
// var maxiLagExp = Module.maxiLagExp;
// var maxiSample = Module.maxiSample;
// var maxiMap = Module.maxiMap;
// var maxiDyn = Module.maxiDyn;
// var maxiEnv = Module.maxiEnv;
// var convert = Module.convert;
// var maxiDistortion = Module.maxiDistortion;
// var maxiFlanger = Module.maxiFlanger;
// var maxiChorus = Module.maxiChorus;
// var maxiEnvelopeFollower = Module.maxiEnvelopeFollower;
// Temporary patch until all browsers support unprefixed context. // Temporary patch until all browsers support unprefixed context.
...@@ -90,7 +113,6 @@ function process(event) { ...@@ -90,7 +113,6 @@ function process(event) {
} }
else else
{ {
for (var channel = 0; channel < numChannels; channel++) { for (var channel = 0; channel < numChannels; channel++) {
event.outputBuffer.getChannelData(channel)[i] = output; event.outputBuffer.getChannelData(channel)[i] = output;
} }
......
This diff is collapsed.
This diff is collapsed.
...@@ -40,29 +40,22 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ...@@ -40,29 +40,22 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<script src="../maxiLib.js"></script> <script src="../maxiLib.js"></script>
<script src="../maxi_webAudio.js"></script> <!-- <script src="../maxi_webAudio.js"></script> -->
<!-- Our javascript code --> <!-- Our javascript code -->
<script type="text/javascript"> <script type="text/javascript">
var myCounter = new Module.maxiOsc(); //these oscillators will help us count and play sound var myCounter = new maximJs.maxiOsc(); //these oscillators will help us count and play sound
var mySwitchableOsc = new Module.maxiOsc();// var mySwitchableOsc = new maximJs.maxiOsc();//
var CurrentCount;// var CurrentCount;//
var myOscOutput,myFilteredOutput;// var myOscOutput,myFilteredOutput;//
var myEnvelopeData = new Module.VectorDouble();//this data will be used to make an envelope. Value and time to value in ms. var myEnvelopeData = GetArrayAsVectorDbl([500,0,1000,500,0,500]); //this data will be used to make an envelope. Value and time to value in ms.
var myEnvelope = new Module.maxiEnvelope(); var myEnvelope = new maximJs.maxiEnvelope();
var myFilter = new Module.maxiFilter(); var myFilter = new maximJs.maxiFilter();
function setup(){ function setup(){
myEnvelopeData.push_back(500);
myEnvelopeData.push_back(0);
myEnvelopeData.push_back(1000);
myEnvelopeData.push_back(500);
myEnvelopeData.push_back(0);
myEnvelopeData.push_back(500);
myEnvelope.amplitude=myEnvelopeData.get(0); //initialise the envelope myEnvelope.amplitude=myEnvelopeData.get(0); //initialise the envelope
} }
......
...@@ -40,14 +40,13 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ...@@ -40,14 +40,13 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<script src="../maxiLib.js"></script> <script src="../maxiLib.js"></script>
<script src="../maxi_webAudio.js"></script>
<!-- Our javascript code --> <!-- Our javascript code -->
<script type="text/javascript"> <script type="text/javascript">
var myCounter = new Module.maxiOsc(); var myCounter = new maximJs.maxiOsc();
var mySwitchableOsc = new Module.maxiOsc(); var mySwitchableOsc = new maximJs.maxiOsc();
var myAutoPanner = new Module.maxiOsc(); var myAutoPanner = new maximJs.maxiOsc();
var currentCount; var currentCount;