Mercurial > hg > svapp
changeset 1:97c69acdcb82
* Adjust use of target sample rate, so as to make the decision about whether
to resample or not more robust.
* Update copyrights to 2006
author | Chris Cannam |
---|---|
date | Thu, 12 Jan 2006 13:45:06 +0000 |
parents | db6fcbd4405c |
children | df5923e33d01 |
files | audioio/AudioCallbackPlaySource.cpp audioio/AudioCallbackPlayTarget.h |
diffstat | 2 files changed, 38 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/audioio/AudioCallbackPlaySource.cpp Tue Jan 10 16:33:16 2006 +0000 +++ b/audioio/AudioCallbackPlaySource.cpp Thu Jan 12 13:45:06 2006 +0000 @@ -2,7 +2,7 @@ /* A waveform viewer and audio annotation editor. - Chris Cannam, Queen Mary University of London, 2005 + Chris Cannam, Queen Mary University of London, 2005-2006 This is experimental software. Not for distribution. */ @@ -118,22 +118,10 @@ } if (buffersChanged || srChanged) { - if (m_converter) { src_delete(m_converter); m_converter = 0; } - - if (getSourceSampleRate() != getTargetSampleRate()) { - - int err = 0; - m_converter = src_new(SRC_SINC_FASTEST, m_bufferCount, &err); - if (!m_converter) { - std::cerr - << "AudioCallbackPlaySource::setModel: ERROR in creating samplerate converter: " - << src_strerror(err) << std::endl; - } - } } m_audioGenerator->addModel(model); @@ -148,10 +136,9 @@ #ifdef DEBUG_AUDIO_PLAY_SOURCE std::cerr << "AudioCallbackPlaySource::addModel: emitting modelReplaced" << std::endl; #endif - emit modelReplaced(); - if (srChanged && (getSourceSampleRate() != getTargetSampleRate())) { - emit sampleRateMismatch(getSourceSampleRate(), getTargetSampleRate()); + if (buffersChanged || srChanged) { + emit modelReplaced(); } } @@ -323,6 +310,19 @@ AudioCallbackPlaySource::setTargetSampleRate(size_t sr) { m_targetSampleRate = sr; + + if (getSourceSampleRate() != getTargetSampleRate()) { + + int err = 0; + m_converter = src_new(SRC_SINC_BEST_QUALITY, m_bufferCount, &err); + if (!m_converter) { + std::cerr + << "AudioCallbackPlaySource::setModel: ERROR in creating samplerate converter: " + << src_strerror(err) << std::endl; + } + + emit sampleRateMismatch(getSourceSampleRate(), getTargetSampleRate()); + } } size_t @@ -543,6 +543,11 @@ #endif bool resample = (getSourceSampleRate() != getTargetSampleRate()); + +#ifdef DEBUG_AUDIO_PLAY_SOURCE + std::cout << (resample ? "" : "not ") << "resampling (source " << getSourceSampleRate() << ", target " << getTargetSampleRate() << ")" << std::endl; +#endif + size_t channels = getSourceChannelCount(); size_t orig = space; size_t got = 0; @@ -558,6 +563,14 @@ size_t generatorBlockSize = m_audioGenerator->getBlockSize(); + if (resample && !m_converter) { + static bool warned = false; + if (!warned) { + std::cerr << "WARNING: sample rates differ, but no converter available!" << std::endl; + warned = true; + } + } + if (resample && m_converter) { double ratio =
--- a/audioio/AudioCallbackPlayTarget.h Tue Jan 10 16:33:16 2006 +0000 +++ b/audioio/AudioCallbackPlayTarget.h Thu Jan 12 13:45:06 2006 +0000 @@ -2,7 +2,7 @@ /* A waveform viewer and audio annotation editor. - Chris Cannam, Queen Mary University of London, 2005 + Chris Cannam, Queen Mary University of London, 2005-2006 This is experimental software. Not for distribution. */ @@ -34,6 +34,14 @@ */ virtual void setOutputGain(float gain); + /** + * The main source model (providing the playback sample rate) has + * been changed. The target should query the source's sample + * rate, set its output sample rate accordingly, and call back on + * the source's setTargetSampleRate to indicate what sample rate + * it succeeded in setting at the output. If this differs from + * the model rate, the source will resample. + */ virtual void sourceModelReplaced() = 0; protected: