30 m_numBands =
static_cast<int>(logSpectrum.size());
31 m_numFrames =
static_cast<int>(logSpectrum[0].size());
35 logSpectrum.insert(std::begin(logSpectrum), logSpectrum.at(1));
37 logSpectrum.insert(std::end(logSpectrum), std::end(logSpectrum)[-2]);
46 std::vector<float> subVec = {logSpectrum[i][j], logSpectrum[i + 1][j], logSpectrum[i + 2][j]};
48 float max = *std::max_element(std::begin(subVec), std::end(subVec));
53 return maxLogSpectrum;
57 const std::vector<std::vector<float>>& logSpectrum,
const std::vector<float>& maxLogSpectum)
59 float diffFlat = 0.0f;
61 std::vector<float> detectionFunctionFlat(
m_numFrames);
70 detectionFunctionFlat[j] = diffFlat;
74 return detectionFunctionFlat;
79 size_t detectionSize = detectionFunction.size();
82 auto movingMaxVec =
movingMax(detectionFunction);
85 auto movingMeanVec =
movingMean(detectionFunction);
88 jassert(movingMaxVec.size() == detectionSize && movingMeanVec.size() == detectionSize);
91 float maxDetect = *std::max_element(std::begin(detectionFunction), std::end(detectionFunction));
92 float minDetect = *std::min_element(std::begin(detectionFunction), std::end(detectionFunction));
93 float delta =
m_deltaPrcnt * ((maxDetect - minDetect) / 2.0f);
96 std::vector<int> allOnsets;
97 for (
int i = 0; i < detectionSize; i++)
100 if (movingMaxVec[i] >= movingMeanVec[i] + delta)
102 allOnsets.push_back(i);
107 std::vector<int> onsetPositions;
111 for (
int i = 1; i < allOnsets.size(); i++)
116 onsetPositions.push_back(allOnsets[i] *
m_hopSize);
121 onsetPositions.insert(std::begin(onsetPositions), allOnsets[1] *
m_hopSize);
123 onsetPositions.insert(std::begin(onsetPositions), 0);
125 return onsetPositions;
130 size_t length = detectionFunction.size();
134 std::vector<float>::const_iterator first = std::begin(detectionFunction) + 1;
136 std::vector<float> subVecStart(first, last);
138 std::reverse(std::begin(subVecStart), std::end(subVecStart));
140 detectionFunction.insert(std::begin(detectionFunction), std::begin(subVecStart), std::end(subVecStart));
144 last = std::end(detectionFunction) - 1;
145 std::vector<float> subVecEnd(first, last);
147 std::reverse(std::begin(subVecEnd), std::end(subVecEnd));
149 detectionFunction.insert(std::end(detectionFunction), std::begin(subVecEnd), std::end(subVecEnd));
151 std::vector<float> movMax(length);
157 std::vector<float>::const_iterator start = std::begin(detectionFunction) + i -
m_preMaxFrames;
159 std::vector<float> subVec(start, finish);
161 movMax.at(i -
m_preMaxFrames) = *std::max_element(std::begin(subVec), std::end(subVec));
169 size_t length = detectionFunction.size();
173 std::vector<float>::const_iterator first = std::begin(detectionFunction) + 1;
175 std::vector<float> subVecStart(first, last);
177 std::reverse(std::begin(subVecStart), std::begin(subVecStart));
179 detectionFunction.insert(std::begin(detectionFunction), std::begin(subVecStart), std::end(subVecStart));
183 last = std::end(detectionFunction) - 1;
184 std::vector<float> subVecEnd(first, last);
186 std::reverse(std::begin(subVecEnd), std::end(subVecEnd));
188 detectionFunction.insert(std::end(detectionFunction), std::begin(subVecEnd), std::end(subVecEnd));
190 std::vector<float> movMean(length);
196 std::vector<float>::const_iterator start = std::begin(detectionFunction) + i -
m_preAvgFrames;
198 std::vector<float> subVec(start, finish);
200 movMean.at(i -
m_preAvgFrames) = std::accumulate(std::begin(subVec), std::end(subVec), 0.0f) / count;
210 std::vector<int> onsetPositions =
peakPicking(detectionFunction);
212 return onsetPositions;
std::vector< float > calculateDetectionFunction(const std::vector< std::vector< float > > &logSpectrum, const std::vector< float > &maxLogSpectum)
Definition SuperFluxOnsetDetection.cpp:56
void setParametersMS(float preMax, float postMax, float preAvg, float postAvg, float combWidth)
Definition SuperFluxOnsetDetection.cpp:12
std::vector< float > movingMean(std::vector< float > detectionFunction)
Definition SuperFluxOnsetDetection.cpp:167
int m_numBands
Definition SuperFluxOnsetDetection.h:97
float m_sampleRate
Definition SuperFluxOnsetDetection.h:99
int m_combWidthFrames
Definition SuperFluxOnsetDetection.h:93
std::vector< int > findOnsetsInSamples()
Definition SuperFluxOnsetDetection.cpp:206
int m_numFrames
Definition SuperFluxOnsetDetection.h:98
float halfWaveRect(float x)
Definition SuperFluxOnsetDetection.h:75
int m_preMaxFrames
Definition SuperFluxOnsetDetection.h:89
const int mi
Definition SuperFluxOnsetDetection.h:96
int m_preAvgFrames
Definition SuperFluxOnsetDetection.h:91
std::vector< std::vector< float > > m_inputLogSpectrum
Definition SuperFluxOnsetDetection.h:83
SuperFluxOnsetDetection(std::vector< std::vector< float > > &logSpectrum, float sampleRate, int hopSize)
Definition SuperFluxOnsetDetection.cpp:3
void setDeltaPercentage(float deltaPrcnt)
Definition SuperFluxOnsetDetection.cpp:25
int m_postMaxFrames
Definition SuperFluxOnsetDetection.h:90
std::vector< int > peakPicking(std::vector< float > detectionFunction)
Definition SuperFluxOnsetDetection.cpp:77
std::vector< float > movingMax(std::vector< float > detectionFunction)
Definition SuperFluxOnsetDetection.cpp:128
int m_postAvgFrames
Definition SuperFluxOnsetDetection.h:92
std::vector< float > trajectoryTracking(std::vector< std::vector< float > > logSpectrum)
Definition SuperFluxOnsetDetection.cpp:27
float m_deltaPrcnt
Definition SuperFluxOnsetDetection.h:87
int m_hopSize
Definition SuperFluxOnsetDetection.h:100
Definition AirAbsorptionFilter.cpp:2