changeset 4:93b9a9471011

Changes to precise onset
author Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk>
date Mon, 06 Jan 2014 18:10:01 +0000
parents 50f62c48b421
children 1e636a3511fb
files ofxPreciseOnsetDetectorOffline/PreciseOnsetDetectorOffline.cpp ofxPreciseOnsetDetectorOffline/PreciseOnsetDetectorOffline.h ofxPreciseOnsetDetectorOffline/PreciseOnsetVisualiser.cpp ofxPreciseOnsetDetectorOffline/PreciseOnsetVisualiser.h src/PeakProcessor.cpp src/PreciseOnsetLocator.cpp src/btrack_plus/OnsetDetectionFunction.h
diffstat 7 files changed, 126 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/ofxPreciseOnsetDetectorOffline/PreciseOnsetDetectorOffline.cpp	Fri Jan 03 17:43:02 2014 +0000
+++ b/ofxPreciseOnsetDetectorOffline/PreciseOnsetDetectorOffline.cpp	Mon Jan 06 18:10:01 2014 +0000
@@ -24,12 +24,12 @@
 }
 
 
-void PreciseOnsetDetectorOffline::load(std::string filename){
+int PreciseOnsetDetectorOffline::load(std::string filename){
 	
 	//name for output file is same dir and filename as aif/wav but with _preciseOnsets.txt added
 	//eg 'song.wav' is 'song.wav_preciseOnsets.txt'
 	
-	processAudioForBeatTimes(filename);
+	return processAudioForBeatTimes(filename);
 }
 
 
@@ -137,7 +137,7 @@
 		}
 		
 		counter++;
-		printf("read %i samples\n", readcount);
+		//printf("read %i samples\n", readcount);
 		//was	sf_write_double(outfile, frame, readcount) ;
 		
 	}//end readcount
@@ -153,6 +153,15 @@
 	
 }
 
+double PreciseOnsetDetectorOffline::frameIndexToSeconds(const int& frameIndex){
+	return ((double)(frameIndex*hopSize) /44100.);//- (detectionFunction.framesize/2)?;
+}
+
+double PreciseOnsetDetectorOffline::secondsToFrameIndex(const double& seconds){
+	return (seconds*44100./(double)hopSize );//- (detectionFunction.framesize/2)?;
+}
+
+
 void PreciseOnsetDetectorOffline::exportOnsetTimes(){
 	exportOnsetTimes(0.0, samples/44100.0);//i.e. the whole file
 }
@@ -210,3 +219,10 @@
 	return bestVal;
 }
 
+void PreciseOnsetDetectorOffline::loadOnsetLocations(DoubleVector& beats){
+	//replaces onset locations with new vector
+	onsetLocations.clear();
+	for (int i = 0; i < beats.size(); i++){
+		onsetLocations.push_back(beats[i]);
+	}
+}
\ No newline at end of file
--- a/ofxPreciseOnsetDetectorOffline/PreciseOnsetDetectorOffline.h	Fri Jan 03 17:43:02 2014 +0000
+++ b/ofxPreciseOnsetDetectorOffline/PreciseOnsetDetectorOffline.h	Mon Jan 06 18:10:01 2014 +0000
@@ -27,7 +27,7 @@
 	~PreciseOnsetDetectorOffline();
 	
 	
-	void load(std::string filename);
+	int load(std::string filename);//returns 0 for completed loading
 	void update();
 	void draw();
 	
@@ -35,6 +35,11 @@
 	void exportOnsetTimes();
 	void exportOnsetTimes(double startTime, double endTime);
 
+	typedef std::vector<double> DoubleVector;
+	void loadOnsetLocations(DoubleVector& beats);
+
+	double frameIndexToSeconds(const int& frame);
+	double secondsToFrameIndex(const double& seconds);
 	double closestOnset(double& targetVal);
 	
 	void printOnsetLocations();
--- a/ofxPreciseOnsetDetectorOffline/PreciseOnsetVisualiser.cpp	Fri Jan 03 17:43:02 2014 +0000
+++ b/ofxPreciseOnsetDetectorOffline/PreciseOnsetVisualiser.cpp	Mon Jan 06 18:10:01 2014 +0000
@@ -29,10 +29,22 @@
 	soundPlay.setPaused(true);
 }
 
+double PreciseOnsetVisualiser::windowWidth(){
+	return windowEnd - windowStart;
+}
+
 void PreciseOnsetVisualiser::update(){
+	double positionNow = positionSeconds();
+	if (positionNow > windowEnd){
+		double tmp = windowWidth();
+		windowEnd += tmp;
+		windowStart += tmp;
+		//printf("Scrolling\n");
+	}
 
 }
 
