Mercurial > hg > sonic-visualiser
comparison transform/FeatureExtractionPluginTransform.cpp @ 182:21a76c9ed5c3
* Merge transform directory from sv-match-alignment branch
(the previous comment included notes for this stuff, but I missed it
in the actual merge)
* Fix crash when a transform fails to create an output model and the
thread that created the transform then deletes its input model thinking
it's no longer needed, even though the transform run thread is still
using it -- fix is to wait() on the transform before returning the
null output model
author | Chris Cannam |
---|---|
date | Fri, 28 Sep 2007 16:15:06 +0000 |
parents | dab257bd9d2d |
children | ebd906049fb6 |
comparison
equal
deleted
inserted
replaced
181:a65a01870d8c | 182:21a76c9ed5c3 |
---|---|
218 } | 218 } |
219 } | 219 } |
220 | 220 |
221 FeatureExtractionPluginTransform::~FeatureExtractionPluginTransform() | 221 FeatureExtractionPluginTransform::~FeatureExtractionPluginTransform() |
222 { | 222 { |
223 std::cerr << "FeatureExtractionPluginTransform::~FeatureExtractionPluginTransform()" << std::endl; | |
223 delete m_plugin; | 224 delete m_plugin; |
224 delete m_descriptor; | 225 delete m_descriptor; |
225 } | 226 } |
226 | 227 |
227 DenseTimeValueModel * | 228 DenseTimeValueModel * |
238 void | 239 void |
239 FeatureExtractionPluginTransform::run() | 240 FeatureExtractionPluginTransform::run() |
240 { | 241 { |
241 DenseTimeValueModel *input = getInput(); | 242 DenseTimeValueModel *input = getInput(); |
242 if (!input) return; | 243 if (!input) return; |
244 | |
245 if (!m_output) return; | |
243 | 246 |
244 while (!input->isReady()) { | 247 while (!input->isReady()) { |
245 /* | 248 /* |
246 if (dynamic_cast<WaveFileModel *>(input)) { | 249 if (dynamic_cast<WaveFileModel *>(input)) { |
247 std::cerr << "FeatureExtractionPluginTransform::run: Model is not ready, but it's not a WaveFileModel (it's a " << typeid(input).name() << "), so that's OK" << std::endl; | 250 std::cerr << "FeatureExtractionPluginTransform::run: Model is not ready, but it's not a WaveFileModel (it's a " << typeid(input).name() << "), so that's OK" << std::endl; |
250 } | 253 } |
251 */ | 254 */ |
252 std::cerr << "FeatureExtractionPluginTransform::run: Waiting for input model to be ready..." << std::endl; | 255 std::cerr << "FeatureExtractionPluginTransform::run: Waiting for input model to be ready..." << std::endl; |
253 sleep(1); | 256 sleep(1); |
254 } | 257 } |
255 | |
256 if (!m_output) return; | |
257 | 258 |
258 size_t sampleRate = m_input->getSampleRate(); | 259 size_t sampleRate = m_input->getSampleRate(); |
259 | 260 |
260 size_t channelCount = input->getChannelCount(); | 261 size_t channelCount = input->getChannelCount(); |
261 if (m_plugin->getMaxChannelCount() < channelCount) { | 262 if (m_plugin->getMaxChannelCount() < channelCount) { |
295 } | 296 } |
296 } | 297 } |
297 | 298 |
298 long startFrame = m_input->getStartFrame(); | 299 long startFrame = m_input->getStartFrame(); |
299 long endFrame = m_input->getEndFrame(); | 300 long endFrame = m_input->getEndFrame(); |
300 long blockFrame = startFrame; | 301 |
302 long contextStart = m_context.startFrame; | |
303 long contextDuration = m_context.duration; | |
304 | |
305 if (contextStart == 0 || contextStart < startFrame) { | |
306 contextStart = startFrame; | |
307 } | |
308 | |
309 if (contextDuration == 0) { | |
310 contextDuration = endFrame - contextStart; | |
311 } | |
312 if (contextStart + contextDuration > endFrame) { | |
313 contextDuration = endFrame - contextStart; | |
314 } | |
315 | |
316 long blockFrame = contextStart; | |
301 | 317 |
302 long prevCompletion = 0; | 318 long prevCompletion = 0; |
303 | 319 |
320 setCompletion(0); | |
321 | |
304 while (!m_abandoned) { | 322 while (!m_abandoned) { |
305 | 323 |
306 if (frequencyDomain) { | 324 if (frequencyDomain) { |
307 if (blockFrame - int(m_context.blockSize)/2 > endFrame) break; | 325 if (blockFrame - int(m_context.blockSize)/2 > |
326 contextStart + contextDuration) break; | |
308 } else { | 327 } else { |
309 if (blockFrame >= endFrame) break; | 328 if (blockFrame >= |
329 contextStart + contextDuration) break; | |
310 } | 330 } |
311 | 331 |
312 // std::cerr << "FeatureExtractionPluginTransform::run: blockFrame " | 332 // std::cerr << "FeatureExtractionPluginTransform::run: blockFrame " |
313 // << blockFrame << ", endFrame " << endFrame << ", blockSize " | 333 // << blockFrame << ", endFrame " << endFrame << ", blockSize " |
314 // << m_context.blockSize << std::endl; | 334 // << m_context.blockSize << std::endl; |
315 | 335 |
316 long completion = | 336 long completion = |
317 (((blockFrame - startFrame) / m_context.stepSize) * 99) / | 337 (((blockFrame - contextStart) / m_context.stepSize) * 99) / |
318 ( (endFrame - startFrame) / m_context.stepSize); | 338 (contextDuration / m_context.stepSize); |
319 | 339 |
320 // channelCount is either m_input->channelCount or 1 | 340 // channelCount is either m_input->channelCount or 1 |
321 | 341 |
322 for (size_t ch = 0; ch < channelCount; ++ch) { | 342 for (size_t ch = 0; ch < channelCount; ++ch) { |
323 if (frequencyDomain) { | 343 if (frequencyDomain) { |
339 Vamp::Plugin::Feature feature = | 359 Vamp::Plugin::Feature feature = |
340 features[m_outputFeatureNo][fi]; | 360 features[m_outputFeatureNo][fi]; |
341 addFeature(blockFrame, feature); | 361 addFeature(blockFrame, feature); |
342 } | 362 } |
343 | 363 |
344 if (blockFrame == startFrame || completion > prevCompletion) { | 364 if (blockFrame == contextStart || completion > prevCompletion) { |
345 setCompletion(completion); | 365 setCompletion(completion); |
346 prevCompletion = completion; | 366 prevCompletion = completion; |
347 } | 367 } |
348 | 368 |
349 blockFrame += m_context.stepSize; | 369 blockFrame += m_context.stepSize; |
498 int binCount = 1; | 518 int binCount = 1; |
499 if (m_descriptor->hasFixedBinCount) { | 519 if (m_descriptor->hasFixedBinCount) { |
500 binCount = m_descriptor->binCount; | 520 binCount = m_descriptor->binCount; |
501 } | 521 } |
502 | 522 |
503 // std::cerr << "FeatureExtractionPluginTransform::setCompletion(" | 523 std::cerr << "FeatureExtractionPluginTransform::setCompletion(" |
504 // << completion << ")" << std::endl; | 524 << completion << ")" << std::endl; |
505 | 525 |
506 if (binCount == 0) { | 526 if (binCount == 0) { |
507 | 527 |
508 SparseOneDimensionalModel *model = getOutput<SparseOneDimensionalModel>(); | 528 SparseOneDimensionalModel *model = getOutput<SparseOneDimensionalModel>(); |
509 if (!model) return; | 529 if (!model) return; |