comparison transform/RealTimePluginTransform.cpp @ 40:75c5951cf9d7

* Some fixes to updating of writable wave file models
author Chris Cannam
date Tue, 03 Oct 2006 15:01:50 +0000
parents f18093617b78
children 5a72bf7490ae
comparison
equal deleted inserted replaced
39:f18093617b78 40:75c5951cf9d7
143 ( (endFrame - startFrame) / blockSize); 143 ( (endFrame - startFrame) / blockSize);
144 144
145 size_t got = 0; 145 size_t got = 0;
146 146
147 if (channelCount == 1) { 147 if (channelCount == 1) {
148 got = input->getValues 148 if (buffers && buffers[0]) {
149 (m_context.channel, blockFrame, blockFrame + blockSize, buffers[0]); 149 got = input->getValues
150 while (got < blockSize) { 150 (m_context.channel, blockFrame, blockFrame + blockSize, buffers[0]);
151 buffers[0][got++] = 0.0; 151 while (got < blockSize) {
152 } 152 buffers[0][got++] = 0.0;
153 if (m_context.channel == -1 && channelCount > 1) {
154 // use mean instead of sum, as plugin input
155 for (size_t i = 0; i < got; ++i) {
156 buffers[0][i] /= channelCount;
157 } 153 }
158 } 154 if (m_context.channel == -1 && channelCount > 1) {
155 // use mean instead of sum, as plugin input
156 for (size_t i = 0; i < got; ++i) {
157 buffers[0][i] /= channelCount;
158 }
159 }
160 }
159 } else { 161 } else {
160 for (size_t ch = 0; ch < channelCount; ++ch) { 162 for (size_t ch = 0; ch < channelCount; ++ch) {
161 got = input->getValues 163 if (buffers && buffers[ch]) {
162 (ch, blockFrame, blockFrame + blockSize, buffers[ch]); 164 got = input->getValues
163 while (got < blockSize) { 165 (ch, blockFrame, blockFrame + blockSize, buffers[ch]);
164 buffers[ch][got++] = 0.0; 166 while (got < blockSize) {
165 } 167 buffers[ch][got++] = 0.0;
168 }
169 }
166 } 170 }
167 } 171 }
168 172
169 m_plugin->run(Vamp::RealTime::frame2RealTime(blockFrame, sampleRate)); 173 m_plugin->run(Vamp::RealTime::frame2RealTime(blockFrame, sampleRate));
170 174
181 185
182 } else if (wwfm) { 186 } else if (wwfm) {
183 187
184 float **buffers = m_plugin->getAudioOutputBuffers(); 188 float **buffers = m_plugin->getAudioOutputBuffers();
185 189
186 if (blockFrame >= latency) { 190 if (buffers) {
187 wwfm->addSamples(buffers, blockSize); 191
188 } else if (blockFrame + blockSize >= latency) { 192 //!!! This will fail if any buffers[c] is null or
189 size_t offset = latency - blockFrame; 193 //uninitialised. The plugin instance should ensure
190 size_t count = blockSize - offset; 194 //that that can't happen -- but it doesn't
191 float **tmp = new float *[channelCount]; 195
192 for (size_t c = 0; c < channelCount; ++c) { 196 if (blockFrame >= latency) {
193 tmp[c] = buffers[c] + offset; 197 wwfm->addSamples(buffers, blockSize);
198 } else if (blockFrame + blockSize >= latency) {
199 size_t offset = latency - blockFrame;
200 size_t count = blockSize - offset;
201 float **tmp = new float *[channelCount];
202 for (size_t c = 0; c < channelCount; ++c) {
203 tmp[c] = buffers[c] + offset;
204 }
205 wwfm->addSamples(tmp, count);
206 delete[] tmp;
194 } 207 }
195 wwfm->addSamples(tmp, count);
196 delete[] tmp;
197 } 208 }
198 } 209 }
199 210
200 if (blockFrame == startFrame || completion > prevCompletion) { 211 if (blockFrame == startFrame || completion > prevCompletion) {
201 if (stvm) stvm->setCompletion(completion); 212 if (stvm) stvm->setCompletion(completion);