Mercurial > hg > qm-dsp
comparison dsp/tempotracking/DownBeat.cpp @ 57:d241e7701c0c
* remove some debug output
author | cannam |
---|---|
date | Fri, 27 Feb 2009 13:07:22 +0000 |
parents | a0f987c06bec |
children | d72fcd34d9a7 |
comparison
equal
deleted
inserted
replaced
56:a0f987c06bec | 57:d241e7701c0c |
---|---|
36 // beat frame size is next power of two up from 1.3 seconds at the | 36 // beat frame size is next power of two up from 1.3 seconds at the |
37 // downsampled rate (happens to produce 4096 for 44100 or 48000 at | 37 // downsampled rate (happens to produce 4096 for 44100 or 48000 at |
38 // 16x decimation, which is our expected normal situation) | 38 // 16x decimation, which is our expected normal situation) |
39 m_beatframesize = MathUtilities::nextPowerOfTwo | 39 m_beatframesize = MathUtilities::nextPowerOfTwo |
40 (int((m_rate / decimationFactor) * 1.3)); | 40 (int((m_rate / decimationFactor) * 1.3)); |
41 std::cerr << "rate = " << m_rate << ", bfs = " << m_beatframesize << std::endl; | 41 // std::cerr << "rate = " << m_rate << ", bfs = " << m_beatframesize << std::endl; |
42 m_beatframe = new double[m_beatframesize]; | 42 m_beatframe = new double[m_beatframesize]; |
43 m_fftRealOut = new double[m_beatframesize]; | 43 m_fftRealOut = new double[m_beatframesize]; |
44 m_fftImagOut = new double[m_beatframesize]; | 44 m_fftImagOut = new double[m_beatframesize]; |
45 } | 45 } |
46 | 46 |
66 { | 66 { |
67 if (m_factor < 2) return; | 67 if (m_factor < 2) return; |
68 int highest = Decimator::getHighestSupportedFactor(); | 68 int highest = Decimator::getHighestSupportedFactor(); |
69 if (m_factor <= highest) { | 69 if (m_factor <= highest) { |
70 m_decimator1 = new Decimator(m_increment, m_factor); | 70 m_decimator1 = new Decimator(m_increment, m_factor); |
71 std::cerr << "DownBeat: decimator 1 factor " << m_factor << ", size " << m_increment << std::endl; | 71 // std::cerr << "DownBeat: decimator 1 factor " << m_factor << ", size " << m_increment << std::endl; |
72 return; | 72 return; |
73 } | 73 } |
74 m_decimator1 = new Decimator(m_increment, highest); | 74 m_decimator1 = new Decimator(m_increment, highest); |
75 std::cerr << "DownBeat: decimator 1 factor " << highest << ", size " << m_increment << std::endl; | 75 // std::cerr << "DownBeat: decimator 1 factor " << highest << ", size " << m_increment << std::endl; |
76 m_decimator2 = new Decimator(m_increment / highest, m_factor / highest); | 76 m_decimator2 = new Decimator(m_increment / highest, m_factor / highest); |
77 std::cerr << "DownBeat: decimator 2 factor " << m_factor / highest << ", size " << m_increment / highest << std::endl; | 77 // std::cerr << "DownBeat: decimator 2 factor " << m_factor / highest << ", size " << m_increment / highest << std::endl; |
78 m_decbuf = new float[m_increment / highest]; | 78 m_decbuf = new float[m_increment / highest]; |
79 } | 79 } |
80 | 80 |
81 void | 81 void |
82 DownBeat::pushAudioBlock(const float *audio) | 82 DownBeat::pushAudioBlock(const float *audio) |
85 if (m_bufsiz == 0) m_bufsiz = m_increment * 16; | 85 if (m_bufsiz == 0) m_bufsiz = m_increment * 16; |
86 else m_bufsiz = m_bufsiz * 2; | 86 else m_bufsiz = m_bufsiz * 2; |
87 if (!m_buffer) { | 87 if (!m_buffer) { |
88 m_buffer = (float *)malloc(m_bufsiz * sizeof(float)); | 88 m_buffer = (float *)malloc(m_bufsiz * sizeof(float)); |
89 } else { | 89 } else { |
90 std::cerr << "DownBeat::pushAudioBlock: realloc m_buffer to " << m_bufsiz << std::endl; | 90 // std::cerr << "DownBeat::pushAudioBlock: realloc m_buffer to " << m_bufsiz << std::endl; |
91 m_buffer = (float *)realloc(m_buffer, m_bufsiz * sizeof(float)); | 91 m_buffer = (float *)realloc(m_buffer, m_bufsiz * sizeof(float)); |
92 } | 92 } |
93 } | 93 } |
94 if (!m_decimator1) makeDecimators(); | 94 if (!m_decimator1) makeDecimators(); |
95 float rmsin = 0, rmsout = 0; | 95 float rmsin = 0, rmsout = 0; |
103 m_decimator1->process(audio, m_buffer + m_buffill); | 103 m_decimator1->process(audio, m_buffer + m_buffill); |
104 } | 104 } |
105 for (int i = 0; i < m_increment / m_factor; ++i) { | 105 for (int i = 0; i < m_increment / m_factor; ++i) { |
106 rmsout += m_buffer[m_buffill + i] * m_buffer[m_buffill + i]; | 106 rmsout += m_buffer[m_buffill + i] * m_buffer[m_buffill + i]; |
107 } | 107 } |
108 std::cerr << "pushAudioBlock: rms in " << sqrt(rmsin) << ", out " << sqrt(rmsout) << std::endl; | 108 // std::cerr << "pushAudioBlock: rms in " << sqrt(rmsin) << ", out " << sqrt(rmsout) << std::endl; |
109 m_buffill += m_increment / m_factor; | 109 m_buffill += m_increment / m_factor; |
110 } | 110 } |
111 | 111 |
112 const float * | 112 const float * |
113 DownBeat::getBufferedAudio(size_t &length) const | 113 DownBeat::getBufferedAudio(size_t &length) const |
166 double mul = 0.5 * (1.0 - cos(TWO_PI * (double(j) / double(beatlen)))); | 166 double mul = 0.5 * (1.0 - cos(TWO_PI * (double(j) / double(beatlen)))); |
167 m_beatframe[j] = audio[beatstart + j] * mul; | 167 m_beatframe[j] = audio[beatstart + j] * mul; |
168 rms += m_beatframe[j] * m_beatframe[j]; | 168 rms += m_beatframe[j] * m_beatframe[j]; |
169 } | 169 } |
170 rms = sqrt(rms); | 170 rms = sqrt(rms); |
171 std::cerr << "beat " << i << ": audio rms " << rms << std::endl; | 171 // std::cerr << "beat " << i << ": audio rms " << rms << std::endl; |
172 | 172 |
173 for (size_t j = beatlen; j < m_beatframesize; ++j) { | 173 for (size_t j = beatlen; j < m_beatframesize; ++j) { |
174 m_beatframe[j] = 0.0; | 174 m_beatframe[j] = 0.0; |
175 } | 175 } |
176 | 176 |
192 | 192 |
193 // Calculate JS divergence between new and old spectral frames | 193 // Calculate JS divergence between new and old spectral frames |
194 | 194 |
195 if (i > 0) { // otherwise we have no previous frame | 195 if (i > 0) { // otherwise we have no previous frame |
196 m_beatsd.push_back(measureSpecDiff(oldspec, newspec)); | 196 m_beatsd.push_back(measureSpecDiff(oldspec, newspec)); |
197 std::cerr << "specdiff: " << m_beatsd[m_beatsd.size()-1] << std::endl; | 197 // std::cerr << "specdiff: " << m_beatsd[m_beatsd.size()-1] << std::endl; |
198 } | 198 } |
199 | 199 |
200 // Copy newspec across to old | 200 // Copy newspec across to old |
201 | 201 |
202 for (size_t j = 0; j < m_beatframesize/2; ++j) { | 202 for (size_t j = 0; j < m_beatframesize/2; ++j) { |
222 if (example < 0) continue; | 222 if (example < 0) continue; |
223 dbcand[beat] += (m_beatsd[example]) / timesig; | 223 dbcand[beat] += (m_beatsd[example]) / timesig; |
224 ++count; | 224 ++count; |
225 } | 225 } |
226 if (count > 0) m_beatsd[beat] /= count; | 226 if (count > 0) m_beatsd[beat] /= count; |
227 std::cerr << "dbcand[" << beat << "] = " << dbcand[beat] << std::endl; | 227 // std::cerr << "dbcand[" << beat << "] = " << dbcand[beat] << std::endl; |
228 } | 228 } |
229 | 229 |
230 | 230 |
231 // first downbeat is beat at index of maximum value of dbcand | 231 // first downbeat is beat at index of maximum value of dbcand |
232 int dbind = MathUtilities::getMax(dbcand); | 232 int dbind = MathUtilities::getMax(dbcand); |