Mercurial > hg > sonic-visualiser
diff transform/RealTimePluginTransform.cpp @ 39:f18093617b78
* Introduce WritableWaveFileModel, and use it as an output model for audio
real-time plugin transforms. Updates aren't working correctly yet.
author | Chris Cannam |
---|---|
date | Tue, 03 Oct 2006 14:17:37 +0000 |
parents | 8ad306d8a568 |
children | 75c5951cf9d7 |
line wrap: on
line diff
--- a/transform/RealTimePluginTransform.cpp Tue Oct 03 10:06:37 2006 +0000 +++ b/transform/RealTimePluginTransform.cpp Tue Oct 03 14:17:37 2006 +0000 @@ -23,6 +23,7 @@ #include "data/model/Model.h" #include "data/model/SparseTimeValueModel.h" #include "data/model/DenseTimeValueModel.h" +#include "data/model/WritableWaveFileModel.h" #include <iostream> @@ -73,7 +74,10 @@ if (m_outputNo == -1) { - //!!! process audio! + WritableWaveFileModel *model = new WritableWaveFileModel + (input->getSampleRate(), input->getChannelCount()); //!!! + + m_output = model; } else { @@ -108,10 +112,11 @@ DenseTimeValueModel *input = getInput(); if (!input) return; - SparseTimeValueModel *model = dynamic_cast<SparseTimeValueModel *>(m_output); - if (!model) return; + SparseTimeValueModel *stvm = dynamic_cast<SparseTimeValueModel *>(m_output); + WritableWaveFileModel *wwfm = dynamic_cast<WritableWaveFileModel *>(m_output); + if (!stvm && !wwfm) return; - if (m_outputNo >= m_plugin->getControlOutputCount()) return; + if (stvm && (m_outputNo >= m_plugin->getControlOutputCount())) return; size_t sampleRate = input->getSampleRate(); int channelCount = input->getChannelCount(); @@ -127,6 +132,8 @@ size_t prevCompletion = 0; + size_t latency = m_plugin->getLatency(); + int i = 0; while (blockFrame < endFrame) { @@ -161,19 +168,44 @@ m_plugin->run(Vamp::RealTime::frame2RealTime(blockFrame, sampleRate)); - float value = m_plugin->getControlOutputValue(m_outputNo); + if (stvm) { - model->addPoint(SparseTimeValueModel::Point - (blockFrame - m_plugin->getLatency(), value, "")); + float value = m_plugin->getControlOutputValue(m_outputNo); + + size_t pointFrame = blockFrame; + if (pointFrame > latency) pointFrame -= latency; + else pointFrame = 0; + + stvm->addPoint(SparseTimeValueModel::Point + (pointFrame, value, "")); + + } else if (wwfm) { + + float **buffers = m_plugin->getAudioOutputBuffers(); + + if (blockFrame >= latency) { + wwfm->addSamples(buffers, blockSize); + } else if (blockFrame + blockSize >= latency) { + size_t offset = latency - blockFrame; + size_t count = blockSize - offset; + float **tmp = new float *[channelCount]; + for (size_t c = 0; c < channelCount; ++c) { + tmp[c] = buffers[c] + offset; + } + wwfm->addSamples(tmp, count); + delete[] tmp; + } + } if (blockFrame == startFrame || completion > prevCompletion) { - model->setCompletion(completion); + if (stvm) stvm->setCompletion(completion); prevCompletion = completion; } blockFrame += blockSize; } - model->setCompletion(100); + if (stvm) stvm->setCompletion(100); + if (wwfm) wwfm->sync(); }