Mercurial > hg > multitrack-audio-matcher
view src/testApp.cpp @ 2:179c09199b3c
bayesian vector now adding gaussians for kick onsets
author | Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk> |
---|---|
date | Tue, 31 Jan 2012 21:34:19 +0000 |
parents | 852173ca8365 |
children | 5e188c0035b6 |
line wrap: on
line source
#include "testApp.h" #include "stdio.h" //#include "aubio.h" #include <iostream> #include <cstring> #include <string> #include <cstdlib> const double samplingFrequency = 44100.0; //-------------------------------------------------------------- void testApp::setup(){ // 2 output channels, // 0 input channels // 22050 samples per second // 256 samples per buffer // 4 num buffers (latency) //nb THIS CODE WOULD BE USEFUL IF WE EVER WANTED REAL-TIME INPUT - VIA ofSoundSteam receiver.setup( PORT ); sampleRate = 44100; ofSoundStreamSetup(2,0,this, sampleRate,256, 4); ofSetFrameRate(30); eventMatcher.recordedTracks.loadTestAudio(); //audioFilePlayer.loadAudioFile(infilename); } /* void testApp::loadTestAudio(){ const char *infilename = "../../../data/sound/bach4_short1.wav"; //LoadedAudioHolder lah; // lah.loadAudioFile(infilename); // loadedAudioFiles.push_back(lah); //Take care here - we need a pointer to create new instance //but not then delete the instance before the vector of all audio tracks has been used //the above code using lah has problem that it deletes objects once out of the scope of testApp.setup() //when lah is in theory no longer used - something like that possible? - at least pointers to onset detection seem deleted loadedAudioPtr = new LoadedAudioHolder; loadedAudioPtr->loadAudioFile(infilename); // loadedAudioFiles.push_back(*loadedAudioPtr); loadedAudioFiles[0] = *loadedAudioPtr; loadedAudioFiles[0].fileLoader.onsetDetect.window.setToRelativeSize(0, 0.0, 1, 0.25); // printf("Loaded audio %i\n", (int)numberOfAudioTracks); printf("loaded max val is %f\n", loadedAudioFiles[0].fileLoader.onsetDetect.onsetDetector.maximumDetectionValue); printf("BEFORE LOADING 1\n"); keyPressed('p'); loadedAudioPtr = new LoadedAudioHolder; loadedAudioPtr->loadAudioFile(infilename); // loadedAudioFiles.push_back(*loadedAudioPtr); loadedAudioFiles[1] = *loadedAudioPtr; loadedAudioFiles[1].fileLoader.onsetDetect.window.setToRelativeSize(0, 0.3, 1, 0.25); printf("AFTER LOADING 1\n"); keyPressed('p'); } */ //-------------------------------------------------------------- void testApp::update(){ eventMatcher.recordedTracks.updatePosition(); // audioFilePlayer.updateToPlayPosition(); checkForOSCmessages(); } void testApp::checkForOSCmessages(){ // check for waiting messages while( receiver.hasWaitingMessages() ) { // get the next message ofxOscMessage m; receiver.getNextMessage( &m ); // check for mouse moved message if ( m.getAddress() == "/aubioPitch" ){ float pitchIn = m.getArgAsFloat(0); int timeIn = m.getArgAsInt32(1); printf("AUBIO PITCH RECEIVED %f at time %i\n", pitchIn, timeIn); eventMatcher.newPitchEvent(pitchIn, timeIn); } if ( m.getAddress() == "/kick" ){ // float pitchIn = m.getArgAsFloat(0); double timeIn = m.getArgAsInt32(0); printf("kick RECEIVED at time %f\n", timeIn); eventMatcher.newKickEvent(timeIn); } if ( m.getAddress() == "/snare" ){ // float pitchIn = m.getArgAsFloat(0); double timeIn = m.getArgAsInt32(0); printf("snare RECEIVED at time %f\n", timeIn); eventMatcher.newSnareEvent(timeIn); } } } //-------------------------------------------------------------- void testApp::draw(){ eventMatcher.draw(); // audioFilePlayer.draw(); } //-------------------------------------------------------------- void testApp::keyPressed (int key){ if (key == '-'){ volume -= 0.05; volume = MAX(volume, 0); } else if (key == '+'){ volume += 0.05; volume = MIN(volume, 1); } if (key == 'q'){ eventMatcher.recordedTracks.switchScreens(); } if (key == OF_KEY_RIGHT){ // audioFilePlayer.loadedAudio.setPosition(min(1.0, audioFilePlayer.loadedAudio.getPosition() + (audioFilePlayer.fileLoader.audioHolder.audioScaleSamples/(4.0*audioFilePlayer.fileLoader.audioHolder.audioVector.size()))) ); } if (key == OF_KEY_LEFT){ // audioFilePlayer.loadedAudio.setPosition(max(0.0, audioFilePlayer.loadedAudio.getPosition() - (audioFilePlayer.fileLoader.audioHolder.audioScaleSamples/(4.0*audioFilePlayer.fileLoader.audioHolder.audioVector.size())))); } if (key == ' '){ eventMatcher.recordedTracks.togglePlay(); } if (key == OF_KEY_RETURN){ eventMatcher.recordedTracks.stop(); } if (key == 'o'){ openNewAudioFileWithdialogBox(); } if (key == 'p'){ } if (key == OF_KEY_UP){ eventMatcher.recordedTracks.zoomOut(); } if (key == OF_KEY_DOWN){ eventMatcher.recordedTracks.zoomIn(); } } //-------------------------------------------------------------- void testApp::keyReleased (int key){ } //-------------------------------------------------------------- void testApp::mouseMoved(int x, int y ){ } //-------------------------------------------------------------- void testApp::mouseDragged(int x, int y, int button){ } //-------------------------------------------------------------- void testApp::mousePressed(int x, int y, int button){ } //-------------------------------------------------------------- void testApp::mouseReleased(int x, int y, int button){ } //-------------------------------------------------------------- void testApp::windowResized(int w, int h){ eventMatcher.windowResized(w, h); } //-------------------------------------------------------------- void testApp::audioRequested (float * output, int bufferSize, int nChannels){ //pan = 0.5f; float leftScale = 1 - pan; float rightScale = pan; } //-------------------------------------------------------------- void testApp::openNewAudioFileWithdialogBox(){ std::string filename; getFilenameFromDialogBox(&filename); loadNewAudio(filename); } void testApp::loadNewAudio(string soundFileName){ eventMatcher.recordedTracks.loadedAudioFiles[0].loadAudioFile(soundFileName); // for (int i = 0;i < numberOfAudioTracks;i++) // loadedAudioFiles[i].loadAudioFile(soundFileName); // audioFilePlayer.loadAudioFile(soundFileName); } bool testApp::getFilenameFromDialogBox(std::string* fileNameToSave){ //this uses a pointer structure within the loader and returns true if the dialogue box was used successfully // first, create a string that will hold the URL string URL; // openFile(string& URL) returns 1 if a file was picked // returns 0 when something went wrong or the user pressed 'cancel' int response = ofxFileDialogOSX::openFile(URL); if(response){ // now you can use the URL *fileNameToSave = URL; //printf("\n filename is %s \n", soundFileName.c_str()); return true; } else { // soundFileName = "OPEN canceled. "; printf("\n open file cancelled \n"); return false; } }