Mercurial > hg > precise-onset-detection
changeset 6:eb29c6b6dff8
added pointer version of visualiser
author | Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk> |
---|---|
date | Sun, 19 Jan 2014 23:07:13 +0000 |
parents | 1e636a3511fb |
children | b1c13e8bec26 |
files | ofxPreciseOnsetDetectorOffline/PointerOnsetVisualiser.cpp ofxPreciseOnsetDetectorOffline/PointerOnsetVisualiser.h ofxPreciseOnsetDetectorOffline/PreciseOnsetDetectorOffline.cpp ofxPreciseOnsetDetectorOffline/PreciseOnsetVisualiser.cpp ofxPreciseOnsetDetectorOffline/PreciseOnsetVisualiser.h ofxPreciseOnsetDetectorOffline/testApp.cpp src/PreciseOnsetLocator.cpp src/btrack_plus/accFFT.cpp |
diffstat | 8 files changed, 391 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ofxPreciseOnsetDetectorOffline/PointerOnsetVisualiser.cpp Sun Jan 19 23:07:13 2014 +0000 @@ -0,0 +1,225 @@ +/* + * PointerOnsetVisualiser.cpp + * GreenOnionsMidiBeatApp + * + * Created by Andrew on 14/01/2014. + * Copyright 2014 QMUL. All rights reserved. + * + */ + +#include "PointerOnsetVisualiser.h" + + +PointerOnsetVisualiser::PointerOnsetVisualiser(){ + +} + +PointerOnsetVisualiser::~PointerOnsetVisualiser(){ + printf("deleting pointer in visualiser\n"); + pod = NULL; + delete pod; + +// delete windowStart; +// delete windowEnd; +// delete windowPress; +} + +void PointerOnsetVisualiser::newFile(){ + resetWindow(); +// windowPress = 0; + + soundPlay.loadSound(pod->loadedFilename, false); + paused = true; + soundPlay.play(); + soundPlay.setPaused(true); +} + +double PointerOnsetVisualiser::windowWidth(){ + return (*windowEnd) - (*windowStart); +} + +void PointerOnsetVisualiser::update(){ + double positionNow = positionSeconds(); + if (positionNow > (*windowEnd)){ + double tmp = windowWidth(); + (*windowEnd) += tmp; + (*windowStart) += tmp; + //printf("Scrolling\n"); + } + +} + + +void PointerOnsetVisualiser::draw(){ + //if plotting use this, else comment out + + ofSetColor(ofColor::white); + window.drawBackground(); + ofSetColor(ofColor::black); + window.drawOutline(); + + //draw df function + /* + int startIndex = 0; + while (startIndex < (int)pod->dfValues.size() && pod->frameIndexToSeconds(startIndex) < (*windowStart)) + startIndex++; + + int endIndex = 0; + while (endIndex < (int)pod->dfValues.size()-1 && pod->frameIndexToSeconds(endIndex) < (*windowEnd)) + endIndex++; + */ + ofSetColor(ofColor::tan); + // plotter.drawVector(pod->dfValues, startIndex, endIndex, window); + plotter.drawVector(pod->dfValues, round(pod->secondsToFrameIndex((*windowStart))), round(pod->secondsToFrameIndex((*windowEnd))), window); + ofSetColor(ofColor::black); + ofDrawBitmapString(ofToString(round(pod->secondsToFrameIndex((*windowStart))), 1), window.x, window.y-10); + ofDrawBitmapString(ofToString(round(pod->secondsToFrameIndex((*windowEnd))), 1), window.x+window.width, window.y-10); + + ofSetColor(ofColor::blue); + plotter.drawBeatStripes(pod->onsetLocations, window, (*windowStart), (*windowEnd)); + + //play position + ofSetColor(ofColor::red); + plotter.drawStripe(positionSeconds(), window, (*windowStart), (*windowEnd)); + + ofSetColor(ofColor::black); + ofDrawBitmapString(ofToString((*windowStart), 1), window.x, window.y+window.height+10); + ofDrawBitmapString(ofToString((*windowEnd), 1), window.x+window.width, window.y+window.height+10); + +} + +double PointerOnsetVisualiser::positionSeconds(){ + return soundPlay.getPosition()*pod->samples/44100.; +} + +//void PointerOnsetVisualiser::drawOnsets(DoubleVector& onsetTimesSeconds, ofxWindowregion& window, double startTime, double endTime){ +//} + +void PointerOnsetVisualiser::resetWindow(){ + (*windowStart) = 0; + (*windowEnd) = 8; + // while ((*windowEnd) < pod->samples/44100.) + // (*windowEnd) *= 2; + + (*windowEnd) = pod->samples/44100.; + + printf("reset: start %.1f end %.1f\n", (*windowStart), (*windowEnd)); +} + +void PointerOnsetVisualiser::cropStart(){ + if (soundPlay.getPositionMS()/1000. < (*windowEnd)){ + (*windowStart) = soundPlay.getPositionMS()/1000.; + printf("s: start %.1f end %.1f\n", (*windowStart), (*windowEnd)); + } +} + +void PointerOnsetVisualiser::cropStartSeconds(double& val){ + if (val < (*windowEnd)) + (*windowStart) = val; +} + +void PointerOnsetVisualiser::cropEnd(){//crops to play position + + if (soundPlay.getPositionMS()/1000. > (*windowStart)){ + (*windowEnd) = soundPlay.getPositionMS()/1000.; + printf("crop end: start %.1f end %.1f\n", (*windowStart), (*windowEnd)); + } +} + + +void PointerOnsetVisualiser::cropEndSeconds(double& val){ + if (val > (*windowStart)) + (*windowEnd) = val; + + printf("crop end: start %.1f end %.1f\n", (*windowStart), (*windowEnd)); +} + + +void PointerOnsetVisualiser::mousePressed(int& x, int& y){ + /* + if (window.tapped(x, y)){ + windowPress = (*windowStart) + ((*windowEnd)-(*windowStart))*(x - window.x)/window.width; + double newPos = windowPress/(double)(pod->samples/44100.); + printf("window position is %.1f new pos %f\n", windowPress, newPos); + soundPlay.setPositionMS(windowPress*1000.0); + } + */ +} + +void PointerOnsetVisualiser::setSoundPositionSeconds(double position){ + printf("set position, was %i, new pos %f\n", soundPlay.getPositionMS(), position); + soundPlay.setPositionMS(position*1000.0); + printf("new position %i\n", soundPlay.getPositionMS()); +} + +void PointerOnsetVisualiser::togglePlay(){ + if (!paused ){ + soundPlay.setPaused(true); + paused = true; + printf("was playing\n"); + } + else { + soundPlay.setPaused(false);// + paused = false; + printf("was not playing\n"); + } +} + +void PointerOnsetVisualiser::stop(){ + soundPlay.stop(); + //then get set to be played + soundPlay.play(); + soundPlay.setPaused(true); + soundPlay.setPositionMS((*windowStart)*1000.0); + paused = true; +} + +void PointerOnsetVisualiser::zoomIn(){ + double positionNow = positionSeconds(); + if (positionNow > (*windowEnd)){ + double tmp = windowWidth(); + (*windowEnd) += windowWidth(); + (*windowStart) += tmp; + } + + (*windowStart) = positionNow - ((*windowEnd)-(*windowStart))/4; + if ((*windowStart) < 0) + (*windowStart) = 0; + (*windowEnd) = positionNow + ((*windowEnd)-(*windowStart))/4; +} + + +void PointerOnsetVisualiser::zoomOut(){ + double positionNow = positionSeconds(); + if (positionNow > (*windowEnd)){ + double tmp = windowWidth(); + (*windowEnd) += tmp; + (*windowStart) += tmp; + } + + (*windowStart) = positionNow - ((*windowEnd)-(*windowStart)); + (*windowEnd) = positionNow + ((*windowEnd)-(*windowStart)); + if ((*windowStart) < 0) + (*windowStart) = 0; +} + +void PointerOnsetVisualiser::scrollLeft(){ + double tmp = windowWidth(); + (*windowStart) = max(0., (*windowStart) - windowWidth()/2.); + (*windowEnd) = (*windowStart) + tmp; + checkPosition(); +} + + +void PointerOnsetVisualiser::scrollRight(){ + double tmp = windowWidth(); + (*windowStart) = min( (*windowStart)+tmp/2., pod->samples/44100.); + (*windowEnd) = (*windowStart) + tmp; + checkPosition(); +} + +void PointerOnsetVisualiser::checkPosition(){ + double positionNow = positionSeconds(); + if (positionNow < (*windowStart) || positionNow > (*windowEnd)) + soundPlay.setPositionMS((*windowStart)*1000); +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ofxPreciseOnsetDetectorOffline/PointerOnsetVisualiser.h Sun Jan 19 23:07:13 2014 +0000 @@ -0,0 +1,64 @@ +/* + * PointerOnsetVisualiser.h + * GreenOnionsMidiBeatApp + * + * Created by Andrew on 14/01/2014. + * Copyright 2014 QMUL. All rights reserved. + * + */ + +//only change with pointer_onset_vis - it follows a NON-POINTER PreciseOnsetVisualiser + +#ifndef POINTER_ONSET_VISUALISER +#define PPOINTER_ONSET_VISUALISER + +#include "PreciseOnsetDetectorOffline.h" + +#include "ofxWindowRegion.h" +#include "ofxPlotFunction.h" + +class PointerOnsetVisualiser{ +public: + PointerOnsetVisualiser(); + ~PointerOnsetVisualiser(); + + void newFile(); + void update(); + void draw(); + double positionSeconds(); + double windowWidth(); + + void mousePressed(int& x, int& y); + void togglePlay(); + void stop(); + + void resetWindow(); + void cropStart(); + void cropEnd(); + void cropStartSeconds(double& val); + void cropEndSeconds(double& val); + + void zoomIn(); + void zoomOut(); + + void scrollLeft(); + void scrollRight(); + void checkPosition(); + + //ew fn + void setSoundPositionSeconds(double position); + //vars + PreciseOnsetDetectorOffline* pod; + ofSoundPlayer soundPlay; + bool paused; + // void drawOnsets(DoubleVector& onsetTimesSeconds, ofxWindowregion& window, double startTime, double endTime); + + ofxWindowRegion window; + ofxPlotFunction plotter; + + //this is the only change with pointer_onset_vis - it follows a NON-POINTER PreciseOnsetVisualiser + double *windowStart; + double *windowEnd; + double *windowPress; +}; +#endif \ No newline at end of file
--- a/ofxPreciseOnsetDetectorOffline/PreciseOnsetDetectorOffline.cpp Mon Jan 06 18:10:15 2014 +0000 +++ b/ofxPreciseOnsetDetectorOffline/PreciseOnsetDetectorOffline.cpp Sun Jan 19 23:07:13 2014 +0000 @@ -12,6 +12,8 @@ #include "PreciseOnsetDetectorOffline.h" +const bool printingOn = false; + PreciseOnsetDetectorOffline::PreciseOnsetDetectorOffline(){ frameSize = 1024; hopSize = 512; @@ -20,7 +22,7 @@ } PreciseOnsetDetectorOffline::~PreciseOnsetDetectorOffline(){ - + //delete infile; } @@ -120,10 +122,11 @@ dfValues.push_back(dfval); - printf("det val %i: %f\n", counter, dfval); + if (printingOn) + printf("det val %i: %f\n", counter, dfval); if (peakProcess.peakProcessing(dfval)){ - printf("BANG\n"); + onsetPositionFrames.push_back(counter); int precisesample = preciseLocator.findExactOnset(&buffer[0]); //so exact sample is @@ -134,6 +137,9 @@ onsetLocations.push_back(exactsample/44100.); + + if (printingOn) + printf("BANG\n"); } counter++; @@ -149,6 +155,8 @@ delete detectionFunction; detectionFunction = NULL; + printf("Number of samples%i\n", samples); + return 0; }
--- a/ofxPreciseOnsetDetectorOffline/PreciseOnsetVisualiser.cpp Mon Jan 06 18:10:15 2014 +0000 +++ b/ofxPreciseOnsetDetectorOffline/PreciseOnsetVisualiser.cpp Sun Jan 19 23:07:13 2014 +0000 @@ -15,8 +15,9 @@ PreciseOnsetVisualiser::~PreciseOnsetVisualiser(){ printf("deleting pointer in visualiser\n"); + pod = NULL; delete pod; - pod = NULL; + } void PreciseOnsetVisualiser::newFile(){ @@ -24,9 +25,10 @@ windowPress = 0; soundPlay.loadSound(pod->loadedFilename, false); - paused = true; - soundPlay.play(); - soundPlay.setPaused(true); + stop(); +// paused = true; +// soundPlay.play(); +// soundPlay.setPaused(true); } double PreciseOnsetVisualiser::windowWidth(){ @@ -34,8 +36,8 @@ } void PreciseOnsetVisualiser::update(){ - double positionNow = positionSeconds(); - if (positionNow > windowEnd){ + currentPlayPosition = positionSeconds(); + if (currentPlayPosition > windowEnd){ double tmp = windowWidth(); windowEnd += tmp; windowStart += tmp; @@ -205,8 +207,50 @@ checkPosition(); } +void PreciseOnsetVisualiser::scrollRightSecs(double secs){ + double positionNow = positionSeconds(); + double newPosition = min(positionNow+secs, pod->samples/44100.); + soundPlay.setPositionMS(newPosition*1000.); + double tmp = windowWidth()/2.; + while (windowEnd < newPosition){ + windowEnd += tmp; + windowStart += tmp; + } +} + + +void PreciseOnsetVisualiser::scrollLeftSecs(double secs){ + double positionNow = positionSeconds(); + double newPosition = max(positionNow-secs, 0.); + soundPlay.setPositionMS(newPosition*1000.); + double tmp = windowWidth()/2.; + while (windowStart > newPosition){ + windowEnd -= tmp; + windowStart -= tmp; + } +} + + void PreciseOnsetVisualiser::checkPosition(){ double positionNow = positionSeconds(); if (positionNow < windowStart || positionNow > windowEnd) - soundPlay.setPositionMS(windowStart*1000); -} \ No newline at end of file + soundPlay.setPositionMS(windowStart*1000.); +} + + +void PreciseOnsetVisualiser::setPositionSeconds(double secs){ + soundPlay.setPositionMS(secs*1000.); + double tmp = windowEnd - windowStart; + while (windowStart > max(0. , secs)){ + windowStart -= tmp; + windowEnd -= tmp; + } + while (windowEnd < min(pod->samples/44100. , secs)){ + windowStart += tmp; + windowEnd += tmp; + } +} + +double PreciseOnsetVisualiser::lengthSeconds(){ + return pod->samples/44100.; +}
--- a/ofxPreciseOnsetDetectorOffline/PreciseOnsetVisualiser.h Mon Jan 06 18:10:15 2014 +0000 +++ b/ofxPreciseOnsetDetectorOffline/PreciseOnsetVisualiser.h Sun Jan 19 23:07:13 2014 +0000 @@ -41,7 +41,13 @@ void scrollLeft(); void scrollRight(); + void scrollRightSecs(double secs); + void scrollLeftSecs(double secs); + void checkPosition(); + void setPositionSeconds(double secs); + + double lengthSeconds(); //vars PreciseOnsetDetectorOffline* pod; @@ -53,5 +59,7 @@ ofxPlotFunction plotter; double windowStart, windowEnd, windowPress; + + double currentPlayPosition; }; #endif \ No newline at end of file
--- a/ofxPreciseOnsetDetectorOffline/testApp.cpp Mon Jan 06 18:10:15 2014 +0000 +++ b/ofxPreciseOnsetDetectorOffline/testApp.cpp Sun Jan 19 23:07:13 2014 +0000 @@ -9,7 +9,10 @@ // preciseOnsetDetect.load("/Users/andrew/Documents/work/programming/MadMax/AudioFiles/AdamBetts/AdamBetss_1_Swing_Kick.wav"); // preciseOnsetDetect.load("/Users/andrew/Music/Logic/GreenOnionsChichester/GreenOnionsChichester/Bouncing/Snare_Sontronics#08edit.aif"); - loadNewFile("/Users/andrew/Music/Logic/GreenOnionsChichester/GreenOnionsChichester/Audio Files/Ride_SM58#08.aif"); + + std::string fileName = "/Users/andrew/Music/Logic/GreenOnionsEvaluation/GreenOnionsEvaluationPlain/Audio Files/SongClickTrack#09.aif"; +// fileName = "/Users/andrew/Music/Logic/GreenOnionsChichester/GreenOnionsChichester/Audio Files/Ride_SM58#08.aif"; + loadNewFile(fileName); } @@ -48,10 +51,15 @@ case 'e': pov.cropEnd(); break; - case 'x': + case 'w': printf("Exporting between %f and %f\n", pov.windowStart, pov.windowEnd); preciseOnsetDetect.exportOnsetTimes(pov.windowStart, pov.windowEnd); break; + case 'x': + printf("Exporting between %f and %f\n", 0., pov.lengthSeconds()); + preciseOnsetDetect.exportOnsetTimes(0, pov.lengthSeconds()); + break; + case 'o': if (getFilenameFromDialogBox(&loadName)){ printf("loading %s\n", (loadName).c_str()); @@ -66,6 +74,19 @@ case OF_KEY_RETURN: pov.soundPlay.stop(); break; + + case OF_KEY_UP: + pov.zoomIn(); + break; + case OF_KEY_DOWN: + pov.zoomOut(); + break; + case OF_KEY_RIGHT: + pov.scrollRight(); + break; + case OF_KEY_LEFT: + pov.scrollLeft(); + break; default: break;
--- a/src/PreciseOnsetLocator.cpp Mon Jan 06 18:10:15 2014 +0000 +++ b/src/PreciseOnsetLocator.cpp Sun Jan 19 23:07:13 2014 +0000 @@ -103,12 +103,13 @@ double PreciseOnsetLocator::getLastEnergySum(const int& startIndex, const int& vectorSize){ double lastEnergySum = 0; - - for (int i = startIndex - vectorSize;i < startIndex;i++){ - if (i > 0) - lastEnergySum += onsetSamples[i] * onsetSamples[i]; - else { - lastEnergySum += recentBufferSamples[bufferSize + i] * recentBufferSamples[bufferSize + i]; + if (bufferSize + startIndex < recentBufferSamples.size()){ + for (int i = startIndex - vectorSize;i < startIndex;i++){ + if (i > 0) + lastEnergySum += onsetSamples[i] * onsetSamples[i]; + else { + lastEnergySum += recentBufferSamples[bufferSize + i] * recentBufferSamples[bufferSize + i]; + } } } return lastEnergySum;