+
 void PreciseOnsetVisualiser::draw(){
 	//if plotting use this, else comment out
 
@@ -40,12 +52,35 @@
 	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 PreciseOnsetVisualiser::positionSeconds(){
@@ -124,4 +159,54 @@
 	soundPlay.setPaused(true);
 	soundPlay.setPositionMS(windowStart*1000.0);
 	paused = true;
+}
+
+void PreciseOnsetVisualiser::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 PreciseOnsetVisualiser::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 PreciseOnsetVisualiser::scrollLeft(){
+	double tmp = windowWidth();
+	windowStart = max(0., windowStart - windowWidth()/2.);
+	windowEnd = windowStart + tmp;
+	checkPosition();
+}
+
+
+void PreciseOnsetVisualiser::scrollRight(){
+	double tmp = windowWidth();
+	windowStart = min( windowStart+tmp/2., pod->samples/44100.);
+	windowEnd = windowStart + tmp;
+	checkPosition();
+}
+
+void PreciseOnsetVisualiser::checkPosition(){
+double positionNow = positionSeconds();
+	if (positionNow < windowStart || positionNow > windowEnd)
+		soundPlay.setPositionMS(windowStart*1000);
 }
\ No newline at end of file
--- a/ofxPreciseOnsetDetectorOffline/PreciseOnsetVisualiser.h	Fri Jan 03 17:43:02 2014 +0000
+++ b/ofxPreciseOnsetDetectorOffline/PreciseOnsetVisualiser.h	Mon Jan 06 18:10:01 2014 +0000
@@ -24,6 +24,7 @@
 	void update();
 	void draw();
 	double positionSeconds();
+	double windowWidth();
 	
 	void mousePressed(int& x, int& y);
 	void togglePlay();
@@ -35,6 +36,13 @@
 	void cropStartSeconds(double& val);
 	void cropEndSeconds(double& val);
 	
+	void zoomIn();
+	void zoomOut();
+	
+	void scrollLeft();
+	void scrollRight();
+	void checkPosition();
+	
 	//vars
 	PreciseOnsetDetectorOffline* pod;
 	ofSoundPlayer soundPlay;
--- a/src/PeakProcessor.cpp	Fri Jan 03 17:43:02 2014 +0000
+++ b/src/PeakProcessor.cpp	Mon Jan 06 18:10:01 2014 +0000
@@ -9,7 +9,7 @@
 
 #include "PeakProcessor.h"
 
-const bool printingOn = true;//false;
+const bool printingOn = false;//true;//false;
 
 PeakProcessor::PeakProcessor(){
 	
@@ -20,9 +20,9 @@
 	numberOfDetectionValuesToTest = 10;
 	currentFrame = 0;
 	cutoffForRepeatOnsetsFrames = 4;
-	detectionTriggerRatio = 0.5f;
-	detectionTriggerThreshold = 5;//0.1;
-	bestSlopeMedian = 8;
+	detectionTriggerRatio = 0.34f;//was 0.5
+	detectionTriggerThreshold = 1.5;//0.1;
+	bestSlopeMedian = 3;
 	thresholdRelativeToMedian = 1.1;
 	slopeFallenBelowMedian = true;
 	lastSlopeOnsetFrame = 0;
--- a/src/PreciseOnsetLocator.cpp	Fri Jan 03 17:43:02 2014 +0000
+++ b/src/PreciseOnsetLocator.cpp	Mon Jan 06 18:10:01 2014 +0000
@@ -9,7 +9,7 @@
 
 #include "PreciseOnsetLocator.h"
 
-const bool printingOn = true;
+const bool printingOn = false;//true;
 
 PreciseOnsetLocator::PreciseOnsetLocator(){
 	setup(512);
--- a/src/btrack_plus/OnsetDetectionFunction.h	Fri Jan 03 17:43:02 2014 +0000
+++ b/src/btrack_plus/OnsetDetectionFunction.h	Mon Jan 06 18:10:01 2014 +0000
@@ -26,6 +26,8 @@
 	double getDFsample(double inputbuffer[]);												// process input buffer and calculate detection function sample
 	void set_df_type(int arg_df_type);														// set the detection function type
 	
+	int framesize;																			// audio framesize
+	int hopsize;																			// audio hopsize
 private:
 	
 	void perform_FFT();																		// perform the FFT on the data in 'frame'
@@ -52,9 +54,7 @@
 	
 	
 	double pi;																				// pi, the constant
-	
-	int framesize;																			// audio framesize
-	int hopsize;																			// audio hopsize	
+																				
 	int df_type;																			// type of detection function
 	
     accFFT *fft;