Commit 4dd91ce1 authored by Daniel Clarke's avatar Daniel Clarke

working with safari now

parent 2cafb6fe
......@@ -10,7 +10,7 @@ SOURCE=src/cpp/maxi_emscr.cpp
# destination .js file
OUTPUT=maxiLib/maxiLib.js
EXP_FUNCS=-s EXPORTED_FUNCTIONS="['_sumArray']"
# EXP_FUNCS=-s EXPORTED_FUNCTIONS="['_sumArray']"
# https://kripken.github.io/emscripten-site/docs/tools_reference/emcc.html
CFLAGS=-O2 $(EXP_FUNCS) -s DISABLE_EXCEPTION_CATCHING=0 -s ALLOW_MEMORY_GROWTH=1 --memory-init-file 0 --profiling
......
This diff is collapsed.
......@@ -63,14 +63,14 @@ public:
int sumArray(uintptr_t input, size_t len) {
const int* ptr = reinterpret_cast<int*>(input);
// double n = 0;
// for(int i = 0; i < len; i++){
// n+=ptr[i];
// }
// double n = 0;
// for(int i = 0; i < len; i++){
// n+=ptr[i];
// }
return ptr[0];
}
};
class maxiSettings {
public:
......@@ -127,7 +127,7 @@ class maxiEnvelope {
public:
// maxiEnvelope(){}
double line(int numberofsegments, std::vector<double>& segments);
// double line(int numberofsegments , double segments[1000]);
// double line(int numberofsegments , double segments[1000]);
void trigger(int index,double amp);
int valindex;
......@@ -194,7 +194,7 @@ class maxiMix {
// double two[2];
// double four[4];
// double eight[8];
public:
// double x;
// double y;
......@@ -204,7 +204,7 @@ public:
currently using non-pointer version for embind, need to sort out pointer stuff though
embind has no support for pointers to primitives!
*/
// double *stereo(double input,double two[2],double x);
// double *stereo(double input,double two[2],double x);
// double *quad(double input,double four[4], double x,double y);
// double *ambisonic(double input,double eight[8],double x,double y, double z);
......@@ -215,37 +215,37 @@ public:
};
//lagging with an exponential moving average
//a lower alpha value gives a slower lag
template <class T>
class maxiLagExp {
public:
//lagging with an exponential moving average
//a lower alpha value gives a slower lag
template <class T>
class maxiLagExp {
public:
T alpha, alphaReciprocal;
T val;
maxiLagExp() {
init(0.5, 0.0);
init(0.5, 0.0);
};
// haven't worked out how to do this (override) with smart_ptr_constructor?!
// 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;
alpha = initAlpha;
alphaReciprocal = 1.0 - alpha;
val = initVal;
}
// no need for inline if declared/defined in .h file
// no need for inline if declared/defined in .h file
void addSample(T newVal) {
val = (alpha * newVal) + (alphaReciprocal * val);
val = (alpha * newVal) + (alphaReciprocal * val);
}
T value() {
return val;
return val;
}
};
};
//lagging with an exponential moving average
......@@ -255,16 +255,16 @@ public:
//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;
......@@ -274,7 +274,7 @@ public:
// void addSample(double newVal) {
// val = (alpha * newVal) + (alphaReciprocal * val);
// }
//
//
// double value() {
// return val;
// }
......@@ -364,7 +364,7 @@ public:
double play();
void clear(){tempVec.clear();}
double playOnce();
double playOnce();
//
double playOnce(double speed);
//
......@@ -379,7 +379,7 @@ public:
//
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);
//
......
// might adopt some strange functions from Module?
// var maximJs = Module;
var maximTools = {};
// alternatively...
// probably better this way
// no inheritance of Module stuff...
......@@ -27,42 +29,14 @@ maximJs.maxiChorus = Module.maxiChorus;
maximJs.maxiEnvelopeFollower = Module.maxiEnvelopeFollower;
// alternative array method to avoid mixing vector terminology with arrays
// seems like bad practice though and needs some testing...
// how to stop people messing with vec and its effects on object
// ------------------------------------------------
// maxiArray - could extend Array object?
// cheaty array method to avoid mixing vector terminology with arrays
// but have to copy everything?!
// better to use GetArrayAsVectorDbl function ???
maximJs.maxiArray = function maxiArray(){
this.length = 0;
this.vec = new Module.VectorDouble();
this.set = function(arrayIn){
this.clear();
this.vec = GetArrayAsVectorDbl(arrayIn);
this.length = this.vec.size();
};
// set object properties to mimic array
this.SetSqBrackets = function(useSq){
for(var i = 0; i < this.length; i++){
if(useSq){
this[i] = this.vec.get(i);
} else{
delete this[i];
}
}
};
this.clear = function(useSq){
for(var i = 0; i < this.length; i++){
delete this[i];
}
Module.vectorTools.clearVectorDbl(this.vec);
this.length = 0;
};
this.push = function(num){
this.vec.push_back(num);
this.length++;
};
var vec = new Module.VectorDouble();
// this.update = function(){
// var lengthsMatch = this.length !== this.vec.size();
......@@ -83,6 +57,54 @@ this.push = function(num){
// };
};
maximJs.maxiArray.prototype.asVector = function(arrayIn){
return this.vec;
};
maximJs.maxiArray.prototype.asJsArray = function(arrayIn){
var arrayOut = [];
for(var i = 0; i < this.length; i++){
array.push(this.vec.get(i));
}
return arrayOut;
};
maximJs.maxiArray.prototype.set = function(arrayIn){
this.clear();
this.vec = GetArrayAsVectorDbl(arrayIn);
this.length = this.vec.size();
this.SetSqBrackets(true);
};
maximJs.maxiArray.prototype.push = function(num){
this.vec.push_back(num);
this[this.length] = num;
this.length++;
};
// set object properties to mimic array
// this doesn't seem particularly efficient or smart
maximJs.maxiArray.prototype.SetSqBrackets = function(useSq){
for(var i = 0; i < this.length; i++){
if(useSq){
this[i] = this.vec.get(i);
} else{
delete this[i];
}
}
};
maximJs.maxiArray.prototype.clear = function(useSq){
for(var i = 0; i < this.length; i++){
delete this[i];
}
Module.vectorTools.clearVectorDbl(this.vec);
this.length = 0;
};
function GetArrayAsVectorDbl(arrayIn){
var vecOut = new Module.VectorDouble();
for(var i = 0; i < arrayIn.length; i++){
......@@ -92,13 +114,15 @@ function GetArrayAsVectorDbl(arrayIn){
return vecOut;
}
// ------------------------------------------------
// would be nice to put this (all below) in function/class of some sort
// Temporary patch until all browsers support unprefixed context.
AudioContext = AudioContext || webkitAudioContext;
// AudioContext = AudioContext || webkitAudioContext;
// var context;
var context = new AudioContext();
// var context = new AudioContext();
var context = new webkitAudioContext() || new AudioContext();
// context = new (window.AudioContext || window.webkitAudioContext)();
var source;
......@@ -175,7 +199,7 @@ function process(event) {
}
else
{
for (var channel = 0; channel < numChannels; channel++) {
for (var channel = 0; channel < numChannels; channel++) {
event.outputBuffer.getChannelData(channel)[i] = output;
}
}
......@@ -205,22 +229,6 @@ function init() {
setup();
}
// function loadSampleBuffers(url){
// bufferLoader = new BufferLoader(
// context,
// [url],
// finishedLoading
// );
// bufferLoader.load();
// // var sources = [];
// // for(var i = 0; i < urls.length; i++){
// // var sourceI = context.createBufferSource();
// // sourceI.buffer = bufferList[i];
// // }
// }
function loadSample(url, samplePlayer) {
var data = [];
......@@ -269,11 +277,3 @@ function loadSample(url, samplePlayer) {
function transferComplete(evt) {
console.log("The transfer is complete.");
}
// function playSound(buffer) {
// var source = context.createBufferSource(); // creates a sound source
// source.buffer = buffer; // tell the source which sound to play
// source.connect(context.destination); // connect the source to the context's destination (the speakers)
// source.start(0); // play the source now
// // note: on older systems, may have to use deprecated noteOn(time);
// }
\ No newline at end of file
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