comparison audio/AudioCallbackPlaySource.cpp @ 741:6508d9d216c7 audio-source-refactor

Comments & tidying
author Chris Cannam
date Mon, 23 Mar 2020 14:14:20 +0000
parents 846970dbef17
children 1c6c10cc5f73
comparison
equal deleted inserted replaced
740:846970dbef17 741:6508d9d216c7
610 } 610 }
611 611
612 void 612 void
613 AudioCallbackPlaySource::setSystemPlaybackTarget(breakfastquay::SystemPlaybackTarget *target) 613 AudioCallbackPlaySource::setSystemPlaybackTarget(breakfastquay::SystemPlaybackTarget *target)
614 { 614 {
615 //!!! This should go, we should be using the ApplicationPlaybackSource callbacks
616
617 if (target == nullptr) { 615 if (target == nullptr) {
618 // reset target-related facts and figures 616 // reset target-related facts and figures
619 m_deviceSampleRate = 0; 617 m_deviceSampleRate = 0;
620 m_deviceChannelCount = 0; 618 m_deviceChannelCount = 0;
621 } 619 }
623 } 621 }
624 622
625 void 623 void
626 AudioCallbackPlaySource::setSystemPlaybackBlockSize(int size) 624 AudioCallbackPlaySource::setSystemPlaybackBlockSize(int size)
627 { 625 {
628 cout << "AudioCallbackPlaySource::setTarget: Block size -> " << size << endl; 626 SVDEBUG << "AudioCallbackPlaySource::setTarget: Block size -> " << size << endl;
629 if (size != 0) { 627 if (size != 0) {
630 m_blockSize = size; 628 m_blockSize = size;
631 } 629 }
632 if (size * 4 > m_ringBufferSize) { 630 if (size * 4 > m_ringBufferSize) {
633 #ifdef DEBUG_AUDIO_PLAY_SOURCE 631 #ifdef DEBUG_AUDIO_PLAY_SOURCE
634 cout << "AudioCallbackPlaySource::setTarget: Buffer size " 632 SVCERR << "AudioCallbackPlaySource::setTarget: Buffer size "
635 << size << " > a quarter of ring buffer size " 633 << size << " > a quarter of ring buffer size "
636 << m_ringBufferSize << ", calling for more ring buffer" 634 << m_ringBufferSize << ", calling for more ring buffer"
637 << endl; 635 << endl;
638 #endif 636 #endif
639 m_ringBufferSize = size * 4; 637 m_ringBufferSize = size * 4;
640 if (m_writeBuffers && !m_writeBuffers->empty()) { 638 if (m_writeBuffers && !m_writeBuffers->empty()) {
641 clearRingBuffers(); 639 clearRingBuffers();
642 } 640 }
719 717
720 bool looping = m_viewManager->getPlayLoopMode(); 718 bool looping = m_viewManager->getPlayLoopMode();
721 719
722 RealTime inbuffer_t = RealTime::frame2RealTime(inbuffer, rate); 720 RealTime inbuffer_t = RealTime::frame2RealTime(inbuffer, rate);
723 721
724 /*!!!
725 sv_frame_t stretchlat = 0;
726 double timeRatio = 1.0;
727
728 if (m_timeStretcher) {
729 stretchlat = m_timeStretcher->getLatency();
730 timeRatio = m_timeStretcher->getTimeRatio();
731 }
732
733 RealTime stretchlat_t = RealTime::frame2RealTime(stretchlat, rate);
734 */
735 // When the target has just requested a block from us, the last 722 // When the target has just requested a block from us, the last
736 // sample it obtained was our buffer fill frame count minus the 723 // sample it obtained was our buffer fill frame count minus the
737 // amount of read space (converted back to source sample rate) 724 // amount of read space (converted back to source sample rate)
738 // remaining now. That sample is not expected to be played until 725 // remaining now. That sample is not expected to be played until
739 // the target's play latency has elapsed. By the time the 726 // the target's play latency has elapsed. By the time the
783 } 770 }
784 771
785 if (m_rangeStarts.empty()) { 772 if (m_rangeStarts.empty()) {
786 // this code is only used in case of error in rebuildRangeLists 773 // this code is only used in case of error in rebuildRangeLists
787 RealTime playing_t = bufferedto_t 774 RealTime playing_t = bufferedto_t
788 //!!! - latency_t - stretchlat_t - lastretrieved_t - inbuffer_t
789 - latency_t - lastretrieved_t - inbuffer_t 775 - latency_t - lastretrieved_t - inbuffer_t
790 + sincerequest_t; 776 + sincerequest_t;
791 if (playing_t < RealTime::zeroTime) playing_t = RealTime::zeroTime; 777 if (playing_t < RealTime::zeroTime) playing_t = RealTime::zeroTime;
792 sv_frame_t frame = RealTime::realTime2Frame(playing_t, rate); 778 sv_frame_t frame = RealTime::realTime2Frame(playing_t, rate);
793 return m_viewManager->alignPlaybackFrameToReference(frame); 779 return m_viewManager->alignPlaybackFrameToReference(frame);
810 } 796 }
811 797
812 RealTime playing_t = bufferedto_t; 798 RealTime playing_t = bufferedto_t;
813 799
814 playing_t = playing_t 800 playing_t = playing_t
815 //!!! - latency_t - stretchlat_t - lastretrieved_t - inbuffer_t
816 - latency_t - lastretrieved_t - inbuffer_t 801 - latency_t - lastretrieved_t - inbuffer_t
817 + sincerequest_t; 802 + sincerequest_t;
818 803
819 // This rather gross little hack is used to ensure that latency 804 // This rather gross little hack is used to ensure that latency
820 // compensation doesn't result in the playback pointer appearing 805 // compensation doesn't result in the playback pointer appearing
829 if (!m_playStartFramePassed) { 814 if (!m_playStartFramePassed) {
830 RealTime playstart_t = RealTime::frame2RealTime(m_playStartFrame, rate); 815 RealTime playstart_t = RealTime::frame2RealTime(m_playStartFrame, rate);
831 if (playing_t < playstart_t) { 816 if (playing_t < playstart_t) {
832 // cout << "playing_t " << playing_t << " < playstart_t " 817 // cout << "playing_t " << playing_t << " < playstart_t "
833 // << playstart_t << endl; 818 // << playstart_t << endl;
834 if (/*!!! sincerequest_t > RealTime::zeroTime && */ 819 if (m_playStartedAt + latency_t <
835 //!!! m_playStartedAt + latency_t + stretchlat_t <
836 m_playStartedAt + latency_t <
837 RealTime::fromSeconds(currentTime)) { 820 RealTime::fromSeconds(currentTime)) {
838 // cout << "but we've been playing for long enough that I think we should disregard it (it probably results from loop wrapping)" << endl; 821 // cout << "but we've been playing for long enough that I think we should disregard it (it probably results from loop wrapping)" << endl;
839 m_playStartFramePassed = true; 822 m_playStartFramePassed = true;
840 } else { 823 } else {
841 playing_t = playstart_t; 824 playing_t = playstart_t;