view ofxPreciseOnsetDetectorOffline/PreciseOnsetDetectorOffline.h @ 7:b1c13e8bec26

adding new files
author Venetian
date Thu, 14 Aug 2014 16:27:52 +0100
parents 93b9a9471011
children
line wrap: on
line source
/*
 *  PreciseOnsetDetectorOffline.h
 *  ofxPreciseOnsetDetectionOffline
 *
 *  Created by Andrew Robertson on 25/12/2013.
 *  Copyright 2013 QMUL. All rights reserved.
 *
 */


#ifndef PRECISE_ONSET_DETECTOR_OFFLINE
#define PRECISE_ONSET_DETECTOR_OFFLINE

#include "OnsetDetectionFunction.h"
#include "vector.h"
#include "ofMain.h"
#include "sndfile.h"

#include "PeakProcessor.h"
#include "PreciseOnsetLocator.h"

#include "AudioRingBuffer.h"

#include "BeatWriter.h"

struct OnsetInfo{
	//double dfValue;
	double onsetLocation;//of exact time in seconds
	int positionFrames;
	int positionSamples;//exact time in samples
	//this for bass onsets
	float pitch;//freq in Hz
	float midiPitch;//in Midi as float
	int roundedPitch;//rounded to nearest MIDI
	int midiPrediction;//prediction according to naive ICMC 2014 method at optimal lag (determined here)
	int markovMidiPrediction;//prediction according to first markov ICMC 2014 method at optimal lag (determined here)
	
	
	int barPosition;//ignore
	int beatPosition;//in beats
	int onsetType;//0-11 where 0 is on beat, 6 is halfbeat etc
	
	float matchIndicator;//?
	
	std::string midiName;//eg C#3
	
	bool onBeat;//is it near a beat - need to call testOnsetCloseToBeat and give a list of beat times in seconds
	
	float expressiveTiming;
};


class PreciseOnsetDetectorOffline{
public:
	PreciseOnsetDetectorOffline();
	~PreciseOnsetDetectorOffline();
	
	
	int load(std::string filename);//returns 0 for completed loading
	void update();
	void draw();
	
	void initialise();
	void processAudioFrame(float* frame, int n);
	
	void setDfType(int t);
	
	void clearAll();
	virtual int processAudioFileForBeatTimes(std::string audiofile);
	
	void endProcessing();
	
	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);
	
	virtual void printOnsetLocations();
	double onsetAtIndex(int index);
	
	void cropStartTo(double startTime);
	
	void setMinimumThreshold(float fVal);
	
	double beatAtIndex(std::vector<double> beatTimes, int beatIndex);
	
	void categoriseOnsets(std::vector<double> beatTimes);
	void doCorrection(int& beattype, int& beatPosition);
	
//	void testOnsetsCloseToBeats(std::vector<double> beatTimes);
	int onsetAtBeat(int testPosition);
					
	//vars
	int frameSize;
	int hopSize;
	int samples;//number of samples
	
	SNDFILE *infile; // define input and output sound files
	SF_INFO sfinfo ; // struct to hold info about sound file
	
	std::string loadedFilename;
	
	OnsetDetectionFunction* detectionFunction;
	
	PeakProcessor peakProcess;
	PreciseOnsetLocator preciseLocator;
	
	std::vector<double> dfValues;
	/*
	std::vector<double> onsetLocations;//of exact time in seconds
	std::vector<int> onsetPositionFrames;
	std::vector<int> onsetPositionSamples;
	*/
	std::vector<OnsetInfo> onsetList;
	
	bool writeOutput;//write output to txt
	
	int dfType;
	
	AudioRingBuffer* ringbuffer;
	
	int sampleCount;
	int frameCount;
	bool isBass;
private:	
	bool initialised;

};
#endif