comparison audioio/AudioCallbackPlaySource.cpp @ 31:37af203dbd15

* Buffer size fixes in the time stretcher, to avoid running out of input data for large or small ratios
author Chris Cannam
date Thu, 21 Sep 2006 09:43:41 +0000
parents d88d117e0c34
children e3b32dc5180b
comparison
equal deleted inserted replaced
30:56e1d4242bb4 31:37af203dbd15
617 PhaseVocoderTimeStretcher *newStretcher = new PhaseVocoderTimeStretcher 617 PhaseVocoderTimeStretcher *newStretcher = new PhaseVocoderTimeStretcher
618 (getTargetSampleRate(), 618 (getTargetSampleRate(),
619 channels, 619 channels,
620 factor, 620 factor,
621 sharpen, 621 sharpen,
622 lrintf(getTargetBlockSize() / factor)); 622 getTargetBlockSize());
623 623
624 m_timeStretcher = newStretcher; 624 m_timeStretcher = newStretcher;
625 625
626 } else { 626 } else {
627 m_timeStretcher = 0; 627 m_timeStretcher = 0;
685 685
686 size_t channels = getTargetChannelCount(); 686 size_t channels = getTargetChannelCount();
687 bool mix = (channels > 1 && ts->getChannelCount() == 1); 687 bool mix = (channels > 1 && ts->getChannelCount() == 1);
688 688
689 size_t available; 689 size_t available;
690
691 int warned = 0;
692
693
694
695 //!!!
696 // We want output blocks of e.g. 1024 (probably fixed, certainly
697 // bounded). We can provide input blocks of any size (unbounded)
698 // at the timestretcher's request. The input block for a given
699 // output is approx output / ratio, but we can't predict it
700 // exactly, for an adaptive timestretcher. The stretcher will
701 // need some additional buffer space.
702
703
704
690 705
691 while ((available = ts->getAvailableOutputSamples()) < count) { 706 while ((available = ts->getAvailableOutputSamples()) < count) {
692 707
693 size_t reqd = lrintf((count - available) / ratio); 708 size_t reqd = lrintf((count - available) / ratio);
694 reqd = std::max(reqd, ts->getRequiredInputSamples()); 709 reqd = std::max(reqd, ts->getRequiredInputSamples());
733 } 748 }
734 749
735 if (got == 0) break; 750 if (got == 0) break;
736 751
737 if (ts->getAvailableOutputSamples() == available) { 752 if (ts->getAvailableOutputSamples() == available) {
738 std::cerr << "WARNING: AudioCallbackPlaySource::getSamples: Added " << got << " samples to time stretcher, created no new available output samples" << std::endl; 753 std::cerr << "WARNING: AudioCallbackPlaySource::getSamples: Added " << got << " samples to time stretcher, created no new available output samples (warned = " << warned << ")" << std::endl;
739 break; 754 if (++warned == 5) break;
740 } 755 }
741 } 756 }
742 757
743 ts->getOutput(buffer, count); 758 ts->getOutput(buffer, count);
744 759