#include "testApp.h" //-------------------------------------------------------------- void testApp::setup() { ofSetVerticalSync(true); ofSetCircleResolution(80); ofBackground(54, 54, 54); // 0 output channels, // 2 input channels // 44100 samples per second // 256 samples per buffer // 4 num buffers (latency) soundStream.listDevices(); //if you want to set a different device id //soundStream.setDeviceID(0); //bear in mind the device id corresponds to all audio devices, including input-only and output-only devices. int rate =44100; int channels=1; int outputNo=0; //string soname="qm-vamp-plugins"; //string id="qm-tempotracker"; //string id="qm-barbeattracker"; ofxXmlSettings xml; if(xml.loadFile("settings.xml") ){ string graph_dir=xml.getAttribute("Rotor","graph_dir","",0); } else cerr<<"Rotor: settings.xml not found, using defaults"<= 400 ){ volHistory.erase(volHistory.begin(), volHistory.begin()+1); } } //-------------------------------------------------------------- void testApp::draw(){ ofSetColor(225); ofDrawBitmapString("AUDIO INPUT EXAMPLE", 32, 32); ofDrawBitmapString("press 's' to unpause the audio\n'e' to pause the audio", 31, 92); ofNoFill(); // draw the left channel: ofPushStyle(); ofPushMatrix(); ofTranslate(32, 170, 0); ofSetColor(225); ofDrawBitmapString("Left Channel", 4, 18); ofSetLineWidth(1); ofRect(0, 0, 512, 200); ofSetColor(245, 58, 135); ofSetLineWidth(3); ofBeginShape(); for (int i = 0; i < left.size()/2; i++){ ofVertex(i, 100 -left[i*2]*180.0f); } ofEndShape(false); ofPopMatrix(); ofPopStyle(); /* // draw the right channel: ofPushStyle(); ofPushMatrix(); ofTranslate(32, 370, 0); ofSetColor(225); ofDrawBitmapString("Right Channel", 4, 18); ofSetLineWidth(1); ofRect(0, 0, 512, 200); ofSetColor(245, 58, 135); ofSetLineWidth(3); ofBeginShape(); for (int i = 0; i < right.size()/2; i++){ ofVertex(i, 100 -right[i*2]*180.0f); } ofEndShape(false); ofPopMatrix(); ofPopStyle(); */ // draw the average volume: ofPushStyle(); ofPushMatrix(); ofTranslate(565, 170, 0); ofSetColor(225); ofDrawBitmapString("Scaled average vol (0-100): " + ofToString(scaledVol * 100.0, 0), 4, 18); ofRect(0, 0, 400, 400); ofSetColor(245, 58, 135); ofFill(); ofCircle(200, 200, scaledVol * 190.0f); //lets draw the volume history as a graph ofBeginShape(); for (int i = 0; i < volHistory.size(); i++){ if( i == 0 ) ofVertex(i, 400); ofVertex(i, 400 - volHistory[i] * 70); if( i == volHistory.size() -1 ) ofVertex(i, 400); } ofEndShape(false); //draw the features history as alternate polygons in a 400x400 box : 16 seconds @ 25fps ofPopMatrix(); ofPopStyle(); drawCounter++; ofSetColor(225); string reportString = "buffers received: "+ofToString(bufferCounter)+"\ndraw routines called: "+ofToString(drawCounter)+"\nticks: " + ofToString(soundStream.getTickCount()); reportString +="\nfeatures found: "+ofToString(vamphost.numFeat)+" average signal: "+ofToString(vamphost.avg)+" samples: "+ofToString(vamphost.num); ofDrawBitmapString(reportString, 32, 589); } void testApp::audioIn(float * input, int bufferSize, int nChannels){ float curVol = 0.0; // samples are "interleaved" int numCounted = 0; //lets go through each sample and calculate the root mean square which is a rough way to calculate volume for (int i = 0; i < bufferSize; i++){ //left[i] = input[i*2]*0.5; //right[i] = input[i*2+1]*0.5; left[i] = input[i]*0.5; curVol += left[i] * left[i]; //curVol += right[i] * right[i]; numCounted++; } //this is how we get the mean of rms :) curVol /= (float)numCounted; // this is how we get the root of rms :) curVol = sqrt( curVol ); smoothedVol *= 0.93; smoothedVol += 0.07 * curVol; bufferCounter++; //input would seem to be in the range 0..1 vamphost.process_frame(input,bufferSize); } //-------------------------------------------------------------- void testApp::exit(){ vamphost.cleanup(); } //-------------------------------------------------------------- void testApp::keyPressed(int key){ if( key == 's' ){ soundStream.start(); } if( key == 'e' ){ soundStream.stop(); } } //-------------------------------------------------------------- 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){ }