Mercurial > hg > vamp-tempogram
comparison NoveltyCurveProcessor.cpp @ 25:fe23998968b4
* Added tempogram via autocorrelation feature, using AutocorrelationProcessor
* Moved calculateMax() from NoveltyCurveProcessor to SpectrogramProcessor
author | Carl Bussey <c.bussey@se10.qmul.ac.uk> |
---|---|
date | Wed, 20 Aug 2014 16:00:37 +0100 |
parents | 957b83524c06 |
children | 1ad47a9afc2e |
comparison
equal
deleted
inserted
replaced
24:957b83524c06 | 25:fe23998968b4 |
---|---|
50 m_pBandBoundaries = 0; | 50 m_pBandBoundaries = 0; |
51 delete []m_pBandSum; | 51 delete []m_pBandSum; |
52 m_pBandSum = 0; | 52 m_pBandSum = 0; |
53 } | 53 } |
54 | 54 |
55 //calculate max of spectrogram | |
56 float NoveltyCurveProcessor::calculateMax(const Spectrogram &spectrogram) const | |
57 { | |
58 float max = 0; | |
59 | |
60 int length = spectrogram.size(); | |
61 int height = spectrogram[0].size(); | |
62 | |
63 for (int i = 0; i < length; i++){ | |
64 for (int j = 0; j < height; j++){ | |
65 max = max > fabs(spectrogram[i][j]) ? max : fabs(spectrogram[i][j]); | |
66 } | |
67 } | |
68 | |
69 return max; | |
70 } | |
71 | |
72 //subtract local average of novelty curve | 55 //subtract local average of novelty curve |
73 //uses m_hannWindow as filter | 56 //uses m_hannWindow as filter |
74 void NoveltyCurveProcessor::subtractLocalAverage(vector<float> &noveltyCurve, const size_t &smoothLength) const | 57 void NoveltyCurveProcessor::subtractLocalAverage(vector<float> &noveltyCurve, const size_t &smoothLength) const |
75 { | 58 { |
76 int numberOfBlocks = noveltyCurve.size(); | 59 int numberOfBlocks = noveltyCurve.size(); |
92 } | 75 } |
93 | 76 |
94 //smoothed differentiator filter. Flips upper half of hanning window about y-axis to create coefficients. | 77 //smoothed differentiator filter. Flips upper half of hanning window about y-axis to create coefficients. |
95 void NoveltyCurveProcessor::smoothedDifferentiator(SpectrogramTransposed &spectrogramTransposed, const size_t &smoothLength) const | 78 void NoveltyCurveProcessor::smoothedDifferentiator(SpectrogramTransposed &spectrogramTransposed, const size_t &smoothLength) const |
96 { | 79 { |
97 | |
98 int numberOfBlocks = spectrogramTransposed[0].size(); | 80 int numberOfBlocks = spectrogramTransposed[0].size(); |
99 | 81 |
100 float * diffHannWindow = new float [smoothLength]; | 82 float * diffHannWindow = new float [smoothLength]; |
101 WindowFunction::hanning(diffHannWindow, smoothLength, true); | 83 WindowFunction::hanning(diffHannWindow, smoothLength, true); |
102 | 84 |
114 | 96 |
115 //half rectification (set negative to zero) | 97 //half rectification (set negative to zero) |
116 void NoveltyCurveProcessor::halfWaveRectify(Spectrogram &spectrogram) const | 98 void NoveltyCurveProcessor::halfWaveRectify(Spectrogram &spectrogram) const |
117 { | 99 { |
118 int length = spectrogram.size(); | 100 int length = spectrogram.size(); |
119 int height = spectrogram[0].size(); | 101 int height = length > 0 ? spectrogram[0].size() : 0; |
120 | 102 |
121 for (int i = 0; i < length; i++){ | 103 for (int i = 0; i < length; i++){ |
122 for (int j = 0; j < height; j++){ | 104 for (int j = 0; j < height; j++){ |
123 if (spectrogram[i][j] < 0.0) spectrogram[i][j] = 0.0; | 105 if (spectrogram[i][j] < 0.0) spectrogram[i][j] = 0.0; |
124 } | 106 } |
129 vector<float> | 111 vector<float> |
130 NoveltyCurveProcessor::spectrogramToNoveltyCurve(const Spectrogram &spectrogram) const //make argument const & | 112 NoveltyCurveProcessor::spectrogramToNoveltyCurve(const Spectrogram &spectrogram) const //make argument const & |
131 { | 113 { |
132 int numberOfBlocks = spectrogram.size(); | 114 int numberOfBlocks = spectrogram.size(); |
133 std::vector<float> noveltyCurve(numberOfBlocks); | 115 std::vector<float> noveltyCurve(numberOfBlocks); |
134 SpectrogramTransposed spectrogramTransposed(spectrogram[0].size(), vector<float>(spectrogram.size())); | 116 SpectrogramTransposed spectrogramTransposed(m_blockSize, vector<float>(spectrogram.size())); |
135 | 117 |
136 //normalise and log spectrogram | 118 //normalise and log spectrogram |
137 float normaliseScale = calculateMax(spectrogram); | 119 float normaliseScale = SpectrogramProcessor::calculateMax(spectrogram); |
138 for (int block = 0; block < (int)numberOfBlocks; block++){ | 120 for (int block = 0; block < (int)numberOfBlocks; block++){ |
139 for (int k = 0; k < (int)m_blockSize; k++){ | 121 for (int k = 0; k < (int)m_blockSize; k++){ |
140 spectrogramTransposed[k][block] = log(1+m_compressionConstant*spectrogram[block][k]); | 122 float magnitude = spectrogram[block][k]; |
141 if(normaliseScale != 0.0) spectrogramTransposed[k][block] /= normaliseScale; //normalise | 123 if(normaliseScale != 0.0) magnitude /= normaliseScale; //normalise |
124 spectrogramTransposed[k][block] = log(1+m_compressionConstant*magnitude); | |
142 } | 125 } |
143 } | 126 } |
144 | 127 |
145 //smooted differentiator | 128 //smooted differentiator |
146 smoothedDifferentiator(spectrogramTransposed, 5); //make smoothLength a parameter! | 129 smoothedDifferentiator(spectrogramTransposed, 5); //make smoothLength a parameter! |