comparison plugins/Silence.cpp @ 35:bcb23bb4b7aa

Get the rest to build
author Chris Cannam <cannam@all-day-breakfast.com>
date Tue, 10 Jul 2012 17:20:10 +0100
parents 8a20f3488d88
children b80056ac0503
comparison
equal deleted inserted replaced
34:0f40399ca1ff 35:bcb23bb4b7aa
23 23
24 Silence::Silence(float inputSampleRate) : 24 Silence::Silence(float inputSampleRate) :
25 Plugin(inputSampleRate), 25 Plugin(inputSampleRate),
26 m_ibuf(0), 26 m_ibuf(0),
27 m_pbuf(0), 27 m_pbuf(0),
28 m_tmpptrs(0),
29 m_threshold(-80), 28 m_threshold(-80),
30 m_prevSilent(false), 29 m_prevSilent(false),
31 m_first(true) 30 m_first(true)
32 { 31 {
33 } 32 }
34 33
35 Silence::~Silence() 34 Silence::~Silence()
36 { 35 {
37 if (m_ibuf) del_fvec(m_ibuf); 36 if (m_ibuf) del_fvec(m_ibuf);
38 if (m_pbuf) del_fvec(m_pbuf); 37 if (m_pbuf) del_fvec(m_pbuf);
39 if (m_tmpptrs) delete[] m_tmpptrs;
40 } 38 }
41 39
42 string 40 string
43 Silence::getIdentifier() const 41 Silence::getIdentifier() const
44 { 42 {
86 m_stepSize = stepSize; 84 m_stepSize = stepSize;
87 m_blockSize = blockSize; 85 m_blockSize = blockSize;
88 86
89 m_ibuf = new_fvec(stepSize); 87 m_ibuf = new_fvec(stepSize);
90 m_pbuf = new_fvec(stepSize); 88 m_pbuf = new_fvec(stepSize);
91 m_tmpptrs = new smpl_t *[channels];
92 89
93 return true; 90 return true;
94 } 91 }
95 92
96 void 93 void
197 Silence::FeatureSet 194 Silence::FeatureSet
198 Silence::process(const float *const *inputBuffers, 195 Silence::process(const float *const *inputBuffers,
199 Vamp::RealTime timestamp) 196 Vamp::RealTime timestamp)
200 { 197 {
201 for (size_t i = 0; i < m_stepSize; ++i) { 198 for (size_t i = 0; i < m_stepSize; ++i) {
202 for (size_t j = 0; j < m_channelCount; ++j) { 199 fvec_write_sample(m_ibuf, inputBuffers[0][i], i);
203 fvec_write_sample(m_ibuf, inputBuffers[j][i], j, i);
204 }
205 } 200 }
206 201
207 bool silent = aubio_silence_detection(m_ibuf, m_threshold); 202 bool silent = aubio_silence_detection(m_ibuf, m_threshold);
208 FeatureSet returnFeatures; 203 FeatureSet returnFeatures;
209 204
219 size_t incr = 16; 214 size_t incr = 16;
220 if (incr > m_stepSize/8) incr = m_stepSize/8; 215 if (incr > m_stepSize/8) incr = m_stepSize/8;
221 216
222 fvec_t vec; 217 fvec_t vec;
223 vec.length = incr * 4; 218 vec.length = incr * 4;
224 vec.channels = m_channelCount;
225 vec.data = m_tmpptrs;
226 219
227 for (size_t i = 0; i < m_stepSize - incr * 4; i += incr) { 220 for (size_t i = 0; i < m_stepSize - incr * 4; i += incr) {
228 for (size_t j = 0; j < m_channelCount; ++j) { 221 vec.data = m_ibuf->data + i;
229 m_tmpptrs[j] = m_ibuf->data[j] + i;
230 }
231 bool subsilent = aubio_silence_detection(&vec, m_threshold); 222 bool subsilent = aubio_silence_detection(&vec, m_threshold);
232 if (silent == subsilent) { 223 if (silent == subsilent) {
233 off = i; 224 off = i;
234 break; 225 break;
235 } 226 }
236 } 227 }
237 228
238 if (silent && (off == 0)) { 229 if (silent && (off == 0)) {
239 for (size_t i = 0; i < m_stepSize - incr; i += incr) { 230 for (size_t i = 0; i < m_stepSize - incr; i += incr) {
240 for (size_t j = 0; j < m_channelCount; ++j) { 231 vec.data = m_pbuf->data + m_stepSize - i - incr;
241 m_tmpptrs[j] = m_pbuf->data[j] + m_stepSize - i - incr;
242 }
243 bool subsilent = aubio_silence_detection(&vec, m_threshold); 232 bool subsilent = aubio_silence_detection(&vec, m_threshold);
244 if (!subsilent) { 233 if (!subsilent) {
245 off = -(long)i; 234 off = -(long)i;
246 break; 235 break;
247 } 236 }
282 } 271 }
283 272
284 // swap ibuf and pbuf data pointers, so that this block's data is 273 // swap ibuf and pbuf data pointers, so that this block's data is
285 // available in pbuf when processing the next block, without 274 // available in pbuf when processing the next block, without
286 // having to allocate new storage for it 275 // having to allocate new storage for it
287 smpl_t **tmpdata = m_ibuf->data; 276 smpl_t *tmpdata = m_ibuf->data;
288 m_ibuf->data = m_pbuf->data; 277 m_ibuf->data = m_pbuf->data;
289 m_pbuf->data = tmpdata; 278 m_pbuf->data = tmpdata;
290 279
291 m_lastTimestamp = timestamp; 280 m_lastTimestamp = timestamp;
292 281