Mercurial > hg > sonic-visualiser
comparison audioio/IntegerTimeStretcher.cpp @ 13:00ed645f4175
* various fixes in the time stretcher
author | Chris Cannam |
---|---|
date | Tue, 12 Sep 2006 19:13:12 +0000 |
parents | ee967635c728 |
children |
comparison
equal
deleted
inserted
replaced
12:ee967635c728 | 13:00ed645f4175 |
---|---|
36 | 36 |
37 m_time = (fftwf_complex *)fftwf_malloc(sizeof(fftwf_complex) * m_wlen); | 37 m_time = (fftwf_complex *)fftwf_malloc(sizeof(fftwf_complex) * m_wlen); |
38 m_freq = (fftwf_complex *)fftwf_malloc(sizeof(fftwf_complex) * m_wlen); | 38 m_freq = (fftwf_complex *)fftwf_malloc(sizeof(fftwf_complex) * m_wlen); |
39 m_dbuf = (float *)fftwf_malloc(sizeof(float) * m_wlen); | 39 m_dbuf = (float *)fftwf_malloc(sizeof(float) * m_wlen); |
40 m_mashbuf = (float *)fftwf_malloc(sizeof(float) * m_wlen); | 40 m_mashbuf = (float *)fftwf_malloc(sizeof(float) * m_wlen); |
41 m_modulationbuf = (float *)fftwf_malloc(sizeof(float) * m_wlen); | |
41 m_prevPhase = (float *)fftwf_malloc(sizeof(float) * m_wlen); | 42 m_prevPhase = (float *)fftwf_malloc(sizeof(float) * m_wlen); |
42 m_prevAdjustedPhase = (float *)fftwf_malloc(sizeof(float) * m_wlen); | 43 m_prevAdjustedPhase = (float *)fftwf_malloc(sizeof(float) * m_wlen); |
43 | 44 |
44 m_plan = fftwf_plan_dft_1d(m_wlen, m_time, m_freq, FFTW_FORWARD, FFTW_ESTIMATE); | 45 m_plan = fftwf_plan_dft_1d(m_wlen, m_time, m_freq, FFTW_FORWARD, FFTW_ESTIMATE); |
45 m_iplan = fftwf_plan_dft_c2r_1d(m_wlen, m_freq, m_dbuf, FFTW_ESTIMATE); | 46 m_iplan = fftwf_plan_dft_c2r_1d(m_wlen, m_freq, m_dbuf, FFTW_ESTIMATE); |
46 | 47 |
47 for (int i = 0; i < m_wlen; ++i) { | 48 for (int i = 0; i < m_wlen; ++i) { |
48 m_mashbuf[i] = 0.0; | 49 m_mashbuf[i] = 0.0; |
50 m_modulationbuf[i] = 0.0; | |
49 m_prevPhase[i] = 0.0; | 51 m_prevPhase[i] = 0.0; |
50 m_prevAdjustedPhase[i] = 0.0; | 52 m_prevAdjustedPhase[i] = 0.0; |
51 } | 53 } |
52 } | 54 } |
53 | 55 |
60 | 62 |
61 fftwf_free(m_time); | 63 fftwf_free(m_time); |
62 fftwf_free(m_freq); | 64 fftwf_free(m_freq); |
63 fftwf_free(m_dbuf); | 65 fftwf_free(m_dbuf); |
64 fftwf_free(m_mashbuf); | 66 fftwf_free(m_mashbuf); |
67 fftwf_free(m_modulationbuf); | |
65 fftwf_free(m_prevPhase); | 68 fftwf_free(m_prevPhase); |
66 fftwf_free(m_prevAdjustedPhase); | 69 fftwf_free(m_prevAdjustedPhase); |
67 | 70 |
68 delete m_window; | 71 delete m_window; |
69 } | 72 } |
123 // pointer. | 126 // pointer. |
124 | 127 |
125 size_t got = m_inbuf.peek(m_dbuf, m_wlen); | 128 size_t got = m_inbuf.peek(m_dbuf, m_wlen); |
126 assert(got == m_wlen); | 129 assert(got == m_wlen); |
127 | 130 |
128 processBlock(m_dbuf, m_mashbuf); | 131 processBlock(m_dbuf, m_mashbuf, m_modulationbuf); |
129 | 132 |
130 #ifdef DEBUG_INTEGER_TIME_STRETCHER | 133 #ifdef DEBUG_INTEGER_TIME_STRETCHER |
131 std::cerr << "writing first " << m_n2 << " from mashbuf, skipping " << m_n1 << " on inbuf " << std::endl; | 134 std::cerr << "writing first " << m_n2 << " from mashbuf, skipping " << m_n1 << " on inbuf " << std::endl; |
132 #endif | 135 #endif |
133 m_inbuf.skip(m_n1); | 136 m_inbuf.skip(m_n1); |
137 | |
138 for (size_t i = 0; i < m_n2; ++i) { | |
139 if (m_modulationbuf[i] > 0.f) { | |
140 m_mashbuf[i] /= m_modulationbuf[i]; | |
141 } | |
142 } | |
143 | |
134 m_outbuf.write(m_mashbuf, m_n2); | 144 m_outbuf.write(m_mashbuf, m_n2); |
135 | 145 |
136 for (size_t i = 0; i < m_wlen - m_n2; ++i) { | 146 for (size_t i = 0; i < m_wlen - m_n2; ++i) { |
137 m_mashbuf[i] = m_mashbuf[i + m_n2]; | 147 m_mashbuf[i] = m_mashbuf[i + m_n2]; |
148 m_modulationbuf[i] = m_modulationbuf[i + m_n2]; | |
138 } | 149 } |
150 | |
139 for (size_t i = m_wlen - m_n2; i < m_wlen; ++i) { | 151 for (size_t i = m_wlen - m_n2; i < m_wlen; ++i) { |
140 m_mashbuf[i] = 0.0f; | 152 m_mashbuf[i] = 0.0f; |
153 m_modulationbuf[i] = 0.0f; | |
141 } | 154 } |
142 } | 155 } |
143 | 156 |
144 // std::cerr << "WARNING: IntegerTimeStretcher::process: writespace not enough for output increment (" << m_outbuf.getWriteSpace() << " < " << m_n2 << ")" << std::endl; | 157 // std::cerr << "WARNING: IntegerTimeStretcher::process: writespace not enough for output increment (" << m_outbuf.getWriteSpace() << " < " << m_n2 << ")" << std::endl; |
145 // } | 158 // } |
169 std::cerr << "IntegerTimeStretcher::process returning" << std::endl; | 182 std::cerr << "IntegerTimeStretcher::process returning" << std::endl; |
170 #endif | 183 #endif |
171 } | 184 } |
172 | 185 |
173 void | 186 void |
174 IntegerTimeStretcher::processBlock(float *buf, float *out) | 187 IntegerTimeStretcher::processBlock(float *buf, float *out, float *modulation) |
175 { | 188 { |
176 size_t i; | 189 size_t i; |
177 | 190 |
178 // buf contains m_wlen samples; out contains enough space for | 191 // buf contains m_wlen samples; out contains enough space for |
179 // m_wlen * ratio samples (we mix into out, rather than replacing) | 192 // m_wlen * ratio samples (we mix into out, rather than replacing) |
230 buf[i] = buf[i + m_wlen/2] / m_wlen; | 243 buf[i] = buf[i + m_wlen/2] / m_wlen; |
231 buf[i + m_wlen/2] = temp; | 244 buf[i + m_wlen/2] = temp; |
232 } | 245 } |
233 | 246 |
234 m_window->cut(buf); | 247 m_window->cut(buf); |
235 | 248 /* |
236 int div = m_wlen / m_n2; | 249 int div = m_wlen / m_n2; |
237 if (div > 1) div /= 2; | 250 if (div > 1) div /= 2; |
238 for (i = 0; i < m_wlen; ++i) { | 251 for (i = 0; i < m_wlen; ++i) { |
239 buf[i] /= div; | 252 buf[i] /= div; |
240 } | 253 } |
241 | 254 */ |
242 for (i = 0; i < m_wlen; ++i) { | 255 for (i = 0; i < m_wlen; ++i) { |
243 out[i] += buf[i]; | 256 out[i] += buf[i]; |
244 } | 257 modulation[i] += m_window->getValue(i); |
245 } | 258 } |
259 } |