Mercurial > hg > sonic-visualiser
comparison audioio/AudioCallbackPlaySource.cpp @ 15:cc566264c935
* timestretcher improvements -- simplify API (it can calculate its own
processing block sizes etc)
author | Chris Cannam |
---|---|
date | Wed, 13 Sep 2006 11:56:44 +0000 |
parents | 085f34c73939 |
children | 3715efc38f95 |
comparison
equal
deleted
inserted
replaced
14:085f34c73939 | 15:cc566264c935 |
---|---|
596 { | 596 { |
597 // std::cerr << "TimeStretcherData::TimeStretcherData(" << channels << ", " << factor << ", " << blockSize << ")" << std::endl; | 597 // std::cerr << "TimeStretcherData::TimeStretcherData(" << channels << ", " << factor << ", " << blockSize << ")" << std::endl; |
598 | 598 |
599 for (size_t ch = 0; ch < channels; ++ch) { | 599 for (size_t ch = 0; ch < channels; ++ch) { |
600 | 600 |
601 m_stretcher[ch] = StretcherBuffer | 601 m_stretcher[ch] = new PhaseVocoderTimeStretcher(factor, blockSize); |
602 //!!! | |
603 (new PhaseVocoderTimeStretcher(factor, | |
604 blockSize, | |
605 // 128), | 602 // 128), |
606 (blockSize/2) / factor), | 603 // (blockSize/2) / factor), |
607 new float[lrintf(blockSize * factor)]); | 604 // new float[lrintf(blockSize * factor)]); |
608 } | 605 } |
609 m_stretchInputBuffer = new float[blockSize]; | |
610 } | 606 } |
611 | 607 |
612 AudioCallbackPlaySource::TimeStretcherData::~TimeStretcherData() | 608 AudioCallbackPlaySource::TimeStretcherData::~TimeStretcherData() |
613 { | 609 { |
614 // std::cerr << "TimeStretcherData::~TimeStretcherData" << std::endl; | 610 // std::cerr << "TimeStretcherData::~TimeStretcherData" << std::endl; |
615 | 611 |
616 while (!m_stretcher.empty()) { | 612 while (!m_stretcher.empty()) { |
617 delete m_stretcher.begin()->second.first; | 613 delete m_stretcher.begin()->second; |
618 delete[] m_stretcher.begin()->second.second; | 614 // delete[] m_stretcher.begin()->second.second; |
619 m_stretcher.erase(m_stretcher.begin()); | 615 m_stretcher.erase(m_stretcher.begin()); |
620 } | 616 } |
621 delete m_stretchInputBuffer; | 617 // delete m_stretchInputBuffer; |
622 } | 618 } |
623 | 619 |
624 PhaseVocoderTimeStretcher * | 620 PhaseVocoderTimeStretcher * |
625 AudioCallbackPlaySource::TimeStretcherData::getStretcher(size_t channel) | 621 AudioCallbackPlaySource::TimeStretcherData::getStretcher(size_t channel) |
626 { | 622 { |
627 return m_stretcher[channel].first; | 623 return m_stretcher[channel]; |
628 } | 624 } |
629 | 625 /* |
630 float * | 626 float * |
631 AudioCallbackPlaySource::TimeStretcherData::getOutputBuffer(size_t channel) | 627 AudioCallbackPlaySource::TimeStretcherData::getOutputBuffer(size_t channel) |
632 { | 628 { |
633 return m_stretcher[channel].second; | 629 return m_stretcher[channel].second; |
634 } | 630 } |
644 { | 640 { |
645 getStretcher(channel)->process(getInputBuffer(), | 641 getStretcher(channel)->process(getInputBuffer(), |
646 getOutputBuffer(channel), | 642 getOutputBuffer(channel), |
647 m_blockSize); | 643 m_blockSize); |
648 } | 644 } |
649 | 645 */ |
650 void | 646 void |
651 AudioCallbackPlaySource::setSlowdownFactor(float factor) | 647 AudioCallbackPlaySource::setSlowdownFactor(float factor) |
652 { | 648 { |
653 // Avoid locks -- create, assign, mark old one for scavenging | 649 // Avoid locks -- create, assign, mark old one for scavenging |
654 // later (as a call to getSourceSamples may still be using it) | 650 // later (as a call to getSourceSamples may still be using it) |
663 TimeStretcherData *newStretcher = new TimeStretcherData | 659 TimeStretcherData *newStretcher = new TimeStretcherData |
664 (getTargetChannelCount(), factor, | 660 (getTargetChannelCount(), factor, |
665 // factor > 1 ? getTargetBlockSize() : getTargetBlockSize() / factor); | 661 // factor > 1 ? getTargetBlockSize() : getTargetBlockSize() / factor); |
666 //!!! doesn't work if the block size > getTargetBlockSize(), but it | 662 //!!! doesn't work if the block size > getTargetBlockSize(), but it |
667 // should be made to | 663 // should be made to |
668 getTargetBlockSize()); | 664 // getTargetBlockSize()); |
665 lrintf(getTargetBlockSize() / factor)); | |
669 m_slowdownCounter = 0; | 666 m_slowdownCounter = 0; |
670 m_timeStretcher = newStretcher; | 667 m_timeStretcher = newStretcher; |
671 } else { | 668 } else { |
672 m_timeStretcher = 0; | 669 m_timeStretcher = 0; |
673 } | 670 } |