andrew@2
|
1 /*
|
andrew@2
|
2 * PreciseOnsetDetectorOffline.h
|
andrew@2
|
3 * ofxPreciseOnsetDetectionOffline
|
andrew@2
|
4 *
|
andrew@2
|
5 * Created by Andrew Robertson on 25/12/2013.
|
andrew@2
|
6 * Copyright 2013 QMUL. All rights reserved.
|
andrew@2
|
7 *
|
andrew@2
|
8 */
|
andrew@2
|
9
|
andrew@2
|
10
|
Venetian@7
|
11 #ifndef PRECISE_ONSET_DETECTOR_OFFLINE
|
Venetian@7
|
12 #define PRECISE_ONSET_DETECTOR_OFFLINE
|
andrew@2
|
13
|
andrew@2
|
14 #include "OnsetDetectionFunction.h"
|
andrew@2
|
15 #include "vector.h"
|
andrew@2
|
16 #include "ofMain.h"
|
andrew@2
|
17 #include "sndfile.h"
|
andrew@2
|
18
|
andrew@2
|
19 #include "PeakProcessor.h"
|
andrew@2
|
20 #include "PreciseOnsetLocator.h"
|
andrew@2
|
21
|
Venetian@7
|
22 #include "AudioRingBuffer.h"
|
Venetian@7
|
23
|
andrew@2
|
24 #include "BeatWriter.h"
|
andrew@2
|
25
|
Venetian@7
|
26 struct OnsetInfo{
|
Venetian@7
|
27 //double dfValue;
|
Venetian@7
|
28 double onsetLocation;//of exact time in seconds
|
Venetian@7
|
29 int positionFrames;
|
Venetian@7
|
30 int positionSamples;//exact time in samples
|
Venetian@7
|
31 //this for bass onsets
|
Venetian@7
|
32 float pitch;//freq in Hz
|
Venetian@7
|
33 float midiPitch;//in Midi as float
|
Venetian@7
|
34 int roundedPitch;//rounded to nearest MIDI
|
Venetian@7
|
35 int midiPrediction;//prediction according to naive ICMC 2014 method at optimal lag (determined here)
|
Venetian@7
|
36 int markovMidiPrediction;//prediction according to first markov ICMC 2014 method at optimal lag (determined here)
|
Venetian@7
|
37
|
Venetian@7
|
38
|
Venetian@7
|
39 int barPosition;//ignore
|
Venetian@7
|
40 int beatPosition;//in beats
|
Venetian@7
|
41 int onsetType;//0-11 where 0 is on beat, 6 is halfbeat etc
|
Venetian@7
|
42
|
Venetian@7
|
43 float matchIndicator;//?
|
Venetian@7
|
44
|
Venetian@7
|
45 std::string midiName;//eg C#3
|
Venetian@7
|
46
|
Venetian@7
|
47 bool onBeat;//is it near a beat - need to call testOnsetCloseToBeat and give a list of beat times in seconds
|
Venetian@7
|
48
|
Venetian@7
|
49 float expressiveTiming;
|
Venetian@7
|
50 };
|
Venetian@7
|
51
|
Venetian@7
|
52
|
andrew@2
|
53 class PreciseOnsetDetectorOffline{
|
andrew@2
|
54 public:
|
andrew@2
|
55 PreciseOnsetDetectorOffline();
|
andrew@2
|
56 ~PreciseOnsetDetectorOffline();
|
andrew@2
|
57
|
andrew@2
|
58
|
andrew@4
|
59 int load(std::string filename);//returns 0 for completed loading
|
andrew@2
|
60 void update();
|
andrew@2
|
61 void draw();
|
andrew@2
|
62
|
Venetian@7
|
63 void initialise();
|
Venetian@7
|
64 void processAudioFrame(float* frame, int n);
|
Venetian@7
|
65
|
Venetian@7
|
66 void setDfType(int t);
|
Venetian@7
|
67
|
Venetian@7
|
68 void clearAll();
|
Venetian@7
|
69 virtual int processAudioFileForBeatTimes(std::string audiofile);
|
Venetian@7
|
70
|
Venetian@7
|
71 void endProcessing();
|
Venetian@7
|
72
|
andrew@3
|
73 void exportOnsetTimes();
|
andrew@3
|
74 void exportOnsetTimes(double startTime, double endTime);
|
andrew@3
|
75
|
andrew@4
|
76 typedef std::vector<double> DoubleVector;
|
andrew@4
|
77 void loadOnsetLocations(DoubleVector& beats);
|
andrew@4
|
78
|
andrew@4
|
79 double frameIndexToSeconds(const int& frame);
|
andrew@4
|
80 double secondsToFrameIndex(const double& seconds);
|
andrew@3
|
81 double closestOnset(double& targetVal);
|
andrew@2
|
82
|
Venetian@7
|
83 virtual void printOnsetLocations();
|
Venetian@7
|
84 double onsetAtIndex(int index);
|
andrew@2
|
85
|
Venetian@7
|
86 void cropStartTo(double startTime);
|
Venetian@7
|
87
|
Venetian@7
|
88 void setMinimumThreshold(float fVal);
|
Venetian@7
|
89
|
Venetian@7
|
90 double beatAtIndex(std::vector<double> beatTimes, int beatIndex);
|
Venetian@7
|
91
|
Venetian@7
|
92 void categoriseOnsets(std::vector<double> beatTimes);
|
Venetian@7
|
93 void doCorrection(int& beattype, int& beatPosition);
|
Venetian@7
|
94
|
Venetian@7
|
95 // void testOnsetsCloseToBeats(std::vector<double> beatTimes);
|
Venetian@7
|
96 int onsetAtBeat(int testPosition);
|
Venetian@7
|
97
|
andrew@2
|
98 //vars
|
andrew@2
|
99 int frameSize;
|
andrew@2
|
100 int hopSize;
|
andrew@2
|
101 int samples;//number of samples
|
andrew@2
|
102
|
andrew@2
|
103 SNDFILE *infile; // define input and output sound files
|
andrew@2
|
104 SF_INFO sfinfo ; // struct to hold info about sound file
|
andrew@2
|
105
|
andrew@2
|
106 std::string loadedFilename;
|
andrew@2
|
107
|
andrew@2
|
108 OnsetDetectionFunction* detectionFunction;
|
andrew@2
|
109
|
andrew@2
|
110 PeakProcessor peakProcess;
|
andrew@2
|
111 PreciseOnsetLocator preciseLocator;
|
andrew@2
|
112
|
andrew@2
|
113 std::vector<double> dfValues;
|
Venetian@7
|
114 /*
|
andrew@2
|
115 std::vector<double> onsetLocations;//of exact time in seconds
|
andrew@2
|
116 std::vector<int> onsetPositionFrames;
|
Venetian@7
|
117 std::vector<int> onsetPositionSamples;
|
Venetian@7
|
118 */
|
Venetian@7
|
119 std::vector<OnsetInfo> onsetList;
|
andrew@2
|
120
|
andrew@2
|
121 bool writeOutput;//write output to txt
|
Venetian@7
|
122
|
Venetian@7
|
123 int dfType;
|
Venetian@7
|
124
|
Venetian@7
|
125 AudioRingBuffer* ringbuffer;
|
Venetian@7
|
126
|
Venetian@7
|
127 int sampleCount;
|
Venetian@7
|
128 int frameCount;
|
Venetian@7
|
129 bool isBass;
|
Venetian@7
|
130 private:
|
Venetian@7
|
131 bool initialised;
|
Venetian@7
|
132
|
andrew@2
|
133 };
|
andrew@2
|
134 #endif |