# HG changeset patch # User Chris Cannam # Date 1159885057 0 # Node ID f18093617b7872bd35c3df3cce32d60efe1653bc # Parent 5c20bb3e6c94af85386aac7287ef78a148458248 * Introduce WritableWaveFileModel, and use it as an output model for audio real-time plugin transforms. Updates aren't working correctly yet. diff -r 5c20bb3e6c94 -r f18093617b78 main/MainWindow.cpp --- a/main/MainWindow.cpp Tue Oct 03 10:06:37 2006 +0000 +++ b/main/MainWindow.cpp Tue Oct 03 14:17:37 2006 +0000 @@ -152,7 +152,7 @@ m_panLayer = new WaveformLayer; m_panLayer->setChannelMode(WaveformLayer::MergeChannels); // m_panLayer->setScale(WaveformLayer::MeterScale); - m_panLayer->setAutoNormalize(true); +// m_panLayer->setAutoNormalize(true); m_panLayer->setBaseColour(Qt::darkGreen); m_panLayer->setAggressiveCacheing(true); m_panner->addLayer(m_panLayer); diff -r 5c20bb3e6c94 -r f18093617b78 transform/RealTimePluginTransform.cpp --- 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 @@ -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(m_output); - if (!model) return; + SparseTimeValueModel *stvm = dynamic_cast(m_output); + WritableWaveFileModel *wwfm = dynamic_cast(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(); }