comparison 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
comparison
equal deleted inserted replaced
38:5c20bb3e6c94 39:f18093617b78
21 #include "plugin/PluginXml.h" 21 #include "plugin/PluginXml.h"
22 22
23 #include "data/model/Model.h" 23 #include "data/model/Model.h"
24 #include "data/model/SparseTimeValueModel.h" 24 #include "data/model/SparseTimeValueModel.h"
25 #include "data/model/DenseTimeValueModel.h" 25 #include "data/model/DenseTimeValueModel.h"
26 #include "data/model/WritableWaveFileModel.h"
26 27
27 #include <iostream> 28 #include <iostream>
28 29
29 RealTimePluginTransform::RealTimePluginTransform(Model *inputModel, 30 RealTimePluginTransform::RealTimePluginTransform(Model *inputModel,
30 QString pluginId, 31 QString pluginId,
71 return; 72 return;
72 } 73 }
73 74
74 if (m_outputNo == -1) { 75 if (m_outputNo == -1) {
75 76
76 //!!! process audio! 77 WritableWaveFileModel *model = new WritableWaveFileModel
78 (input->getSampleRate(), input->getChannelCount()); //!!!
79
80 m_output = model;
77 81
78 } else { 82 } else {
79 83
80 SparseTimeValueModel *model = new SparseTimeValueModel 84 SparseTimeValueModel *model = new SparseTimeValueModel
81 (input->getSampleRate(), m_context.blockSize, 0.0, 0.0, false); 85 (input->getSampleRate(), m_context.blockSize, 0.0, 0.0, false);
106 RealTimePluginTransform::run() 110 RealTimePluginTransform::run()
107 { 111 {
108 DenseTimeValueModel *input = getInput(); 112 DenseTimeValueModel *input = getInput();
109 if (!input) return; 113 if (!input) return;
110 114
111 SparseTimeValueModel *model = dynamic_cast<SparseTimeValueModel *>(m_output); 115 SparseTimeValueModel *stvm = dynamic_cast<SparseTimeValueModel *>(m_output);
112 if (!model) return; 116 WritableWaveFileModel *wwfm = dynamic_cast<WritableWaveFileModel *>(m_output);
113 117 if (!stvm && !wwfm) return;
114 if (m_outputNo >= m_plugin->getControlOutputCount()) return; 118
119 if (stvm && (m_outputNo >= m_plugin->getControlOutputCount())) return;
115 120
116 size_t sampleRate = input->getSampleRate(); 121 size_t sampleRate = input->getSampleRate();
117 int channelCount = input->getChannelCount(); 122 int channelCount = input->getChannelCount();
118 if (m_context.channel != -1) channelCount = 1; 123 if (m_context.channel != -1) channelCount = 1;
119 124
124 size_t startFrame = m_input->getStartFrame(); 129 size_t startFrame = m_input->getStartFrame();
125 size_t endFrame = m_input->getEndFrame(); 130 size_t endFrame = m_input->getEndFrame();
126 size_t blockFrame = startFrame; 131 size_t blockFrame = startFrame;
127 132
128 size_t prevCompletion = 0; 133 size_t prevCompletion = 0;
134
135 size_t latency = m_plugin->getLatency();
129 136
130 int i = 0; 137 int i = 0;
131 138
132 while (blockFrame < endFrame) { 139 while (blockFrame < endFrame) {
133 140
159 } 166 }
160 } 167 }
161 168
162 m_plugin->run(Vamp::RealTime::frame2RealTime(blockFrame, sampleRate)); 169 m_plugin->run(Vamp::RealTime::frame2RealTime(blockFrame, sampleRate));
163 170
164 float value = m_plugin->getControlOutputValue(m_outputNo); 171 if (stvm) {
165 172
166 model->addPoint(SparseTimeValueModel::Point 173 float value = m_plugin->getControlOutputValue(m_outputNo);
167 (blockFrame - m_plugin->getLatency(), value, "")); 174
175 size_t pointFrame = blockFrame;
176 if (pointFrame > latency) pointFrame -= latency;
177 else pointFrame = 0;
178
179 stvm->addPoint(SparseTimeValueModel::Point
180 (pointFrame, value, ""));
181
182 } else if (wwfm) {
183
184 float **buffers = m_plugin->getAudioOutputBuffers();
185
186 if (blockFrame >= latency) {
187 wwfm->addSamples(buffers, blockSize);
188 } else if (blockFrame + blockSize >= latency) {
189 size_t offset = latency - blockFrame;
190 size_t count = blockSize - offset;
191 float **tmp = new float *[channelCount];
192 for (size_t c = 0; c < channelCount; ++c) {
193 tmp[c] = buffers[c] + offset;
194 }
195 wwfm->addSamples(tmp, count);
196 delete[] tmp;
197 }
198 }
168 199
169 if (blockFrame == startFrame || completion > prevCompletion) { 200 if (blockFrame == startFrame || completion > prevCompletion) {
170 model->setCompletion(completion); 201 if (stvm) stvm->setCompletion(completion);
171 prevCompletion = completion; 202 prevCompletion = completion;
172 } 203 }
173 204
174 blockFrame += blockSize; 205 blockFrame += blockSize;
175 } 206 }
176 207
177 model->setCompletion(100); 208 if (stvm) stvm->setCompletion(100);
178 } 209 if (wwfm) wwfm->sync();
179 210 }
211