andrew@2: /* andrew@2: * PreciseOnsetDetectorOffline.h andrew@2: * ofxPreciseOnsetDetectionOffline andrew@2: * andrew@2: * Created by Andrew Robertson on 25/12/2013. andrew@2: * Copyright 2013 QMUL. All rights reserved. andrew@2: * andrew@2: */ andrew@2: andrew@2: Venetian@7: #ifndef PRECISE_ONSET_DETECTOR_OFFLINE Venetian@7: #define PRECISE_ONSET_DETECTOR_OFFLINE andrew@2: andrew@2: #include "OnsetDetectionFunction.h" andrew@2: #include "vector.h" andrew@2: #include "ofMain.h" andrew@2: #include "sndfile.h" andrew@2: andrew@2: #include "PeakProcessor.h" andrew@2: #include "PreciseOnsetLocator.h" andrew@2: Venetian@7: #include "AudioRingBuffer.h" Venetian@7: andrew@2: #include "BeatWriter.h" andrew@2: Venetian@7: struct OnsetInfo{ Venetian@7: //double dfValue; Venetian@7: double onsetLocation;//of exact time in seconds Venetian@7: int positionFrames; Venetian@7: int positionSamples;//exact time in samples Venetian@7: //this for bass onsets Venetian@7: float pitch;//freq in Hz Venetian@7: float midiPitch;//in Midi as float Venetian@7: int roundedPitch;//rounded to nearest MIDI Venetian@7: int midiPrediction;//prediction according to naive ICMC 2014 method at optimal lag (determined here) Venetian@7: int markovMidiPrediction;//prediction according to first markov ICMC 2014 method at optimal lag (determined here) Venetian@7: Venetian@7: Venetian@7: int barPosition;//ignore Venetian@7: int beatPosition;//in beats Venetian@7: int onsetType;//0-11 where 0 is on beat, 6 is halfbeat etc Venetian@7: Venetian@7: float matchIndicator;//? Venetian@7: Venetian@7: std::string midiName;//eg C#3 Venetian@7: Venetian@7: bool onBeat;//is it near a beat - need to call testOnsetCloseToBeat and give a list of beat times in seconds Venetian@7: Venetian@7: float expressiveTiming; Venetian@7: }; Venetian@7: Venetian@7: andrew@2: class PreciseOnsetDetectorOffline{ andrew@2: public: andrew@2: PreciseOnsetDetectorOffline(); andrew@2: ~PreciseOnsetDetectorOffline(); andrew@2: andrew@2: andrew@4: int load(std::string filename);//returns 0 for completed loading andrew@2: void update(); andrew@2: void draw(); andrew@2: Venetian@7: void initialise(); Venetian@7: void processAudioFrame(float* frame, int n); Venetian@7: Venetian@7: void setDfType(int t); Venetian@7: Venetian@7: void clearAll(); Venetian@7: virtual int processAudioFileForBeatTimes(std::string audiofile); Venetian@7: Venetian@7: void endProcessing(); Venetian@7: andrew@3: void exportOnsetTimes(); andrew@3: void exportOnsetTimes(double startTime, double endTime); andrew@3: andrew@4: typedef std::vector DoubleVector; andrew@4: void loadOnsetLocations(DoubleVector& beats); andrew@4: andrew@4: double frameIndexToSeconds(const int& frame); andrew@4: double secondsToFrameIndex(const double& seconds); andrew@3: double closestOnset(double& targetVal); andrew@2: Venetian@7: virtual void printOnsetLocations(); Venetian@7: double onsetAtIndex(int index); andrew@2: Venetian@7: void cropStartTo(double startTime); Venetian@7: Venetian@7: void setMinimumThreshold(float fVal); Venetian@7: Venetian@7: double beatAtIndex(std::vector beatTimes, int beatIndex); Venetian@7: Venetian@7: void categoriseOnsets(std::vector beatTimes); Venetian@7: void doCorrection(int& beattype, int& beatPosition); Venetian@7: Venetian@7: // void testOnsetsCloseToBeats(std::vector beatTimes); Venetian@7: int onsetAtBeat(int testPosition); Venetian@7: andrew@2: //vars andrew@2: int frameSize; andrew@2: int hopSize; andrew@2: int samples;//number of samples andrew@2: andrew@2: SNDFILE *infile; // define input and output sound files andrew@2: SF_INFO sfinfo ; // struct to hold info about sound file andrew@2: andrew@2: std::string loadedFilename; andrew@2: andrew@2: OnsetDetectionFunction* detectionFunction; andrew@2: andrew@2: PeakProcessor peakProcess; andrew@2: PreciseOnsetLocator preciseLocator; andrew@2: andrew@2: std::vector dfValues; Venetian@7: /* andrew@2: std::vector onsetLocations;//of exact time in seconds andrew@2: std::vector onsetPositionFrames; Venetian@7: std::vector onsetPositionSamples; Venetian@7: */ Venetian@7: std::vector onsetList; andrew@2: andrew@2: bool writeOutput;//write output to txt Venetian@7: Venetian@7: int dfType; Venetian@7: Venetian@7: AudioRingBuffer* ringbuffer; Venetian@7: Venetian@7: int sampleCount; Venetian@7: int frameCount; Venetian@7: bool isBass; Venetian@7: private: Venetian@7: bool initialised; Venetian@7: andrew@2: }; andrew@2: #endif