From 1100fc8c462d9a17731340596e7d9c07adb3fe54 Mon Sep 17 00:00:00 2001 From: mick grierson Date: Mon, 27 Jul 2015 01:07:41 +0100 Subject: More major repair work. New OS X 10.10 SDK example project. New project structure. New Tutorials / Examples. --- main.cpp | 115 +++++++++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 98 insertions(+), 17 deletions(-) (limited to 'main.cpp') diff --git a/main.cpp b/main.cpp index 119fddf..07795df 100755 --- a/main.cpp +++ b/main.cpp @@ -1,32 +1,113 @@ #include "maximilian.h" +#include "libs/maxim.h" + +//This shows how to use maximilian to build a polyphonic synth. + +//These are the synthesiser bits +maxiOsc VCO1[6],VCO2[6],LFO1[6],LFO2[6]; +maxiFilter VCF[6]; +maxiEnv ADSR[6]; + +//This is a bunch of control signals so that we can hear something + +maxiOsc timer;//this is the metronome +int currentCount,lastCount,voice=0;//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 + +double VCO1out[6],VCO2out[6],LFO1out[6],LFO2out[6],VCFout[6],ADSRout[6],mix,pitch[6]; + +maxiFFTOctaveAnalyzer octo; +int nAverages; +float *ifftOutput; +int ifftSize; + +maxiIFFT ifft; +maxiFFT mfft; +int fftSize; +int bins, dataSize; -maxiSample beats; //We give our sample a name. It's called beats this time. We could have loads of them, but they have to have different names. -maxiDyn compressor; //this is a compressor -double out; void setup() {//some inits - beats.load("/Users/michaelgrierson/Documents/workspace/Maximilian/ofxMaxim/examples/OSX/ofMaximExample007OSX_Granular/bin/data/beat2.wav");//load in your samples. Provide the full path to a wav file. - printf("Summary:\n%s", beats.getSummary());//get info on samples if you like. + fftSize = 1024; + mfft.setup(fftSize, 1024, 256); + ifft.setup(fftSize, 1024, 256); - compressor.setAttack(300); - compressor.setRelease(300); - compressor.setThreshold(0.25); - compressor.setRatio(5); + + nAverages = 12; + octo.setup(44100, fftSize/2, nAverages); - //you can set these any time you like. + for (int i=0;i<6;i++) { + ADSR[i].setAttack(0); + ADSR[i].setDecay(200); + ADSR[i].setSustain(0.2); + ADSR[i].setRelease(2000); + + } } -void play(double *output) {//this is where the magic happens. Very slow magic. +void play(double *output) { + + mix=0;//we're adding up the samples each update and it makes sense to clear them each time first. + + //so this first bit is just a basic metronome so we can hear what we're doing. + + currentCount=(int)timer.phasor(8);//this sets up a metronome that ticks 8 times a second + if (lastCount!=currentCount) {//if we have a new timer int this sample, play the sound + + if (voice==6) { + voice=0; + } + + ADSR[voice].trigger=1;//trigger the envelope from the start + pitch[voice]=voice+1; + voice++; + + lastCount=0; + cout << mfft.spectralFlatness() << ", " << mfft.spectralCentroid() << endl; + + for (int i=0; i