Mercurial > hg > sonic-visualiser
comparison transform/RealTimePluginTransform.cpp @ 184:ebd906049fb6
* Change WaveFileModel API from getValues(start,end) to getData(start,count).
It's much less error-prone to pass in frame counts instead of start/end
locations. Should have done this ages ago. This closes #1794563.
* Add option to apply a transform to only the selection region, instead of
the whole audio.
* (to make the above work properly) Add start frame offset to wave models
author | Chris Cannam |
---|---|
date | Mon, 01 Oct 2007 13:48:38 +0000 |
parents | 3e5a32a2acf4 |
children |
comparison
equal
deleted
inserted
replaced
183:3fdaf3157eea | 184:ebd906049fb6 |
---|---|
136 | 136 |
137 size_t sampleRate = input->getSampleRate(); | 137 size_t sampleRate = input->getSampleRate(); |
138 size_t channelCount = input->getChannelCount(); | 138 size_t channelCount = input->getChannelCount(); |
139 if (!wwfm && m_context.channel != -1) channelCount = 1; | 139 if (!wwfm && m_context.channel != -1) channelCount = 1; |
140 | 140 |
141 size_t blockSize = m_plugin->getBufferSize(); | 141 long blockSize = m_plugin->getBufferSize(); |
142 | 142 |
143 float **inbufs = m_plugin->getAudioInputBuffers(); | 143 float **inbufs = m_plugin->getAudioInputBuffers(); |
144 | 144 |
145 size_t startFrame = m_input->getStartFrame(); | 145 long startFrame = m_input->getStartFrame(); |
146 size_t endFrame = m_input->getEndFrame(); | 146 long endFrame = m_input->getEndFrame(); |
147 size_t blockFrame = startFrame; | 147 |
148 | 148 long contextStart = m_context.startFrame; |
149 size_t prevCompletion = 0; | 149 long contextDuration = m_context.duration; |
150 | 150 |
151 size_t latency = m_plugin->getLatency(); | 151 if (contextStart == 0 || contextStart < startFrame) { |
152 | 152 contextStart = startFrame; |
153 while (blockFrame < endFrame + latency && !m_abandoned) { | 153 } |
154 | 154 |
155 size_t completion = | 155 if (contextDuration == 0) { |
156 (((blockFrame - startFrame) / blockSize) * 99) / | 156 contextDuration = endFrame - contextStart; |
157 ( (endFrame - startFrame) / blockSize); | 157 } |
158 | 158 if (contextStart + contextDuration > endFrame) { |
159 size_t got = 0; | 159 contextDuration = endFrame - contextStart; |
160 } | |
161 | |
162 wwfm->setStartFrame(contextStart); | |
163 | |
164 long blockFrame = contextStart; | |
165 | |
166 long prevCompletion = 0; | |
167 | |
168 long latency = m_plugin->getLatency(); | |
169 | |
170 while (blockFrame < contextStart + contextDuration + latency && | |
171 !m_abandoned) { | |
172 | |
173 long completion = | |
174 (((blockFrame - contextStart) / blockSize) * 99) / | |
175 ((contextDuration) / blockSize); | |
176 | |
177 long got = 0; | |
160 | 178 |
161 if (channelCount == 1) { | 179 if (channelCount == 1) { |
162 if (inbufs && inbufs[0]) { | 180 if (inbufs && inbufs[0]) { |
163 got = input->getValues | 181 got = input->getData |
164 (m_context.channel, blockFrame, blockFrame + blockSize, inbufs[0]); | 182 (m_context.channel, blockFrame, blockSize, inbufs[0]); |
165 while (got < blockSize) { | 183 while (got < blockSize) { |
166 inbufs[0][got++] = 0.0; | 184 inbufs[0][got++] = 0.0; |
167 } | 185 } |
168 } | 186 } |
169 for (size_t ch = 1; ch < m_plugin->getAudioInputCount(); ++ch) { | 187 for (size_t ch = 1; ch < m_plugin->getAudioInputCount(); ++ch) { |
170 for (size_t i = 0; i < blockSize; ++i) { | 188 for (long i = 0; i < blockSize; ++i) { |
171 inbufs[ch][i] = inbufs[0][i]; | 189 inbufs[ch][i] = inbufs[0][i]; |
172 } | 190 } |
173 } | 191 } |
174 } else { | 192 } else { |
175 for (size_t ch = 0; ch < channelCount; ++ch) { | 193 for (size_t ch = 0; ch < channelCount; ++ch) { |
176 if (inbufs && inbufs[ch]) { | 194 if (inbufs && inbufs[ch]) { |
177 got = input->getValues | 195 got = input->getData |
178 (ch, blockFrame, blockFrame + blockSize, inbufs[ch]); | 196 (ch, blockFrame, blockSize, inbufs[ch]); |
179 while (got < blockSize) { | 197 while (got < blockSize) { |
180 inbufs[ch][got++] = 0.0; | 198 inbufs[ch][got++] = 0.0; |
181 } | 199 } |
182 } | 200 } |
183 } | 201 } |
184 for (size_t ch = channelCount; ch < m_plugin->getAudioInputCount(); ++ch) { | 202 for (size_t ch = channelCount; ch < m_plugin->getAudioInputCount(); ++ch) { |
185 for (size_t i = 0; i < blockSize; ++i) { | 203 for (long i = 0; i < blockSize; ++i) { |
186 inbufs[ch][i] = inbufs[ch % channelCount][i]; | 204 inbufs[ch][i] = inbufs[ch % channelCount][i]; |
187 } | 205 } |
188 } | 206 } |
189 } | 207 } |
190 | 208 |
206 | 224 |
207 if (stvm) { | 225 if (stvm) { |
208 | 226 |
209 float value = m_plugin->getControlOutputValue(m_outputNo); | 227 float value = m_plugin->getControlOutputValue(m_outputNo); |
210 | 228 |
211 size_t pointFrame = blockFrame; | 229 long pointFrame = blockFrame; |
212 if (pointFrame > latency) pointFrame -= latency; | 230 if (pointFrame > latency) pointFrame -= latency; |
213 else pointFrame = 0; | 231 else pointFrame = 0; |
214 | 232 |
215 stvm->addPoint(SparseTimeValueModel::Point | 233 stvm->addPoint(SparseTimeValueModel::Point |
216 (pointFrame, value, "")); | 234 (pointFrame, value, "")); |
220 float **outbufs = m_plugin->getAudioOutputBuffers(); | 238 float **outbufs = m_plugin->getAudioOutputBuffers(); |
221 | 239 |
222 if (outbufs) { | 240 if (outbufs) { |
223 | 241 |
224 if (blockFrame >= latency) { | 242 if (blockFrame >= latency) { |
225 size_t writeSize = std::min(blockSize, | 243 long writeSize = std::min |
226 endFrame + latency - blockFrame); | 244 (blockSize, |
245 contextStart + contextDuration + latency - blockFrame); | |
227 wwfm->addSamples(outbufs, writeSize); | 246 wwfm->addSamples(outbufs, writeSize); |
228 } else if (blockFrame + blockSize >= latency) { | 247 } else if (blockFrame + blockSize >= latency) { |
229 size_t offset = latency - blockFrame; | 248 long offset = latency - blockFrame; |
230 size_t count = blockSize - offset; | 249 long count = blockSize - offset; |
231 float **tmp = new float *[channelCount]; | 250 float **tmp = new float *[channelCount]; |
232 for (size_t c = 0; c < channelCount; ++c) { | 251 for (size_t c = 0; c < channelCount; ++c) { |
233 tmp[c] = outbufs[c] + offset; | 252 tmp[c] = outbufs[c] + offset; |
234 } | 253 } |
235 wwfm->addSamples(tmp, count); | 254 wwfm->addSamples(tmp, count); |
236 delete[] tmp; | 255 delete[] tmp; |
237 } | 256 } |
238 } | 257 } |
239 } | 258 } |
240 | 259 |
241 if (blockFrame == startFrame || completion > prevCompletion) { | 260 if (blockFrame == contextStart || completion > prevCompletion) { |
242 if (stvm) stvm->setCompletion(completion); | 261 if (stvm) stvm->setCompletion(completion); |
243 if (wwfm) wwfm->setCompletion(completion); | 262 if (wwfm) wwfm->setCompletion(completion); |
244 prevCompletion = completion; | 263 prevCompletion = completion; |
245 } | 264 } |
246 | 265 |