Mercurial > hg > svapp
comparison audioio/AudioCallbackPlaySource.cpp @ 5:2edc0757ca75
* Fixes to playback of short looped files, of synthesised content within looped
sections, and a few other fixes
author | Chris Cannam |
---|---|
date | Thu, 26 Jan 2006 11:56:09 +0000 |
parents | 5865094175ea |
children | f3d777b693f7 |
comparison
equal
deleted
inserted
replaced
4:5865094175ea | 5:2edc0757ca75 |
---|---|
202 } | 202 } |
203 | 203 |
204 void | 204 void |
205 AudioCallbackPlaySource::play(size_t startFrame) | 205 AudioCallbackPlaySource::play(size_t startFrame) |
206 { | 206 { |
207 if (m_viewManager->getPlaySelectionMode()) { | 207 if (m_viewManager->getPlaySelectionMode() && |
208 !m_viewManager->getSelections().empty()) { | |
208 ViewManager::SelectionList selections = m_viewManager->getSelections(); | 209 ViewManager::SelectionList selections = m_viewManager->getSelections(); |
209 ViewManager::SelectionList::iterator i = selections.begin(); | 210 ViewManager::SelectionList::iterator i = selections.begin(); |
210 if (i != selections.end()) { | 211 if (i != selections.end()) { |
211 if (startFrame < i->getStartFrame()) { | 212 if (startFrame < i->getStartFrame()) { |
212 startFrame = i->getStartFrame(); | 213 startFrame = i->getStartFrame(); |
216 if (startFrame >= j->getEndFrame()) { | 217 if (startFrame >= j->getEndFrame()) { |
217 startFrame = i->getStartFrame(); | 218 startFrame = i->getStartFrame(); |
218 } | 219 } |
219 } | 220 } |
220 } | 221 } |
222 } else { | |
223 if (startFrame >= m_lastModelEndFrame) { | |
224 startFrame = 0; | |
225 } | |
221 } | 226 } |
222 | 227 |
223 // The fill thread will automatically empty its buffers before | 228 // The fill thread will automatically empty its buffers before |
224 // starting again if we have not so far been playing, but not if | 229 // starting again if we have not so far been playing, but not if |
225 // we're just re-seeking. | 230 // we're just re-seeking. |
341 } | 346 } |
342 | 347 |
343 latency += readSpace; | 348 latency += readSpace; |
344 size_t bufferedFrame = m_bufferedToFrame; | 349 size_t bufferedFrame = m_bufferedToFrame; |
345 | 350 |
351 bool looping = m_viewManager->getPlayLoopMode(); | |
352 bool constrained = (m_viewManager->getPlaySelectionMode() && | |
353 !m_viewManager->getSelections().empty()); | |
354 | |
346 size_t framePlaying = bufferedFrame; | 355 size_t framePlaying = bufferedFrame; |
356 | |
357 if (looping && !constrained) { | |
358 while (framePlaying < latency) framePlaying += m_lastModelEndFrame; | |
359 } | |
360 | |
347 if (framePlaying > latency) framePlaying -= latency; | 361 if (framePlaying > latency) framePlaying -= latency; |
348 else { | 362 else framePlaying = 0; |
349 //!!! Not right | 363 |
350 if (m_viewManager->getPlayLoopMode() && | 364 if (!constrained) { |
351 !m_viewManager->getPlaySelectionMode()) { | 365 if (!looping && framePlaying > m_lastModelEndFrame) { |
352 framePlaying += m_lastModelEndFrame; | 366 framePlaying = m_lastModelEndFrame; |
353 if (framePlaying > latency) framePlaying -= latency; | 367 stop(); |
354 else framePlaying = 0; | 368 } |
355 } | |
356 } | |
357 | |
358 if (!m_viewManager->getPlaySelectionMode()) { | |
359 return framePlaying; | 369 return framePlaying; |
360 } | 370 } |
361 | 371 |
362 ViewManager::SelectionList selections = m_viewManager->getSelections(); | 372 ViewManager::SelectionList selections = m_viewManager->getSelections(); |
363 if (selections.empty()) { | |
364 return framePlaying; | |
365 } | |
366 | |
367 ViewManager::SelectionList::const_iterator i; | 373 ViewManager::SelectionList::const_iterator i; |
368 | 374 |
369 i = selections.begin(); | 375 i = selections.begin(); |
370 size_t rangeStart = i->getStartFrame(); | 376 size_t rangeStart = i->getStartFrame(); |
371 | 377 |
384 if (i == selections.end()) { | 390 if (i == selections.end()) { |
385 --i; | 391 --i; |
386 if (i->getEndFrame() + latency < f) { | 392 if (i->getEndFrame() + latency < f) { |
387 // std::cerr << "framePlaying = " << framePlaying << ", rangeEnd = " << rangeEnd << std::endl; | 393 // std::cerr << "framePlaying = " << framePlaying << ", rangeEnd = " << rangeEnd << std::endl; |
388 | 394 |
389 if (!m_viewManager->getPlayLoopMode() && (framePlaying > rangeEnd)) { | 395 if (!looping && (framePlaying > rangeEnd)) { |
390 // std::cerr << "STOPPING" << std::endl; | 396 // std::cerr << "STOPPING" << std::endl; |
391 stop(); | 397 stop(); |
392 return rangeEnd; | 398 return rangeEnd; |
393 } else { | 399 } else { |
394 return framePlaying; | 400 return framePlaying; |
411 framePlaying = 0; | 417 framePlaying = 0; |
412 } | 418 } |
413 break; | 419 break; |
414 } else { | 420 } else { |
415 if (i == selections.begin()) { | 421 if (i == selections.begin()) { |
416 if (m_viewManager->getPlayLoopMode()) { | 422 if (looping) { |
417 i = selections.end(); | 423 i = selections.end(); |
418 } | 424 } |
419 } | 425 } |
420 latency -= offset; | 426 latency -= offset; |
421 --i; | 427 --i; |
841 size_t processed = 0; | 847 size_t processed = 0; |
842 size_t chunkStart = frame; | 848 size_t chunkStart = frame; |
843 size_t chunkSize = count; | 849 size_t chunkSize = count; |
844 size_t nextChunkStart = chunkStart + chunkSize; | 850 size_t nextChunkStart = chunkStart + chunkSize; |
845 | 851 |
846 bool useSelection = (m_viewManager->getPlaySelectionMode() && | 852 bool looping = m_viewManager->getPlayLoopMode(); |
847 !m_viewManager->getSelections().empty()); | 853 bool constrained = (m_viewManager->getPlaySelectionMode() && |
854 !m_viewManager->getSelections().empty()); | |
848 | 855 |
849 static float **chunkBufferPtrs = 0; | 856 static float **chunkBufferPtrs = 0; |
850 static size_t chunkBufferPtrCount = 0; | 857 static size_t chunkBufferPtrCount = 0; |
851 size_t channels = getSourceChannelCount(); | 858 size_t channels = getSourceChannelCount(); |
852 | 859 |
869 chunkSize = count - processed; | 876 chunkSize = count - processed; |
870 nextChunkStart = chunkStart + chunkSize; | 877 nextChunkStart = chunkStart + chunkSize; |
871 | 878 |
872 size_t fadeIn = 0, fadeOut = 0; | 879 size_t fadeIn = 0, fadeOut = 0; |
873 | 880 |
874 if (useSelection) { | 881 if (constrained) { |
875 | 882 |
876 Selection selection = | 883 Selection selection = |
877 m_viewManager->getContainingSelection(chunkStart, true); | 884 m_viewManager->getContainingSelection(chunkStart, true); |
878 | 885 |
879 if (selection.isEmpty()) { | 886 if (selection.isEmpty()) { |
880 if (m_viewManager->getPlayLoopMode()) { | 887 if (looping) { |
881 selection = *m_viewManager->getSelections().begin(); | 888 selection = *m_viewManager->getSelections().begin(); |
882 chunkStart = selection.getStartFrame(); | 889 chunkStart = selection.getStartFrame(); |
883 fadeIn = 50; | 890 fadeIn = 50; |
884 } | 891 } |
885 } | 892 } |
904 } | 911 } |
905 | 912 |
906 chunkSize = nextChunkStart - chunkStart; | 913 chunkSize = nextChunkStart - chunkStart; |
907 } | 914 } |
908 | 915 |
909 } else if (m_viewManager->getPlayLoopMode() && | 916 } else if (looping && m_lastModelEndFrame > 0) { |
910 m_lastModelEndFrame > 0) { | |
911 | 917 |
912 if (chunkStart >= m_lastModelEndFrame) { | 918 if (chunkStart >= m_lastModelEndFrame) { |
913 chunkStart = 0; | 919 chunkStart = 0; |
914 } | 920 } |
915 if (chunkSize > m_lastModelEndFrame - chunkStart) { | 921 if (chunkSize > m_lastModelEndFrame - chunkStart) { |