Commit 0160af9d authored by Dr-Dan's avatar Dr-Dan
Browse files

changed js to work with different numbers of channels. mixing example done;...

changed js to work with different numbers of channels. mixing example done; some cheating on c++ maxiMix stuff
parent 2090a747
...@@ -2,4 +2,38 @@ ...@@ -2,4 +2,38 @@
<Bucket <Bucket
type = "1" type = "1"
version = "2.0"> version = "2.0">
<Breakpoints>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Maxi_Emscripten/maxi_emscr.cpp"
timestampString = "468433055.819784"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "415"
endingLineNumber = "415"
landmarkName = "maxiMix::stereo(double input,vector&lt;double&gt;&amp; two,double x)"
landmarkType = "5">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Maxi_Emscripten/maxi_embind.h"
timestampString = "468536366.681087"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "97"
endingLineNumber = "97"
landmarkName = "EMSCRIPTEN_BINDINGS(my_module)"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket> </Bucket>
...@@ -9,7 +9,8 @@ ...@@ -9,7 +9,8 @@
#ifndef Maxi_Emscripten_maxi_embind_h #ifndef Maxi_Emscripten_maxi_embind_h
#define Maxi_Emscripten_maxi_embind_h #define Maxi_Emscripten_maxi_embind_h
#include <emscripten/bind.h> #include <emscripten.h>
#include <bind.h>
class vectorTools { class vectorTools {
public: public:
...@@ -37,6 +38,7 @@ EMSCRIPTEN_BINDINGS(my_module) { ...@@ -37,6 +38,7 @@ EMSCRIPTEN_BINDINGS(my_module) {
; ;
// MAXI OSC
class_<maxiOsc>("maxiOsc") class_<maxiOsc>("maxiOsc")
.constructor<>() .constructor<>()
.function("sinewave", &maxiOsc::sinewave) .function("sinewave", &maxiOsc::sinewave)
...@@ -55,19 +57,24 @@ EMSCRIPTEN_BINDINGS(my_module) { ...@@ -55,19 +57,24 @@ EMSCRIPTEN_BINDINGS(my_module) {
.function("phaseReset", &maxiOsc::phaseReset) .function("phaseReset", &maxiOsc::phaseReset)
; ;
// MAXI ENVELOPE
class_<maxiEnvelope>("maxiEnvelope") class_<maxiEnvelope>("maxiEnvelope")
.constructor<>() .constructor<>()
.function("line", &maxiEnvelope::line) .function("line", &maxiEnvelope::line)
// .function("line", &maxiEnvelope::line, allow_raw_pointers()) // if using array version
.function("trigger", &maxiEnvelope::trigger) .function("trigger", &maxiEnvelope::trigger)
.property("amplitude", &maxiEnvelope::GetAmplitude, &maxiEnvelope::SetAmplitude) .property("amplitude", &maxiEnvelope::GetAmplitude, &maxiEnvelope::SetAmplitude)
; ;
// class_<maxiDelayline>("maxiDelayline") // MAXI DELAYLINE
// .constructor<>() class_<maxiDelayline>("maxiDelayline")
// .function("dl", select_overload<double(double, int, double)>(&maxiDelayline::dl)) .constructor<>()
// .function("dl", select_overload<double(double, int, double, int)>(&maxiDelayline::dl)) .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") class_<maxiFilter>("maxiFilter")
.constructor<>() .constructor<>()
.function("lores", &maxiFilter::lores) .function("lores", &maxiFilter::lores)
...@@ -77,6 +84,15 @@ EMSCRIPTEN_BINDINGS(my_module) { ...@@ -77,6 +84,15 @@ EMSCRIPTEN_BINDINGS(my_module) {
.function("hipass", &maxiFilter::hipass) .function("hipass", &maxiFilter::hipass)
; ;
// MAXI MIX
class_<maxiMix>("maxiMix")
.constructor<>()
.function("stereo", &maxiMix::stereo, allow_raw_pointers())
.function("quad", &maxiMix::quad, allow_raw_pointers())
.function("ambisonic", &maxiMix::ambisonic, allow_raw_pointers())
;
// MAXI SAMPLE
class_<maxiSample>("maxiSample") class_<maxiSample>("maxiSample")
.constructor<>() .constructor<>()
.function("setSample", &maxiSample::setSample) .function("setSample", &maxiSample::setSample)
...@@ -96,5 +112,64 @@ EMSCRIPTEN_BINDINGS(my_module) { ...@@ -96,5 +112,64 @@ EMSCRIPTEN_BINDINGS(my_module) {
// .function("load", &maxiSample::load) // .function("load", &maxiSample::load)
// .function("read", &maxiSample::read, allow_raw_pointers()) // .function("read", &maxiSample::read, allow_raw_pointers())
; ;
}
// MAXI MAP
class_<maxiMap>("maxiMap")
.constructor<>()
.function("linlin", &maxiMap::linlin)
.function("linexp", &maxiMap::linexp)
.function("explin", &maxiMap::explin)
.function("clamp", &maxiMap::clamp)
;
// MAXI DYN
class_<maxiDyn>("maxiDyn")
.constructor<>()
.function("gate", &maxiDyn::gate)
.function("compressor", &maxiDyn::compressor)
;
// MAXI ENV
class_<maxiEnv>("maxiEnv")
.constructor<>()
.function("ar", &maxiEnv::ar)
.function("adsr", &maxiEnv::adsr)
;
// CONVERT
class_<convert>("convert")
.constructor<>()
.function("mtof", &convert::mtof)
;
// MAXI DISTORTION
class_<maxiDistortion>("maxiDistortion")
.constructor<>()
.function("fastAtan", &maxiDistortion::fastatan)
.function("atanDist", &maxiDistortion::atanDist)
.function("fastAtanDist", &maxiDistortion::fastAtanDist)
;
// MAXI FLANGER
class_<maxiFlanger>("maxiFlanger")
.constructor<>()
.function("flange", &maxiFlanger::flange)
;
// MAXI CHORUS
class_<maxiChorus>("maxiChorus")
.constructor<>()
.function("chorus", &maxiChorus::chorus)
;
// MAXI ENVELOPE FOLLOWER
class_<maxiEnvelopeFollower>("maxiEnvelopeFollower")
.constructor<>()
.function("setAttack", &maxiEnvelopeFollower::setAttack)
.function("setRelease", &maxiEnvelopeFollower::setRelease)
.function("play", &maxiEnvelopeFollower::play)
.function("reset", &maxiEnvelopeFollower::reset)
;
};
#endif #endif
...@@ -228,7 +228,7 @@ double maxiOsc::triangle(double frequency) { ...@@ -228,7 +228,7 @@ double maxiOsc::triangle(double frequency) {
// -------------------------------------------------------------------------------- // --------------------------------------------------------------------------------
// MAXI ENVELOPE // MAXI ENVELOPE
//double maxiEnvelope::line(int numberofsegments, double segments[]) {
double maxiEnvelope::line(int numberofsegments, std::vector<double>& segments) { double maxiEnvelope::line(int numberofsegments, std::vector<double>& segments) {
//This is a basic multi-segment ramp generator that you can use for more or less anything. //This is a basic multi-segment ramp generator that you can use for more or less anything.
//However, it's not that intuitive. //However, it's not that intuitive.
...@@ -266,7 +266,6 @@ void maxiEnvelope::trigger(int index, double amp) { ...@@ -266,7 +266,6 @@ void maxiEnvelope::trigger(int index, double amp) {
// amplitude=amp; // amplitude=amp;
} }
/*
// -------------------------------------------------------------------------------- // --------------------------------------------------------------------------------
// MAXI DELAY LINE // MAXI DELAY LINE
...@@ -297,7 +296,7 @@ double maxiDelayline::dl(double input, int size, double feedback, int position) ...@@ -297,7 +296,7 @@ double maxiDelayline::dl(double input, int size, double feedback, int position)
return(output); return(output);
} }
*/
// -------------------------------------------------------------------------------- // --------------------------------------------------------------------------------
// MAXI FILTER // MAXI FILTER
...@@ -365,11 +364,11 @@ double maxiFilter::bandpass(double input,double cutoff1, double resonance) { ...@@ -365,11 +364,11 @@ double maxiFilter::bandpass(double input,double cutoff1, double resonance) {
/*
// -------------------------------------------------------------------------------- // --------------------------------------------------------------------------------
// MAXI MIX // MAXI MIX
/*
//stereo bus //stereo bus
double *maxiMix::stereo(double input,double two[2],double x) { double *maxiMix::stereo(double input,double two[2],double x) {
if (x>1) x=1; if (x>1) x=1;
...@@ -410,7 +409,51 @@ double *maxiMix::ambisonic(double input,double eight[8],double x,double y,double ...@@ -410,7 +409,51 @@ double *maxiMix::ambisonic(double input,double eight[8],double x,double y,double
eight[7]=input*sqrt((x*(1.0-y))*z); eight[7]=input*sqrt((x*(1.0-y))*z);
return(eight); return(eight);
} }
*/ */
//stereo bus
void maxiMix::stereo(double input,vector<double>& two,double x) {
if (x>1) x=1;
if (x<0) x=0;
// two.clear();
two[0]=input*sqrt(1.0-x);
two[1]=input*sqrt(x);
// return(two);
}
//quad bus
vector<double> maxiMix::quad(double input,vector<double> four, double x,double y) {
if (x>1) x=1;
if (x<0) x=0;
if (y>1) y=1;
if (y<0) y=0;
four[0]=input*sqrt((1.0-x)*y);
four[1]=input*sqrt((1.0-x)*(1.0-y));
four[2]=input*sqrt(x*y);
four[3]=input*sqrt(x*(1.0-y));
return(four);
}
//ambisonic bus
vector<double> maxiMix::ambisonic(double input,vector<double> eight,double x,double y,double z) {
if (x>1) x=1;
if (x<0) x=0;
if (y>1) y=1;
if (y<0) y=0;
if (z>1) y=1;
if (z<0) y=0;
eight[0]=input*(sqrt((1.0-x)*y)*1.0-z);
eight[1]=input*(sqrt((1.0-x)*(1.0-y))*1.0-z);
eight[2]=input*(sqrt(x*y)*1.0-z);
eight[3]=input*(sqrt(x*(1.0-y))*1.0-z);
eight[4]=input*(sqrt((1.0-x)*y)*z);
eight[5]=input*(sqrt((1.0-x)*(1.0-y))*z);
eight[6]=input*sqrt((x*y)*z);
eight[7]=input*sqrt((x*(1.0-y))*z);
return(eight);
}
// -------------------------------------------------------------------------------- // --------------------------------------------------------------------------------
// MAXI SAMPLE // MAXI SAMPLE
...@@ -456,7 +499,7 @@ void maxiSample::trigger() { ...@@ -456,7 +499,7 @@ void maxiSample::trigger() {
position = 0; position = 0;
} }
/*
//This is the main read function. //This is the main read function.
bool maxiSample::read() bool maxiSample::read()
{ {
...@@ -538,20 +581,20 @@ bool maxiSample::read() ...@@ -538,20 +581,20 @@ bool maxiSample::read()
return result; // this should probably be something more descriptive return result; // this should probably be something more descriptive
} }
*/
// 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)(tempDC.at((int)position)); output = (double)(tempVec.at((int)position));
return output; return output;
} }
void maxiSample::setSample(vector<double>& temp){ void maxiSample::setSample(vector<double>& temp){
tempDC = temp; tempVec = temp;
length = tempDC.size(); length = tempVec.size();
} }
...@@ -572,7 +615,7 @@ double maxiSample::playOnce(double speed) { ...@@ -572,7 +615,7 @@ 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) * tempDC.at(1+ (long) position) + remainder * tempDC.at(2+(long) position));//linear interpolation output = (double) ((1-remainder) * tempVec.at(1+ (long) position) + remainder * tempVec.at(2+(long) position));//linear interpolation
else else
output=0; output=0;
return(output); return(output);
...@@ -602,7 +645,7 @@ double maxiSample::play(double speed) { ...@@ -602,7 +645,7 @@ double maxiSample::play(double speed) {
b=length-1; b=length-1;
} }
output = (double) ((1-remainder) * tempDC.at(a) + remainder * tempDC.at(b));//linear interpolation output = (double) ((1-remainder) * tempVec.at(a) + remainder * tempVec.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);
...@@ -619,7 +662,7 @@ double maxiSample::play(double speed) { ...@@ -619,7 +662,7 @@ double maxiSample::play(double speed) {
else { else {
b=0; b=0;
} }
output = (double) ((-1-remainder) * tempDC.at(a) + remainder * tempDC.at(b));//linear interpolation output = (double) ((-1-remainder) * tempVec.at(a) + remainder * tempVec.at(b));//linear interpolation
} }
return(output); return(output);
} }
...@@ -659,8 +702,8 @@ double maxiSample::play(double frequency, double start, double end, double& pos) ...@@ -659,8 +702,8 @@ double maxiSample::play(double frequency, double start, double end, double& pos)
b=length-1; b=length-1;
} }
output = (double) ((1-remainder) * tempDC.at(a) + output = (double) ((1-remainder) * tempVec.at(a) +
remainder * tempDC.at(b));//linear interpolation remainder * tempVec.at(b));//linear interpolation
} else { } else {
frequency=frequency-(frequency+frequency); frequency=frequency-(frequency+frequency);
if ( pos <= start ) pos = end; if ( pos <= start ) pos = end;
...@@ -679,8 +722,8 @@ double maxiSample::play(double frequency, double start, double end, double& pos) ...@@ -679,8 +722,8 @@ double maxiSample::play(double frequency, double start, double end, double& pos)
else { else {
b=0; b=0;
} }
output = (double) ((-1-remainder) * tempDC.at(a) + output = (double) ((-1-remainder) * tempVec.at(a) +
remainder * tempDC.at(b));//linear interpolation remainder * tempVec.at(b));//linear interpolation
} }
...@@ -703,26 +746,26 @@ double maxiSample::play4(double frequency, double start, double end) { ...@@ -703,26 +746,26 @@ 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>0) { if (position>0) {
a=tempDC.at((long)(floor(position))-1); a=tempVec.at((long)(floor(position))-1);
} else { } else {
a=tempDC.at(0); a=tempVec.at(0);
} }
b=tempDC.at((long) position); b=tempVec.at((long) position);
if (position<end-2) { if (position<end-2) {
c=tempDC.at((long) position+1); c=tempVec.at((long) position+1);
} else { } else {
c=tempDC.at(0); c=tempVec.at(0);
} }
if (position<end-3) { if (position<end-3) {
d=tempDC.at((long) position+2); d=tempVec.at((long) position+2);
} else { } else {
d=tempDC.at(0); d=tempVec.at(0);
} }
a1 = 0.5f * (c - a); a1 = 0.5f * (c - a);
...@@ -736,26 +779,26 @@ double maxiSample::play4(double frequency, double start, double end) { ...@@ -736,26 +779,26 @@ 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=tempDC.at((long) position+1); a=tempVec.at((long) position+1);
} else { } else {
a=tempDC.at(0); a=tempVec.at(0);
} }
b=tempDC.at((long) position); b=tempVec.at((long) position);
if (position>start) { if (position>start) {
c=tempDC.at((long) position-1); c=tempVec.at((long) position-1);
} else { } else {
c=tempDC.at(0); c=tempVec.at(0);
} }
if (position>start+1) { if (position>start+1) {
d=tempDC.at((long) position-2); d=tempVec.at((long) position-2);
} else { } else {
d=tempDC.at(0); d=tempVec.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;
...@@ -992,7 +1035,7 @@ void maxiSample::reset() { ...@@ -992,7 +1035,7 @@ void maxiSample::reset() {
incrementing - consequently a long attack is something like 0.0001 and a long release is like 0.9999. incrementing - consequently a long attack is something like 0.0001 and a long release is like 0.9999.
Annoyingly, a short attack is 0.1, and a short release is 0.99. I'll sort this out laters */ Annoyingly, a short attack is 0.1, and a short release is 0.99. I'll sort this out laters */
/*
double maxiDyn::gate(double input, double threshold, long holdtime, double attack, double release) { double maxiDyn::gate(double input, double threshold, long holdtime, double attack, double release) {
if (fabs(input)>threshold && attackphase!=1){ if (fabs(input)>threshold && attackphase!=1){
...@@ -1061,13 +1104,13 @@ double maxiDyn::compressor(double input, double ratio, double threshold, double ...@@ -1061,13 +1104,13 @@ double maxiDyn::compressor(double input, double ratio, double threshold, double
return output*(1+log(ratio)); return output*(1+log(ratio));
} }
*/
/* Lots of people struggle with the envelope generators so here's a new easy one. /* Lots of people struggle with the envelope generators so here's a new easy one.
It takes mental numbers for attack and release tho. Basically, they're exponentials. It takes mental numbers for attack and release tho. Basically, they're exponentials.
I'll map them out later so that it's a bit more intuitive */ I'll map them out later so that it's a bit more intuitive */
/*
double maxiEnv::ar(double input, double attack, double release, long holdtime, int trigger) { double maxiEnv::ar(double input, double attack, double release, long holdtime, int trigger) {
if (trigger==1 && attackphase!=1 && holdphase!=1){ if (trigger==1 && attackphase!=1 && holdphase!=1){
...@@ -1175,4 +1218,3 @@ void maxiEnvelopeFollower::setAttack(double attackMS) { ...@@ -1175,4 +1218,3 @@ void maxiEnvelopeFollower::setAttack(double attackMS) {
void maxiEnvelopeFollower::setRelease(double releaseMS) { void maxiEnvelopeFollower::setRelease(double releaseMS) {
release = pow( 0.01, 1.0 / ( releaseMS * maxiSettings::sampleRate * 0.001 ) ); release = pow( 0.01, 1.0 / ( releaseMS * maxiSettings::sampleRate * 0.001 ) );
} }
*/
...@@ -126,7 +126,7 @@ public: ...@@ -126,7 +126,7 @@ public:
}; };
/*
class maxiDelayline { class maxiDelayline {
double frequency; double frequency;
int phase; int phase;
...@@ -139,10 +139,8 @@ public: ...@@ -139,10 +139,8 @@ public:
maxiDelayline(); maxiDelayline();
double dl(double input, int size, double feedback); double dl(double input, int size, double feedback);
double dl(double input, int size, double feedback, int position); double dl(double input, int size, double feedback, int position);