Mercurial > hg > svapp
comparison audioio/AudioCallbackPlaySource.cpp @ 233:8aace2d9f1c2
Seems to be a bad idea to use plain DEBUG symbol on OS/X (system wants it)
author | Chris Cannam |
---|---|
date | Tue, 14 Jun 2011 15:27:12 +0100 |
parents | 8c13e8219903 |
children | 1fcee2a1c03e f853dfb200de |
comparison
equal
deleted
inserted
replaced
232:025065fd5b49 | 233:8aace2d9f1c2 |
---|---|
99 } | 99 } |
100 | 100 |
101 AudioCallbackPlaySource::~AudioCallbackPlaySource() | 101 AudioCallbackPlaySource::~AudioCallbackPlaySource() |
102 { | 102 { |
103 #ifdef DEBUG_AUDIO_PLAY_SOURCE | 103 #ifdef DEBUG_AUDIO_PLAY_SOURCE |
104 DEBUG << "AudioCallbackPlaySource::~AudioCallbackPlaySource entering" << endl; | 104 SVDEBUG << "AudioCallbackPlaySource::~AudioCallbackPlaySource entering" << endl; |
105 #endif | 105 #endif |
106 m_exiting = true; | 106 m_exiting = true; |
107 | 107 |
108 if (m_fillThread) { | 108 if (m_fillThread) { |
109 #ifdef DEBUG_AUDIO_PLAY_SOURCE | 109 #ifdef DEBUG_AUDIO_PLAY_SOURCE |
134 delete m_monoStretcher; | 134 delete m_monoStretcher; |
135 | 135 |
136 m_bufferScavenger.scavenge(true); | 136 m_bufferScavenger.scavenge(true); |
137 m_pluginScavenger.scavenge(true); | 137 m_pluginScavenger.scavenge(true); |
138 #ifdef DEBUG_AUDIO_PLAY_SOURCE | 138 #ifdef DEBUG_AUDIO_PLAY_SOURCE |
139 DEBUG << "AudioCallbackPlaySource::~AudioCallbackPlaySource finishing" << endl; | 139 SVDEBUG << "AudioCallbackPlaySource::~AudioCallbackPlaySource finishing" << endl; |
140 #endif | 140 #endif |
141 } | 141 } |
142 | 142 |
143 void | 143 void |
144 AudioCallbackPlaySource::addModel(Model *model) | 144 AudioCallbackPlaySource::addModel(Model *model) |
190 // the wrong rate anyway | 190 // the wrong rate anyway |
191 WaveFileModel *wfm = dynamic_cast<WaveFileModel *>(*i); | 191 WaveFileModel *wfm = dynamic_cast<WaveFileModel *>(*i); |
192 if (wfm && wfm != dtvm && | 192 if (wfm && wfm != dtvm && |
193 wfm->getSampleRate() != model->getSampleRate() && | 193 wfm->getSampleRate() != model->getSampleRate() && |
194 wfm->getSampleRate() == m_sourceSampleRate) { | 194 wfm->getSampleRate() == m_sourceSampleRate) { |
195 DEBUG << "AudioCallbackPlaySource::addModel: Conflicting wave file model " << *i << " found" << endl; | 195 SVDEBUG << "AudioCallbackPlaySource::addModel: Conflicting wave file model " << *i << " found" << endl; |
196 conflicting = true; | 196 conflicting = true; |
197 break; | 197 break; |
198 } | 198 } |
199 } | 199 } |
200 | 200 |
201 if (conflicting) { | 201 if (conflicting) { |
202 | 202 |
203 DEBUG << "AudioCallbackPlaySource::addModel: ERROR: " | 203 SVDEBUG << "AudioCallbackPlaySource::addModel: ERROR: " |
204 << "New model sample rate does not match" << endl | 204 << "New model sample rate does not match" << endl |
205 << "existing model(s) (new " << model->getSampleRate() | 205 << "existing model(s) (new " << model->getSampleRate() |
206 << " vs " << m_sourceSampleRate | 206 << " vs " << m_sourceSampleRate |
207 << "), playback will be wrong" | 207 << "), playback will be wrong" |
208 << endl; | 208 << endl; |
264 | 264 |
265 void | 265 void |
266 AudioCallbackPlaySource::modelChanged(size_t startFrame, size_t endFrame) | 266 AudioCallbackPlaySource::modelChanged(size_t startFrame, size_t endFrame) |
267 { | 267 { |
268 #ifdef DEBUG_AUDIO_PLAY_SOURCE | 268 #ifdef DEBUG_AUDIO_PLAY_SOURCE |
269 DEBUG << "AudioCallbackPlaySource::modelChanged(" << startFrame << "," << endFrame << ")" << endl; | 269 SVDEBUG << "AudioCallbackPlaySource::modelChanged(" << startFrame << "," << endFrame << ")" << endl; |
270 #endif | 270 #endif |
271 if (endFrame > m_lastModelEndFrame) { | 271 if (endFrame > m_lastModelEndFrame) { |
272 m_lastModelEndFrame = endFrame; | 272 m_lastModelEndFrame = endFrame; |
273 rebuildRangeLists(); | 273 rebuildRangeLists(); |
274 } | 274 } |
382 AudioCallbackPlaySource::play(size_t startFrame) | 382 AudioCallbackPlaySource::play(size_t startFrame) |
383 { | 383 { |
384 if (m_viewManager->getPlaySelectionMode() && | 384 if (m_viewManager->getPlaySelectionMode() && |
385 !m_viewManager->getSelections().empty()) { | 385 !m_viewManager->getSelections().empty()) { |
386 | 386 |
387 DEBUG << "AudioCallbackPlaySource::play: constraining frame " << startFrame << " to selection = "; | 387 SVDEBUG << "AudioCallbackPlaySource::play: constraining frame " << startFrame << " to selection = "; |
388 | 388 |
389 startFrame = m_viewManager->constrainFrameToSelection(startFrame); | 389 startFrame = m_viewManager->constrainFrameToSelection(startFrame); |
390 | 390 |
391 DEBUG << startFrame << endl; | 391 SVDEBUG << startFrame << endl; |
392 | 392 |
393 } else { | 393 } else { |
394 if (startFrame >= m_lastModelEndFrame) { | 394 if (startFrame >= m_lastModelEndFrame) { |
395 startFrame = 0; | 395 startFrame = 0; |
396 } | 396 } |
464 | 464 |
465 void | 465 void |
466 AudioCallbackPlaySource::stop() | 466 AudioCallbackPlaySource::stop() |
467 { | 467 { |
468 #ifdef DEBUG_AUDIO_PLAY_SOURCE | 468 #ifdef DEBUG_AUDIO_PLAY_SOURCE |
469 DEBUG << "AudioCallbackPlaySource::stop()" << endl; | 469 SVDEBUG << "AudioCallbackPlaySource::stop()" << endl; |
470 #endif | 470 #endif |
471 bool changed = m_playing; | 471 bool changed = m_playing; |
472 m_playing = false; | 472 m_playing = false; |
473 | 473 |
474 #ifdef DEBUG_AUDIO_PLAY_SOURCE | 474 #ifdef DEBUG_AUDIO_PLAY_SOURCE |
553 std::cout << "AudioCallbackPlaySource::setTarget: Block size -> " << size << std::endl; | 553 std::cout << "AudioCallbackPlaySource::setTarget: Block size -> " << size << std::endl; |
554 if (size != 0) { | 554 if (size != 0) { |
555 m_blockSize = size; | 555 m_blockSize = size; |
556 } | 556 } |
557 if (size * 4 > m_ringBufferSize) { | 557 if (size * 4 > m_ringBufferSize) { |
558 DEBUG << "AudioCallbackPlaySource::setTarget: Buffer size " | 558 SVDEBUG << "AudioCallbackPlaySource::setTarget: Buffer size " |
559 << size << " > a quarter of ring buffer size " | 559 << size << " > a quarter of ring buffer size " |
560 << m_ringBufferSize << ", calling for more ring buffer" | 560 << m_ringBufferSize << ", calling for more ring buffer" |
561 << endl; | 561 << endl; |
562 m_ringBufferSize = size * 4; | 562 m_ringBufferSize = size * 4; |
563 if (m_writeBuffers && !m_writeBuffers->empty()) { | 563 if (m_writeBuffers && !m_writeBuffers->empty()) { |
846 | 846 |
847 MultiSelection::SelectionList selections = m_viewManager->getSelections(); | 847 MultiSelection::SelectionList selections = m_viewManager->getSelections(); |
848 MultiSelection::SelectionList::const_iterator i; | 848 MultiSelection::SelectionList::const_iterator i; |
849 | 849 |
850 #ifdef DEBUG_AUDIO_PLAY_SOURCE | 850 #ifdef DEBUG_AUDIO_PLAY_SOURCE |
851 DEBUG << "AudioCallbackPlaySource::rebuildRangeLists" << endl; | 851 SVDEBUG << "AudioCallbackPlaySource::rebuildRangeLists" << endl; |
852 #endif | 852 #endif |
853 | 853 |
854 if (!selections.empty()) { | 854 if (!selections.empty()) { |
855 | 855 |
856 for (i = selections.begin(); i != selections.end(); ++i) { | 856 for (i = selections.begin(); i != selections.end(); ++i) { |
966 { | 966 { |
967 if (q == m_resampleQuality) return; | 967 if (q == m_resampleQuality) return; |
968 m_resampleQuality = q; | 968 m_resampleQuality = q; |
969 | 969 |
970 #ifdef DEBUG_AUDIO_PLAY_SOURCE | 970 #ifdef DEBUG_AUDIO_PLAY_SOURCE |
971 DEBUG << "AudioCallbackPlaySource::setResampleQuality: setting to " | 971 SVDEBUG << "AudioCallbackPlaySource::setResampleQuality: setting to " |
972 << m_resampleQuality << endl; | 972 << m_resampleQuality << endl; |
973 #endif | 973 #endif |
974 | 974 |
975 initialiseConverter(); | 975 initialiseConverter(); |
976 } | 976 } |
1066 { | 1066 { |
1067 int count = ucount; | 1067 int count = ucount; |
1068 | 1068 |
1069 if (!m_playing) { | 1069 if (!m_playing) { |
1070 #ifdef DEBUG_AUDIO_PLAY_SOURCE_PLAYING | 1070 #ifdef DEBUG_AUDIO_PLAY_SOURCE_PLAYING |
1071 DEBUG << "AudioCallbackPlaySource::getSourceSamples: Not playing" << endl; | 1071 SVDEBUG << "AudioCallbackPlaySource::getSourceSamples: Not playing" << endl; |
1072 #endif | 1072 #endif |
1073 for (size_t ch = 0; ch < getTargetChannelCount(); ++ch) { | 1073 for (size_t ch = 0; ch < getTargetChannelCount(); ++ch) { |
1074 for (int i = 0; i < count; ++i) { | 1074 for (int i = 0; i < count; ++i) { |
1075 buffer[ch][i] = 0.0; | 1075 buffer[ch][i] = 0.0; |
1076 } | 1076 } |
1077 } | 1077 } |
1078 return 0; | 1078 return 0; |
1079 } | 1079 } |
1080 | 1080 |
1081 #ifdef DEBUG_AUDIO_PLAY_SOURCE_PLAYING | 1081 #ifdef DEBUG_AUDIO_PLAY_SOURCE_PLAYING |
1082 DEBUG << "AudioCallbackPlaySource::getSourceSamples: Playing" << endl; | 1082 SVDEBUG << "AudioCallbackPlaySource::getSourceSamples: Playing" << endl; |
1083 #endif | 1083 #endif |
1084 | 1084 |
1085 // Ensure that all buffers have at least the amount of data we | 1085 // Ensure that all buffers have at least the amount of data we |
1086 // need -- else reduce the size of our requests correspondingly | 1086 // need -- else reduce the size of our requests correspondingly |
1087 | 1087 |
1228 } | 1228 } |
1229 if (gotHere < got) got = gotHere; | 1229 if (gotHere < got) got = gotHere; |
1230 | 1230 |
1231 #ifdef DEBUG_AUDIO_PLAY_SOURCE_PLAYING | 1231 #ifdef DEBUG_AUDIO_PLAY_SOURCE_PLAYING |
1232 if (c == 0) { | 1232 if (c == 0) { |
1233 DEBUG << "feeding stretcher: got " << gotHere | 1233 SVDEBUG << "feeding stretcher: got " << gotHere |
1234 << ", " << rb->getReadSpace() << " remain" << endl; | 1234 << ", " << rb->getReadSpace() << " remain" << endl; |
1235 } | 1235 } |
1236 #endif | 1236 #endif |
1237 | 1237 |
1238 } else { | 1238 } else { |
1720 if ((m_writeBufferFill + m_blockSize * 2) < | 1720 if ((m_writeBufferFill + m_blockSize * 2) < |
1721 m_lastModelEndFrame) { | 1721 m_lastModelEndFrame) { |
1722 // OK, we don't have enough and there's more to | 1722 // OK, we don't have enough and there's more to |
1723 // read -- don't unify until we can do better | 1723 // read -- don't unify until we can do better |
1724 #ifdef DEBUG_AUDIO_PLAY_SOURCE_PLAYING | 1724 #ifdef DEBUG_AUDIO_PLAY_SOURCE_PLAYING |
1725 DEBUG << "AudioCallbackPlaySource::unifyRingBuffers: Not unifying: write buffer has less (" << wb->getReadSpace() << ") than " << m_blockSize*2 << " to read and write buffer fill (" << m_writeBufferFill << ") is not close to end frame (" << m_lastModelEndFrame << ")" << endl; | 1725 SVDEBUG << "AudioCallbackPlaySource::unifyRingBuffers: Not unifying: write buffer has less (" << wb->getReadSpace() << ") than " << m_blockSize*2 << " to read and write buffer fill (" << m_writeBufferFill << ") is not close to end frame (" << m_lastModelEndFrame << ")" << endl; |
1726 #endif | 1726 #endif |
1727 return; | 1727 return; |
1728 } | 1728 } |
1729 } | 1729 } |
1730 break; | 1730 break; |
1740 if (rs < rf) rf -= rs; | 1740 if (rs < rf) rf -= rs; |
1741 else rf = 0; | 1741 else rf = 0; |
1742 } | 1742 } |
1743 | 1743 |
1744 #ifdef DEBUG_AUDIO_PLAY_SOURCE_PLAYING | 1744 #ifdef DEBUG_AUDIO_PLAY_SOURCE_PLAYING |
1745 DEBUG << "AudioCallbackPlaySource::unifyRingBuffers: m_readBufferFill = " << m_readBufferFill << ", rf = " << rf << ", m_writeBufferFill = " << m_writeBufferFill << endl; | 1745 SVDEBUG << "AudioCallbackPlaySource::unifyRingBuffers: m_readBufferFill = " << m_readBufferFill << ", rf = " << rf << ", m_writeBufferFill = " << m_writeBufferFill << endl; |
1746 #endif | 1746 #endif |
1747 | 1747 |
1748 size_t wf = m_writeBufferFill; | 1748 size_t wf = m_writeBufferFill; |
1749 size_t skip = 0; | 1749 size_t skip = 0; |
1750 for (size_t c = 0; c < getTargetChannelCount(); ++c) { | 1750 for (size_t c = 0; c < getTargetChannelCount(); ++c) { |