Commit fc26f9bb authored by Dr-Dan's avatar Dr-Dan

Replicant example working

parent 0160af9d
......@@ -415,7 +415,6 @@ double *maxiMix::ambisonic(double input,double eight[8],double x,double y,double
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);
......@@ -423,7 +422,7 @@ void maxiMix::stereo(double input,vector<double>& two,double x) {
}
//quad bus
vector<double> maxiMix::quad(double input,vector<double> four, double x,double y) {
void 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;
......@@ -432,11 +431,11 @@ vector<double> maxiMix::quad(double input,vector<double> four, double x,double 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);
// return(four);
}
//ambisonic bus
vector<double> maxiMix::ambisonic(double input,vector<double> eight,double x,double y,double z) {
void 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;
......@@ -451,7 +450,7 @@ vector<double> maxiMix::ambisonic(double input,vector<double> eight,double x,dou
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);
// return(eight);
}
// --------------------------------------------------------------------------------
......
......@@ -6,7 +6,7 @@
* Copyright 2009 Mick Grierson & Strangeloop Limited. All rights reserved.
* Thanks to the Goldsmiths Creative Computing Team.
* Special thanks to Arturo Castro for the PortAudio implementation.
*
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
......@@ -15,16 +15,16 @@
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions o/Users/Dan/Downloads/Maximilian-master/stb_vorbis.c
/Users/Dan/Downloads/Maximilian-master/stb_vorbis.h
/Users/Dan/Downloads/Maximilian-master/player.h
/Users/Dan/Downloads/Maximilian-master/player.cpp
/Users/Dan/Downloads/Maximilian-master/maximilian.cpp
/Users/Dan/Downloads/Maximilian-master/maximilian.hf the Software.
/Users/Dan/Downloads/Maximilian-master/stb_vorbis.h
/Users/Dan/Downloads/Maximilian-master/player.h
/Users/Dan/Downloads/Maximilian-master/player.cpp
/Users/Dan/Downloads/Maximilian-master/maximilian.cpp
/Users/Dan/Downloads/Maximilian-master/maximilian.hf the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
......@@ -91,8 +91,8 @@ public:
double noise();
double sinebuf(double frequency);
double sinebuf4(double frequency);
double sawn(double frequency);
double rect(double frequency, double duty=0.5);
double sawn(double frequency);
double rect(double frequency, double duty=0.5);
void phaseReset(double phaseIn);
};
......@@ -106,12 +106,12 @@ class maxiEnvelope {
double currentval;
double nextval;
int isPlaying;
public:
// maxiEnvelope(){}
// 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;
double amplitude;
......@@ -143,7 +143,7 @@ public:
// NEXT
class maxiFilter {
class maxiFilter {
double gain;
double input;
double output;
......@@ -154,7 +154,7 @@ class maxiFilter {
double y;//pos
double z;//pole
double c;//filter coefficient
public:
maxiFilter():x(0.0), y(0.0), z(0.0), c(0.0){};
double cutoff;
......@@ -171,63 +171,65 @@ public:
// most variables in this class seem to have no use ??
// all recieved as args ...
class maxiMix {
// double input;
// double two[2];
// double four[4];
// double eight[8];
// vector<double> two;
// vector<double> four[4];
// vector<double> eight[8];
// these are never used???
// double input;
// double two[2];
// double four[4];
// double eight[8];
// vector<double> two;
// vector<double> four[4];
// vector<double> eight[8];
public:
// double x;
// double y;
// double z;
// double x;
// double y;
// double z;
/*
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 *quad(double input,double four[4], double x,double y);
// double *ambisonic(double input,double eight[8],double x,double y, double z);
*/
// 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);
void stereo(double input,vector<double>& two,double x);
vector<double> quad(double input,vector<double> four, double x,double y);
vector<double> ambisonic(double input,vector<double> eight, double x,double y, double z);
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>
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);
};
maxiLagExp(T initAlpha, T initVal) {
init(initAlpha, 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;
}
inline void addSample(T newVal) {
val = (alpha * newVal) + (alphaReciprocal * val);
val = (alpha * newVal) + (alphaReciprocal * val);
}
inline T value() {
return val;
return val;
}
};
*/
};
*/
......@@ -246,7 +248,7 @@ private:
double position, recordPosition;
double speed;
double output;
// maxiLagExp<double> loopRecordLag;
// maxiLagExp<double> loopRecordLag;
public:
int myDataSize;
......@@ -254,122 +256,122 @@ public:
int mySampleRate;
long length;
void getLength();
void setLength(unsigned long numSamples);
void setLength(unsigned long numSamples);
char* myData;
short* temp;
short* temp;
// different vars for use with js
vector<double> tempVec;
vector<double> tempVec;
~maxiSample()
{
if (myData) free(myData);
if (temp) free(temp);
printf("freeing SampleData");
if (temp) free(temp);
printf("freeing SampleData");
}
maxiSample():myData(NULL),temp(NULL),position(0), recordPosition(0), myChannels(1), mySampleRate(maxiSettings::sampleRate) {};
bool load(string fileName, int channel=0);
// bool loadOgg(string filename,int channel=0);
//
// bool loadOgg(string filename,int channel=0);
//
void trigger();
// read a wav file into this class
bool read();
//read an ogg file into this class using stb_vorbis
// bool readOgg();
//
// void loopRecord(double newSample, const bool recordEnabled, const double recordMix) {
// loopRecordLag.addSample(recordEnabled);
// if(recordEnabled) {
// double currentSample = ((short*)myData)[(unsigned long)recordPosition] / 32767.0;
// newSample = (recordMix * currentSample) + ((1.0 - recordMix) * newSample);
// newSample *= loopRecordLag.value();
// ((short*)myData)[(unsigned long)recordPosition] = newSample * 32767;
// }
// ++recordPosition;
// if (recordPosition == length)
// recordPosition=0;
// }
//
// void clear();
//
// void reset();
// double play();
// bool readOgg();
//
// void loopRecord(double newSample, const bool recordEnabled, const double recordMix) {
// loopRecordLag.addSample(recordEnabled);
// if(recordEnabled) {
// double currentSample = ((short*)myData)[(unsigned long)recordPosition] / 32767.0;
// newSample = (recordMix * currentSample) + ((1.0 - recordMix) * newSample);
// newSample *= loopRecordLag.value();
// ((short*)myData)[(unsigned long)recordPosition] = newSample * 32767;
// }
// ++recordPosition;
// if (recordPosition == length)
// recordPosition=0;
// }
//
// void clear();
//
// void reset();
// double play();
void setSample(vector<double>& temp);
double play();
void clear(){tempVec.clear();}
// double playOnce();
//
// double playOnce();
//
double playOnce(double speed);
//
//
double play(double speed);
double play(double frequency, double start, double end);
// why this no work with embind? :
// non-const lvalue reference to type 'double' cannot bind to a temporary of type 'double'
// why this no work with embind? :
// non-const lvalue reference to type 'double' cannot bind to a temporary of type 'double'
double play(double frequency, double start, double end, double& pos);
//
//
//
//
double play4(double frequency, double start, double end);
//
// double bufferPlay(unsigned char &bufferin,long length);
//
// double bufferPlay(unsigned char &bufferin,double speed,long length);
//
// double bufferPlay(unsigned char &bufferin,double frequency, double start, double end);
//
// double bufferPlay4(unsigned char &bufferin,double frequency, double start, double end);
// bool save() {
// save(myPath);
// }
// bool save(string filename)
// {
// fstream myFile (filename.c_str(), ios::out | ios::binary);
//
// // write the wav file per the wav file format
// myFile.seekp (0, ios::beg);
// myFile.write ("RIFF", 4);
// myFile.write ((char*) &myChunkSize, 4);
// myFile.write ("WAVE", 4);
// myFile.write ("fmt ", 4);
// myFile.write ((char*) &mySubChunk1Size, 4);
// myFile.write ((char*) &myFormat, 2);
// myFile.write ((char*) &myChannels, 2);
// myFile.write ((char*) &mySampleRate, 4);
// myFile.write ((char*) &myByteRate, 4);
// myFile.write ((char*) &myBlockAlign, 2);
// myFile.write ((char*) &myBitsPerSample, 2);
// myFile.write ("data", 4);
// myFile.write ((char*) &myDataSize, 4);
// myFile.write (myData, myDataSize);
//
// return true;
// }
//
// double bufferPlay(unsigned char &bufferin,long length);
//
// double bufferPlay(unsigned char &bufferin,double speed,long length);
//
// double bufferPlay(unsigned char &bufferin,double frequency, double start, double end);
//
// double bufferPlay4(unsigned char &bufferin,double frequency, double start, double end);
// bool save() {
// save(myPath);
// }
// bool save(string filename)
// {
// fstream myFile (filename.c_str(), ios::out | ios::binary);
//
// // write the wav file per the wav file format
// myFile.seekp (0, ios::beg);
// myFile.write ("RIFF", 4);
// myFile.write ((char*) &myChunkSize, 4);
// myFile.write ("WAVE", 4);
// myFile.write ("fmt ", 4);
// myFile.write ((char*) &mySubChunk1Size, 4);
// myFile.write ((char*) &myFormat, 2);
// myFile.write ((char*) &myChannels, 2);
// myFile.write ((char*) &mySampleRate, 4);
// myFile.write ((char*) &myByteRate, 4);
// myFile.write ((char*) &myBlockAlign, 2);
// myFile.write ((char*) &myBitsPerSample, 2);
// myFile.write ("data", 4);
// myFile.write ((char*) &myDataSize, 4);
// myFile.write (myData, myDataSize);
//
// return true;
// }
// return a printable summary of the wav file
// char *getSummary()
// {
// char *summary = new char[250];
// sprintf(summary, " Format: %d\n Channels: %d\n SampleRate: %d\n ByteRate: %d\n BlockAlign: %d\n BitsPerSample: %d\n DataSize: %d\n", myFormat, myChannels, mySampleRate, myByteRate, myBlockAlign, myBitsPerSample, myDataSize);
// std::cout << myDataSize;
// return summary;
// }
// char *getSummary()
// {
// char *summary = new char[250];
// sprintf(summary, " Format: %d\n Channels: %d\n SampleRate: %d\n ByteRate: %d\n BlockAlign: %d\n BitsPerSample: %d\n DataSize: %d\n", myFormat, myChannels, mySampleRate, myByteRate, myBlockAlign, myBitsPerSample, myDataSize);
// std::cout << myDataSize;
// return summary;
// }
string getSummary()
{
......@@ -457,23 +459,23 @@ public:
class maxiDistortion {
public:
// atan distortion, see http://www.musicdsp.org/showArchiveComment.php?ArchiveID=104
// shape from 1 (soft clipping) to infinity (hard clipping)
double atanDist(const double in, const double shape);
double fastAtanDist(const double in, const double shape);
double fastatan( double x );
// atan distortion, see http://www.musicdsp.org/showArchiveComment.php?ArchiveID=104
// shape from 1 (soft clipping) to infinity (hard clipping)
double atanDist(const double in, const double shape);
double fastAtanDist(const double in, const double shape);
double fastatan( double x );
};
inline double maxiDistortion::atanDist(const double in, const double shape) {
double out;
out = (1.0 / atan(shape)) * atan(in * shape);
return out;
double out;
out = (1.0 / atan(shape)) * atan(in * shape);
return out;
}
inline double maxiDistortion::fastAtanDist(const double in, const double shape) {
double out;
out = (1.0 / fastatan(shape)) * fastatan(in * shape);
return out;
double out;
out = (1.0 / fastatan(shape)) * fastatan(in * shape);
return out;
}
inline double maxiDistortion::fastatan(double x)
......@@ -484,76 +486,76 @@ inline double maxiDistortion::fastatan(double x)
class maxiFlanger {
public:
//delay = delay time - ~800 sounds good
//feedback = 0 - 1
//speed = lfo speed in Hz, 0.0001 - 10 sounds good
//depth = 0 - 1
double flange(const double input, const unsigned int delay, const double feedback, const double speed, const double depth);
maxiDelayline dl;
maxiOsc lfo;
//delay = delay time - ~800 sounds good
//feedback = 0 - 1
//speed = lfo speed in Hz, 0.0001 - 10 sounds good
//depth = 0 - 1
double flange(const double input, const unsigned int delay, const double feedback, const double speed, const double depth);
maxiDelayline dl;
maxiOsc lfo;
};
inline double maxiFlanger::flange(const double input, const unsigned int delay, const double feedback, const double speed, const double depth)
{
//todo: needs fixing
double output;
double lfoVal = lfo.triangle(speed);
output = dl.dl(input, delay + (lfoVal * depth * delay) + 1, feedback) ;
double normalise = (1 - fabs(output));
output *= normalise;
return (output + input) / 2.0;
//todo: needs fixing
double output;
double lfoVal = lfo.triangle(speed);
output = dl.dl(input, delay + (lfoVal * depth * delay) + 1, feedback) ;
double normalise = (1 - fabs(output));
output *= normalise;
return (output + input) / 2.0;
}
class maxiChorus {
public:
//delay = delay time - ~800 sounds good
//feedback = 0 - 1
//speed = lfo speed in Hz, 0.0001 - 10 sounds good
//depth = 0 - 1
double chorus(const double input, const unsigned int delay, const double feedback, const double speed, const double depth);
maxiDelayline dl, dl2;
maxiOsc lfo;
maxiFilter lopass;
//delay = delay time - ~800 sounds good
//feedback = 0 - 1
//speed = lfo speed in Hz, 0.0001 - 10 sounds good
//depth = 0 - 1
double chorus(const double input, const unsigned int delay, const double feedback, const double speed, const double depth);
maxiDelayline dl, dl2;
maxiOsc lfo;
maxiFilter lopass;
};
inline double maxiChorus::chorus(const double input, const unsigned int delay, const double feedback, const double speed, const double depth)
{
//this needs fixing
double output1, output2;
double lfoVal = lfo.noise();
lfoVal = lopass.lores(lfoVal, speed, 1.0) * 2.0;
output1 = dl.dl(input, delay + (lfoVal * depth * delay) + 1, feedback) ;
output2 = dl2.dl(input, (delay + (lfoVal * depth * delay * 1.02) + 1) * 0.98, feedback * 0.99) ;
output1 *= (1.0 - fabs(output1));
output2 *= (1.0 - fabs(output2));
return (output1 + output2 + input) / 3.0;
//this needs fixing
double output1, output2;
double lfoVal = lfo.noise();
lfoVal = lopass.lores(lfoVal, speed, 1.0) * 2.0;
output1 = dl.dl(input, delay + (lfoVal * depth * delay) + 1, feedback) ;
output2 = dl2.dl(input, (delay + (lfoVal * depth * delay * 1.02) + 1) * 0.98, feedback * 0.99) ;
output1 *= (1.0 - fabs(output1));
output2 *= (1.0 - fabs(output2));
return (output1 + output2 + input) / 3.0;
}
class maxiEnvelopeFollower {
public:
maxiEnvelopeFollower() {
setAttack(100);
setRelease(100);
env = 0;
}
void setAttack(double attackMS);
void setRelease(double releaseMS);
inline double play(double input) {
input = fabs(input);
if (input>env)
env = attack * (env - input) + input;
else
env = release * (env - input) + input;
return env;
}
maxiEnvelopeFollower() {
setAttack(100);
setRelease(100);
env = 0;
}
void setAttack(double attackMS);
void setRelease(double releaseMS);
inline double play(double input) {
input = fabs(input);
if (input>env)
env = attack * (env - input) + input;
else
env = release * (env - input) + input;
return env;
}
void reset() {env=0;}
private:
double attack, release, env;
double attack, release, env;
};
#endif
......@@ -68,7 +68,7 @@ var outputErrorLogged = false;
function process(event) {
var numChannels = event.outputBuffer.numberOfChannels;
var outputLength = event.outputBuffer.getChannelData(0).length;
console.log(numChannels);
// console.log(numChannels);
for (var i = 0; i < outputLength; ++i) {
play();
......
<!--
Copyright 2010, Google Inc.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
<