andrew@0
|
1 /*
|
andrew@0
|
2 * AudioEventMatcher.h
|
andrew@0
|
3 * MultipleAudioMathcher
|
andrew@0
|
4 *
|
andrew@0
|
5 * Created by Andrew on 31/01/2012.
|
andrew@0
|
6 * Copyright 2012 QMUL. All rights reserved.
|
andrew@0
|
7 *
|
andrew@0
|
8 */
|
andrew@0
|
9
|
andrew@0
|
10
|
andrew@0
|
11
|
andrew@0
|
12 #ifndef AUDIO_EVENT_MATCHER_H
|
andrew@0
|
13 #define AUDIO_EVENT_MATCHER_H
|
andrew@0
|
14
|
andrew@32
|
15
|
andrew@0
|
16
|
andrew@0
|
17 #include "ofMain.h"
|
andrew@0
|
18 #include "ChromaOnset.h"
|
andrew@0
|
19 #include "LiveAudioInput.h"
|
andrew@0
|
20 #include "ofxWindowRegion.h"
|
andrew@0
|
21 #include "BayesianArrayStructure.h"
|
andrew@1
|
22 #include "RecordedMultitrackAudio.h"
|
andrew@7
|
23 #include "DynamicVector.h"
|
andrew@16
|
24 #include "AccompanimentSynchroniser.h"
|
andrew@19
|
25 #include "TempoFollower.h"
|
andrew@50
|
26 #include "MatchMarkers.h"
|
andrew@0
|
27
|
andrew@52
|
28 #include "OutputDataWriter.h"
|
andrew@52
|
29
|
andrew@32
|
30 static const int numberOfChannels = 4;
|
andrew@32
|
31
|
andrew@0
|
32 class AudioEventMatcher{
|
andrew@0
|
33
|
andrew@0
|
34 public:
|
andrew@0
|
35 AudioEventMatcher();
|
andrew@0
|
36
|
andrew@0
|
37 void setArraySizes();
|
andrew@0
|
38
|
andrew@9
|
39 void updatePosition();
|
andrew@8
|
40 void updateBestAlignmentPosition();
|
andrew@8
|
41
|
andrew@50
|
42
|
andrew@0
|
43 void draw();
|
andrew@32
|
44 void drawBayesianDistributions();
|
andrew@32
|
45 void drawPositionWindow();
|
andrew@32
|
46 void drawTrackLikelihoods();
|
andrew@32
|
47 void drawInfo();
|
andrew@45
|
48 void drawAlignmentTimes();
|
andrew@50
|
49 void drawMarkers();
|
andrew@32
|
50
|
andrew@7
|
51 void setWindowDimensions();
|
andrew@37
|
52 int getScreenWidthIndexOfEventTime(const double& time);
|
andrew@45
|
53 int getTimeNow();
|
andrew@0
|
54
|
andrew@50
|
55 void addMarkerNow();
|
andrew@50
|
56 void deleteMarkers();
|
andrew@50
|
57 void deleteNearestMarker();
|
andrew@50
|
58 void moveToNextMarker();
|
andrew@50
|
59 void moveToPreviousMarker();
|
andrew@50
|
60 void goToMarker(const int& markerID);
|
andrew@50
|
61 void setToPosition(const double& position);//for Bayesian distbn
|
andrew@50
|
62 void setPlaybackPosition(const double& millis);
|
andrew@50
|
63 void mousePressed(const int& x);
|
andrew@50
|
64
|
andrew@6
|
65 void newPitchEvent(const int& channel, const double& pitchIn, const double& timeIn);
|
andrew@2
|
66 void newKickEvent(const double& timeIn);
|
andrew@6
|
67 void newKickEvent(const int& channel, const double& timeIn);
|
andrew@2
|
68 void newSnareEvent(const double& timeIn);
|
andrew@7
|
69 void newSnareEvent(const int& channel, const double& timeIn);
|
andrew@2
|
70
|
andrew@32
|
71 void newChromaEvent(const int& channel, float* chromaIn, const double& timeIn);
|
andrew@32
|
72
|
andrew@32
|
73
|
andrew@2
|
74 void matchNewPitchEvent(const int& channel, const double& pitchIn, const double& timeIn);
|
andrew@2
|
75 void matchNewOnsetEvent(const int& channel, const double& timeIn);
|
andrew@32
|
76 void matchNewChromaEvent(const int& channel, float* chroma, const double& timeIn);
|
andrew@35
|
77
|
andrew@35
|
78 double getChromaDotProductDistance(float* chromaOne, float* chromaTwo);
|
andrew@35
|
79 double getChromaEuclideanDistance(float* chromaOne, float* chromaTwo);
|
andrew@35
|
80 bool useChromaDotProduct;
|
andrew@52
|
81 float quantisedChromagramReceived[12];
|
andrew@52
|
82 void makeQuantisedChroma(float* chromaIn);
|
andrew@1
|
83
|
andrew@0
|
84 BayesianArrayStructure bayesianStruct;//hold the probability distriubtions
|
andrew@0
|
85
|
andrew@0
|
86 LiveAudioInput liveInput;//hold the new events that come in
|
andrew@1
|
87 RecordedMultitrackAudio recordedTracks;
|
andrew@1
|
88
|
andrew@16
|
89 void loadAudioFiles();
|
andrew@22
|
90 void rescue();//flat prior
|
andrew@1
|
91 void windowResized(const int& w, const int& h);
|
andrew@0
|
92
|
andrew@0
|
93 ofxWindowRegion bayesTempoWindow;
|
andrew@3
|
94 ofxWindowRegion bayesPositionWindow;
|
andrew@3
|
95 ofxWindowRegion bayesLikelihoodWindow;
|
andrew@0
|
96
|
andrew@3
|
97 bool checkMatch(const double& recordedPitch, const double& livePitch);
|
andrew@3
|
98 double getPitchDistance(const double& pitchOne, const double& pitchTwo, const double& scale);
|
andrew@3
|
99
|
andrew@3
|
100 void startPlaying();
|
andrew@15
|
101 void stopPlaying();
|
andrew@15
|
102 bool startedPlaying;
|
andrew@3
|
103
|
andrew@3
|
104 bool usingRealTime;
|
andrew@37
|
105 double recentPitch, recentPitchEventTime;
|
andrew@7
|
106
|
andrew@32
|
107 DynamicVector likelihoodVisualisation[numberOfChannels];
|
andrew@32
|
108 DynamicVector recentPriors[numberOfChannels];
|
andrew@13
|
109 //DynamicVector recentPrior;
|
andrew@10
|
110 DynamicVector projectedPrior;
|
andrew@8
|
111
|
andrew@8
|
112 double currentAlignmentPosition;
|
andrew@8
|
113 double lastAlignmentTime;
|
andrew@8
|
114
|
andrew@32
|
115 double recentEventTime[numberOfChannels];
|
andrew@10
|
116 int startTime;
|
andrew@11
|
117 int currentAlignmentTime;
|
andrew@9
|
118
|
andrew@9
|
119 double screenStartTimeMillis, screenEndTimeMillis, screenWidthMillis;
|
andrew@9
|
120 bool followingLiveInput;
|
andrew@9
|
121 void setScreenDisplayTimes();
|
andrew@14
|
122
|
andrew@16
|
123 AccompanimentSynchroniser synchroniser;
|
andrew@16
|
124
|
andrew@14
|
125 //params
|
andrew@14
|
126 double onsetLikelihoodWidth;
|
andrew@56
|
127 double pitchLikelihoodWidth;
|
andrew@56
|
128 //double onsetLikelihoodToNoise;
|
andrew@53
|
129 double kickLikelihoodToNoise, snareLikelihoodToNoise;
|
andrew@15
|
130 double pitchLikelihoodToNoise;//more noise
|
andrew@32
|
131 double chromaLikelihoodToNoise;
|
andrew@18
|
132
|
andrew@18
|
133 double pitchOfNearestMatch;//for viz purposes
|
andrew@18
|
134 double distanceOfNearestMatch;
|
andrew@19
|
135
|
andrew@32
|
136 double chromaLikelihoodWidth;
|
andrew@19
|
137
|
andrew@19
|
138 TempoFollower temporal;
|
andrew@20
|
139 TempoFollower recordedTempoData;
|
andrew@20
|
140 void calculateRecordedTempoData();
|
andrew@56
|
141
|
andrew@20
|
142 void setTempoPrior(double tempo);
|
andrew@20
|
143
|
andrew@20
|
144 void setNextOnsetTime(const int&channel, int& time, int* indexForOnsets);
|
andrew@20
|
145 int recordedTempoIndex;
|
andrew@20
|
146 double recordedTempo;
|
andrew@20
|
147 void updateRecordedTempo();
|
andrew@56
|
148 double getRecordedTempoAtMillis(const double& millisPosition);
|
andrew@56
|
149
|
andrew@20
|
150 void drawRecordedTempo();
|
andrew@20
|
151 double currentSpeedRatio;
|
andrew@20
|
152 void drawPlayingTempo();
|
andrew@20
|
153 void setSpeedRatioDistribution(const double& speedRatio);
|
andrew@37
|
154
|
andrew@55
|
155 void setNewLimits(const double& position);
|
andrew@55
|
156
|
andrew@37
|
157 double euclideanMaximumDistance;
|
andrew@37
|
158 bool printingData;
|
andrew@50
|
159
|
andrew@50
|
160 bool drawLikelihoods;
|
andrew@50
|
161 bool drawPosterior;
|
andrew@50
|
162
|
andrew@50
|
163 MatchMarkers markedPoints;
|
andrew@50
|
164 double markerPlaybackPosition;
|
andrew@52
|
165
|
andrew@52
|
166 OutputDataWriter testDistributionOutput;
|
andrew@52
|
167 void writeAllDistributions();
|
andrew@52
|
168 void writeDistribution(DynamicVector& distribution, std::string filename);
|
andrew@55
|
169 void writeKickEvent(const int& startMatchingTime, const int& endMatchingTime, std::string filepath);
|
andrew@52
|
170 ofImage img;
|
andrew@53
|
171
|
andrew@53
|
172 void checkTempo();
|
andrew@53
|
173 double relativeTempo;
|
andrew@56
|
174
|
andrew@56
|
175 bool updateTempoMethodOn;
|
andrew@0
|
176 };
|
andrew@0
|
177 #endif
|