From 0b32a159bb21c4d789a6425819b2c1c931167c9a Mon Sep 17 00:00:00 2001 From: Chris Kiefer Date: Thu, 10 Nov 2011 16:58:03 +0000 Subject: Atom book player --- .../maxiAtomSynthesis/src/mp.cpp | 31 ++++++++++------------ 1 file changed, 14 insertions(+), 17 deletions(-) (limited to 'ofxMaxim/ofxMaximExamples007OSX/maxiAtomSynthesis/src/mp.cpp') diff --git a/ofxMaxim/ofxMaximExamples007OSX/maxiAtomSynthesis/src/mp.cpp b/ofxMaxim/ofxMaximExamples007OSX/maxiAtomSynthesis/src/mp.cpp index 7db1374..57970cf 100644 --- a/ofxMaxim/ofxMaximExamples007OSX/maxiAtomSynthesis/src/mp.cpp +++ b/ofxMaxim/ofxMaximExamples007OSX/maxiAtomSynthesis/src/mp.cpp @@ -1,6 +1,5 @@ #include "mp.h" - //-------------------------------------------------------------- void mp::setup(){ ofEnableAlphaBlending(); @@ -11,8 +10,7 @@ void mp::setup(){ // pyd.clear(); - - maxiAtomBook::loadMPTKXmlBook(ofToDataPath("/tmp/book.xml"), book); + maxiAtomBook::loadMPTKXmlBook(ofToDataPath("book100.xml"), book); sort(book.atoms.begin(), book.atoms.end(), maxiAtom::atomSortPositionAsc); atomBuffer.resize(512); atomData.resize(book.atoms[0]->length); @@ -20,6 +18,9 @@ void mp::setup(){ ofxMaxiSettings::setup(44100, 2, 512); ofSoundStreamSetup(maxiSettings::channels,0,this, maxiSettings::sampleRate, maxiSettings::bufferSize, 4);/* Call this last ! */ +// flArr test; +// maxiCollider::createGabor(test, maxiMap::linexp(atom->frequency, 0, 0.2, 20, 20000), 44100, atom->length, atom->phase, 0.3, atom->amp / 40.0); + } @@ -27,17 +28,21 @@ void mp::setup(){ //-------------------------------------------------------------- void mp::update(){ flArr test; + //generate atoms from mouse position // maxiCollider::createGabor(test, maxiMap::linexp((float)mouseX/ofGetWidth(), 0, 1, 100, 10000) * (1.0 + (ofRandomuf() * 0.2)), // maxiSettings::sampleRate, // maxiMap::linlin((float)mouseY / ofGetHeight(), 0, 1, 2000, 40000) * (1.0 + (ofRandomuf() * 0.3)), // ofRandomf() * PI, 0.3, 0.05); // atomStream.addAtom(test); - static int atomIdx=0; - maxiGaborAtom *atom = (maxiGaborAtom*) book.atoms[atomIdx % book.atoms.size()]; - maxiCollider::createGabor(test, maxiMap::linexp(atom->frequency, 0, 0.2, 20, 20000), 44100, atom->length, atom->phase, 0.3, atom->amp / 40.0); - atomStream.addAtom(test); - atomIdx++; + //play book back one atom at a time +// static int atomIdx=0; +// maxiGaborAtom *atom = (maxiGaborAtom*) book.atoms[atomIdx % book.atoms.size()]; +// maxiCollider::createGabor(test, maxiMap::linlin(atom->frequency, 0.0, 1.0, 20, 20000), 44100, atom->length, atom->phase, 0.3, atom->amp / 30.0); +// atomStream.addAtom(test); +// atomIdx++; +// cout << (atomIdx % book.atoms.size()) << ", " << maxiMap::linlin(atom->frequency, 0.0, 1.0, 20, 20000) << ", " << atom->amp << endl; + } //-------------------------------------------------------------- @@ -46,15 +51,7 @@ void mp::draw(){ } void mp::audioRequested (float * output, int bufferSize, int nChannels){ -// long idx = atomStream.getSampleIdx(); -// static int atomIdx = 0; -// maxiGaborAtom *atom = (maxiGaborAtom*) book.atoms[atomIdx % book.atoms.size()]; -// while(atom->position < (idx + bufferSize) % book.numSamples) { -// maxiCollider::createGabor(atomData, maxiMap::linexp(atom->frequency, 0, 0.2, 20, 20000), 44100, atom->length, atom->phase, 0.3, atom->amp / 40.0); -// atomStream.addAtom(atomData); -// atomIdx++; -// atom = (maxiGaborAtom*) book.atoms[atomIdx % book.atoms.size()]; -// } + atomPlayer.play(book, atomStream, output, bufferSize); memset(&atomBuffer[0], 0, sizeof(float) * bufferSize); atomStream.fillNextBuffer(&(atomBuffer[0]), bufferSize); -- cgit v1.3