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 @@
<key>IDESourceControlProjectIdentifier</key>
<string>60ED41D8-5A86-4A08-934A-D5D543E71DB5</string>
<key>IDESourceControlProjectName</key>
<string>project</string>
<string>Maxi_Emscripten</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>
<string>Maxi_Emscripten/Maxi_Emscripten.xcodeproj</string>
<key>IDESourceControlProjectRelativeInstallPathDictionary</key>
<dict>
<key>2653DE3A5C3DAD65C1C716DDF72F2CEE601CF5A0</key>
......
......@@ -26,12 +26,12 @@ EMSCRIPTEN_BINDINGS(my_module) {
register_vector<int>("VectorInt");
register_vector<double>("VectorDouble");
// register_vector<float>("VectorFloat");
class_<vectorTools>("vectorTools")
.constructor<>()
.class_function("clearVectorDbl", &vectorTools::clearVectorDbl)
;
class_<maxiSettings>("maxiSettings")
.constructor<>()
.class_function("setup", &maxiSettings::setup)
......@@ -40,12 +40,12 @@ EMSCRIPTEN_BINDINGS(my_module) {
// MAXI OSC
class_<maxiOsc>("maxiOsc")
.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>)
// .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("coswave", &maxiOsc::coswave)
.function("phasor", select_overload<double(double)>(&maxiOsc::phasor))
......@@ -64,9 +64,9 @@ EMSCRIPTEN_BINDINGS(my_module) {
// MAXI ENVELOPE
class_<maxiEnvelope>("maxiEnvelope")
.constructor<>()
// .smart_ptr_constructor("shared_ptr<maxiEnvelope>",&std::make_shared<maxiEnvelope>)
// .constructor<>()
.smart_ptr_constructor("shared_ptr<maxiEnvelope>",&std::make_shared<maxiEnvelope>)
.function("line", &maxiEnvelope::line)
// .function("line", &maxiEnvelope::line, allow_raw_pointers()) // if using array version
.function("trigger", &maxiEnvelope::trigger)
......@@ -75,17 +75,17 @@ EMSCRIPTEN_BINDINGS(my_module) {
// MAXI DELAYLINE
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, int)>(&maxiDelayline::dl))
;
// MAXI FILTER
class_<maxiFilter>("maxiFilter")
.constructor<>()
// .smart_ptr_constructor("shared_ptr<maxiFilter>",&std::make_shared<maxiFilter>)
// .constructor<>()
.smart_ptr_constructor("shared_ptr<maxiFilter>",&std::make_shared<maxiFilter>)
.function("lores", &maxiFilter::lores)
.function("hires", &maxiFilter::hires)
.function("bandpass", &maxiFilter::bandpass)
......@@ -95,44 +95,61 @@ EMSCRIPTEN_BINDINGS(my_module) {
// MAXI MIX
class_<maxiMix>("maxiMix")
.constructor<>()
// .smart_ptr_constructor("shared_ptr<maxiMix>",&std::make_shared<maxiMix>)
// .constructor<>()
.smart_ptr_constructor("shared_ptr<maxiMix>",&std::make_shared<maxiMix>)
.function("stereo", &maxiMix::stereo, allow_raw_pointers())
.function("quad", &maxiMix::quad, 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
class_<maxiSample>("maxiSample")
.constructor<>()
// .property("length", &maxiSample::getLength, &maxiSample::setLength)
// makes some problems in browser?
// .smart_ptr_constructor("shared_ptr<maxiSample>",&std::make_shared<maxiSample>)
// .constructor<>()
.smart_ptr_constructor("shared_ptr<maxiSample>",&std::make_shared<maxiSample>)
// .property("length", &maxiSample::getLength, &maxiSample::setLength) // no work???
.function("getLength", &maxiSample::getLength)
.function("setSample", &maxiSample::setSample)
// .function("getSummary", &maxiSample::getSummary)
// .function("getSummary", &maxiSample::getSummary)
.function("isReady", &maxiSample::isReady)
.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(double)>(&maxiSample::play))
.function("play", select_overload<double(double, double, double)>(&maxiSample::play))
.function("play4", &maxiSample::play4)
.function("trigger", &maxiSample::trigger)
.function("clear", &maxiSample::clear)
// .function("load", &maxiSample::load)
// .function("read", &maxiSample::read, allow_raw_pointers())
// .function("read", &maxiSample::read, allow_raw_pointers())
;
// MAXI MAP
class_<maxiMap>("maxiMap")
.constructor<>()
// .constructor<>()
.smart_ptr_constructor("shared_ptr<maxiMap>",&std::make_shared<maxiMap>)
.function("linlin", &maxiMap::linlin)
.function("linexp", &maxiMap::linexp)
.function("explin", &maxiMap::explin)
......@@ -141,27 +158,33 @@ EMSCRIPTEN_BINDINGS(my_module) {
// MAXI DYN
class_<maxiDyn>("maxiDyn")
.constructor<>()
// .constructor<>()
.smart_ptr_constructor("shared_ptr<maxiDyn>",&std::make_shared<maxiDyn>)
.function("gate", &maxiDyn::gate)
.function("compressor", &maxiDyn::compressor)
;
// MAXI ENV
class_<maxiEnv>("maxiEnv")
.constructor<>()
// .constructor<>()
.smart_ptr_constructor("shared_ptr<maxiEnv>",&std::make_shared<maxiEnv>)
.function("ar", &maxiEnv::ar)
.function("adsr", &maxiEnv::adsr)
;
// CONVERT
class_<convert>("convert")
.constructor<>()
// .constructor<>()
.smart_ptr_constructor("shared_ptr<convert>",&std::make_shared<convert>)
.function("mtof", &convert::mtof)
// .class_function("mtof", &convert::mtof)
;
// MAXI DISTORTION
class_<maxiDistortion>("maxiDistortion")
.constructor<>()
// .constructor<>()
.smart_ptr_constructor("shared_ptr<maxiDistortion>",&std::make_shared<maxiDistortion>)
.function("fastAtan", &maxiDistortion::fastatan)
.function("atanDist", &maxiDistortion::atanDist)
.function("fastAtanDist", &maxiDistortion::fastAtanDist)
......@@ -169,19 +192,22 @@ EMSCRIPTEN_BINDINGS(my_module) {
// MAXI FLANGER
class_<maxiFlanger>("maxiFlanger")
.constructor<>()
// .constructor<>()
.smart_ptr_constructor("shared_ptr<maxiFlanger>",&std::make_shared<maxiFlanger>)
.function("flange", &maxiFlanger::flange)
;
// MAXI CHORUS
class_<maxiChorus>("maxiChorus")
.constructor<>()
// .constructor<>()
.smart_ptr_constructor("shared_ptr<maxiChorus>",&std::make_shared<maxiChorus>)
.function("chorus", &maxiChorus::chorus)
;
// MAXI ENVELOPE FOLLOWER
class_<maxiEnvelopeFollower>("maxiEnvelopeFollower")
.constructor<>()
// .constructor<>()
.smart_ptr_constructor("shared_ptr<maxiEnvelopeFollower>",&std::make_shared<maxiEnvelopeFollower>)
.function("setAttack", &maxiEnvelopeFollower::setAttack)
.function("setRelease", &maxiEnvelopeFollower::setRelease)
.function("play", &maxiEnvelopeFollower::play)
......
......@@ -1216,8 +1216,7 @@ double maxiEnv::adsr(double input, double attack, double decay, double sustain,
return output;
}
double convert::mtof(int midinote) {
double convert::mtof(int midinote) {
return mtofarray[midinote];
}
......
......@@ -190,11 +190,13 @@ public:
// double *quad(double input,double four[4], double x,double y);
// 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 quad(double input,vector<double>& four, double x,double y);
void ambisonic(double input,vector<double>& eight, double x,double y, double z);
};
/*
//lagging with an exponential moving average
//a lower alpha value gives a slower lag
template <class T>
......@@ -206,29 +208,59 @@ public:
maxiLagExp() {
init(0.5, 0.0);
};
maxiLagExp(T initAlpha, T initVal) {
init(initAlpha, initVal);
}
// haven't worked out how to do this (override) with smart_ptr_constructor?!
// maxiLagExp(T initAlpha, T initVal) {
// init(initAlpha, initVal);
// }
void init(T initAlpha, T initVal) {
alpha = initAlpha;
alphaReciprocal = 1.0 - alpha;
val = initVal;
}
inline void addSample(T newVal) {
// no need for inline if declared/defined in .h file
void addSample(T newVal) {
val = (alpha * newVal) + (alphaReciprocal * val);
}
inline T value() {
T value() {
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 {
......@@ -273,8 +305,6 @@ public:
maxiSample():myData(NULL),temp(NULL),position(0), recordPosition(0), myChannels(1), mySampleRate(maxiSettings::sampleRate) {};
bool load(string fileName, int channel=0);
bool isReady();
......@@ -455,6 +485,7 @@ public:
class convert {
public:
double mtof(int midinote);
// static double mtof(int midinote); // should be static really
};
......
#!/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
# --preload-file "test.wav"
\ No newline at end of file
# emscr compiler frontend:
# https://kripken.github.io/emscripten-site/docs/tools_reference/emcc.html
../../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.
......@@ -90,7 +113,6 @@ function process(event) {
}
else
{
for (var channel = 0; channel < numChannels; channel++) {
event.outputBuffer.getChannelData(channel)[i] = output;
}
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -40,29 +40,22 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<script src="../maxiLib.js"></script>
<script src="../maxi_webAudio.js"></script>
<!-- <script src="../maxi_webAudio.js"></script> -->
<!-- Our javascript code -->
<script type="text/javascript">
var myCounter = new Module.maxiOsc(); //these oscillators will help us count and play sound
var mySwitchableOsc = new Module.maxiOsc();//
var myCounter = new maximJs.maxiOsc(); //these oscillators will help us count and play sound
var mySwitchableOsc = new maximJs.maxiOsc();//
var CurrentCount;//
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 myFilter = new Module.maxiFilter();
var myEnvelope = new maximJs.maxiEnvelope();
var myFilter = new maximJs.maxiFilter();
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
}
......
......@@ -40,14 +40,13 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<script src="../maxiLib.js"></script>
<script src="../maxi_webAudio.js"></script>
<!-- Our javascript code -->
<script type="text/javascript">
var myCounter = new Module.maxiOsc();
var mySwitchableOsc = new Module.maxiOsc();
var myAutoPanner = new Module.maxiOsc();
var myCounter = new maximJs.maxiOsc();
var mySwitchableOsc = new maximJs.maxiOsc();
var myAutoPanner = new maximJs.maxiOsc();
var currentCount;
var myOscOutput, myFilteredOutput, myPanPosition;
......@@ -58,9 +57,9 @@ var myStereoOutput = new Module.VectorDouble();// we need an output for each cha
var myEnvelopeData = new Module.VectorDouble();//this data will be used to make an envelope. Value and time to value in ms.
var myEnvelope = new Module.maxiEnvelope();
var myFilter = new Module.maxiFilter();
var myOutputs = new Module.maxiMix();
var myEnvelope = new maximJs.maxiEnvelope();
var myFilter = new maximJs.maxiFilter();
var myOutputs = new maximJs.maxiMix();
function setup(){
......
......@@ -40,17 +40,14 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<script src="../maxiLib.js"></script>
<script src="../maxi_webAudio.js"></script>
<!-- Our javascript code -->
<script type="text/javascript">
var samplePlayer = new maximJs.maxiSample();
var mySine = new maximJs.maxiOsc();
var samplePlayer = new Module.maxiSample();
var mySine = new Module.maxiOsc();
function setup(){
// 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));
loadSample("./beat2.wav", samplePlayer);
......
<!--
Copyright 2010, Google Inc.
All rights reserved.
......@@ -40,7 +39,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<script src="../maxiLib.js"></script>
<script src="../maxi_webAudio.js"></script>
<!-- <script src="../maxi_webAudio.js"></script> -->
<!-- Our javascript code -->
<script type="text/javascript">
......@@ -59,26 +58,26 @@ var env2 = GetArrayAsVectorDbl([10000,0,9000,5,0,5]);
var melody = [600,0,0,650,0,0,400,0,0,425,0,300,0,315,0,315, 0];//the melody data
var rhythm1 = [1,0,0,1,0,0,1,0,0,1,0,0,1,0,1,0];//another way of doing a rhythm
var a = new Module.maxiOsc();
var c = new Module.maxiOsc();
var d = new Module.maxiOsc();
var e = new Module.maxiOsc();
var g = new Module.maxiOsc();
var h = new Module.maxiOsc();
var i = new Module.maxiOsc();
var j = new Module.maxiOsc();
var squarewave = new Module.maxiOsc();//some oscillators maxiOsc...
var b = new Module.maxiEnvelope();
var f = new Module.maxiEnvelope();//two envelopers
var delay = new Module.maxiDelayline();//a delay line
var myfilter = new Module.maxiFilter();
var antia = new Module.maxiFilter();// a FAT filter
var mymix = new Module.maxiMix();
var bobbins = new Module.maxiMix();//some panning busses
var beats = new Module.maxiSample();
var a = new maximJs.maxiOsc();
var c = new maximJs.maxiOsc();
var d = new maximJs.maxiOsc();
var e = new maximJs.maxiOsc();
var g = new maximJs.maxiOsc();
var h = new maximJs.maxiOsc();
var i = new maximJs.maxiOsc();
var j = new maximJs.maxiOsc();
var squarewave = new maximJs.maxiOsc();//some oscillators maxiOsc...
var b = new maximJs.maxiEnvelope();
var f = new maximJs.maxiEnvelope();//two envelopers
var delay = new maximJs.maxiDelayline();//a delay line
var myfilter = new maximJs.maxiFilter();
var antia = new maximJs.maxiFilter();// a FAT filter
var mymix = new maximJs.maxiMix();
var bobbins = new maximJs.maxiMix();//some panning busses
var beats = new maximJs.maxiSample();
function setup() {//some inits
outputs.push_back(0);
......
......@@ -40,21 +40,21 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<script src="../maxiLib.js"></script>
<script src="../maxi_webAudio.js"></script>
<!-- <script src="../maxi_webAudio.js"></script> -->
<!-- Our javascript code -->
<script type="text/javascript">
//This shows how to use maximilian to build a monophonic synth
//These are the synthesiser bits
var VCO1 = new Module.maxiOsc();
var VCO2 = new Module.maxiOsc();
var LFO1 = new Module.maxiOsc();
var LFO2 = new Module.maxiOsc();
var VCO1 = new maximJs.maxiOsc();
var VCO2 = new maximJs.maxiOsc();
var LFO1 = new maximJs.maxiOsc();
var LFO2 = new maximJs.maxiOsc();
var VCF = new Module.maxiFilter();
var VCF = new maximJs.maxiFilter();
var ADSR = new Module.maxiEnvelope();
var ADSR = new maximJs.maxiEnvelope();
//These are the control values for the envelope
......@@ -63,7 +63,7 @@ var adsrEnv = GetArrayAsVectorDbl(adsrEnvArray);
//This is a bunch of control signals so that we can hear something
var timer = new Module.maxiOsc();//this is the metronome
var timer = new maximJs.maxiOsc();//this is the metronome
var currentCount,lastCount;//these values are used to check if we have a new beat this sample
//and these are some variables we can use to pass stuff around
......
......@@ -40,7 +40,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<script src="../maxiLib.js"></script>
<script src="../maxi_webAudio.js"></script>
<!-- <script src="../maxi_webAudio.js"></script> -->
<!-- Our javascript code -->
<script type="text/javascript">
......@@ -56,14 +56,14 @@ var ADSR = [];
var VCO1out = [], VCO2out = [], LFO1out = [],LFO2out = [], VCFout = [], ADSRout = [];
for(var i = 0; i < VCO_ArraySize; i++){
VCO1.push(new Module.maxiOsc());
VCO2.push(new Module.maxiOsc());
LFO1.push(new Module.maxiOsc());
LFO2.push(new Module.maxiOsc());
VCO1.push(new maximJs.maxiOsc());
VCO2.push(new maximJs.maxiOsc());
LFO1.push(new maximJs.maxiOsc());
LFO2.push(new maximJs.maxiOsc());