Mercurial > hg > svapp
comparison audioio/AudioCallbackPlaySource.cpp @ 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 | 75c3ea1c3a32 |
comparison
equal
deleted
inserted
replaced
0:db6fcbd4405c | 1:97c69acdcb82 |
---|---|
1 /* -*- c-basic-offset: 4 -*- vi:set ts=8 sts=4 sw=4: */ | 1 /* -*- c-basic-offset: 4 -*- vi:set ts=8 sts=4 sw=4: */ |
2 | 2 |
3 /* | 3 /* |
4 A waveform viewer and audio annotation editor. | 4 A waveform viewer and audio annotation editor. |
5 Chris Cannam, Queen Mary University of London, 2005 | 5 Chris Cannam, Queen Mary University of London, 2005-2006 |
6 | 6 |
7 This is experimental software. Not for distribution. | 7 This is experimental software. Not for distribution. |
8 */ | 8 */ |
9 | 9 |
10 #include "AudioCallbackPlaySource.h" | 10 #include "AudioCallbackPlaySource.h" |
116 if (buffersChanged) { | 116 if (buffersChanged) { |
117 m_audioGenerator->setTargetChannelCount(m_bufferCount); | 117 m_audioGenerator->setTargetChannelCount(m_bufferCount); |
118 } | 118 } |
119 | 119 |
120 if (buffersChanged || srChanged) { | 120 if (buffersChanged || srChanged) { |
121 | |
122 if (m_converter) { | 121 if (m_converter) { |
123 src_delete(m_converter); | 122 src_delete(m_converter); |
124 m_converter = 0; | 123 m_converter = 0; |
125 } | 124 } |
126 | |
127 if (getSourceSampleRate() != getTargetSampleRate()) { | |
128 | |
129 int err = 0; | |
130 m_converter = src_new(SRC_SINC_FASTEST, m_bufferCount, &err); | |
131 if (!m_converter) { | |
132 std::cerr | |
133 << "AudioCallbackPlaySource::setModel: ERROR in creating samplerate converter: " | |
134 << src_strerror(err) << std::endl; | |
135 } | |
136 } | |
137 } | 125 } |
138 | 126 |
139 m_audioGenerator->addModel(model); | 127 m_audioGenerator->addModel(model); |
140 | 128 |
141 m_mutex.unlock(); | 129 m_mutex.unlock(); |
146 } | 134 } |
147 | 135 |
148 #ifdef DEBUG_AUDIO_PLAY_SOURCE | 136 #ifdef DEBUG_AUDIO_PLAY_SOURCE |
149 std::cerr << "AudioCallbackPlaySource::addModel: emitting modelReplaced" << std::endl; | 137 std::cerr << "AudioCallbackPlaySource::addModel: emitting modelReplaced" << std::endl; |
150 #endif | 138 #endif |
151 emit modelReplaced(); | 139 |
152 | 140 if (buffersChanged || srChanged) { |
153 if (srChanged && (getSourceSampleRate() != getTargetSampleRate())) { | 141 emit modelReplaced(); |
154 emit sampleRateMismatch(getSourceSampleRate(), getTargetSampleRate()); | |
155 } | 142 } |
156 } | 143 } |
157 | 144 |
158 void | 145 void |
159 AudioCallbackPlaySource::removeModel(Model *model) | 146 AudioCallbackPlaySource::removeModel(Model *model) |
321 | 308 |
322 void | 309 void |
323 AudioCallbackPlaySource::setTargetSampleRate(size_t sr) | 310 AudioCallbackPlaySource::setTargetSampleRate(size_t sr) |
324 { | 311 { |
325 m_targetSampleRate = sr; | 312 m_targetSampleRate = sr; |
313 | |
314 if (getSourceSampleRate() != getTargetSampleRate()) { | |
315 | |
316 int err = 0; | |
317 m_converter = src_new(SRC_SINC_BEST_QUALITY, m_bufferCount, &err); | |
318 if (!m_converter) { | |
319 std::cerr | |
320 << "AudioCallbackPlaySource::setModel: ERROR in creating samplerate converter: " | |
321 << src_strerror(err) << std::endl; | |
322 } | |
323 | |
324 emit sampleRateMismatch(getSourceSampleRate(), getTargetSampleRate()); | |
325 } | |
326 } | 326 } |
327 | 327 |
328 size_t | 328 size_t |
329 AudioCallbackPlaySource::getTargetSampleRate() const | 329 AudioCallbackPlaySource::getTargetSampleRate() const |
330 { | 330 { |
541 #ifdef DEBUG_AUDIO_PLAY_SOURCE | 541 #ifdef DEBUG_AUDIO_PLAY_SOURCE |
542 std::cout << "buffered to " << f << " already" << std::endl; | 542 std::cout << "buffered to " << f << " already" << std::endl; |
543 #endif | 543 #endif |
544 | 544 |
545 bool resample = (getSourceSampleRate() != getTargetSampleRate()); | 545 bool resample = (getSourceSampleRate() != getTargetSampleRate()); |
546 | |
547 #ifdef DEBUG_AUDIO_PLAY_SOURCE | |
548 std::cout << (resample ? "" : "not ") << "resampling (source " << getSourceSampleRate() << ", target " << getTargetSampleRate() << ")" << std::endl; | |
549 #endif | |
550 | |
546 size_t channels = getSourceChannelCount(); | 551 size_t channels = getSourceChannelCount(); |
547 size_t orig = space; | 552 size_t orig = space; |
548 size_t got = 0; | 553 size_t got = 0; |
549 | 554 |
550 static float **bufferPtrs = 0; | 555 static float **bufferPtrs = 0; |
555 bufferPtrs = new float *[channels]; | 560 bufferPtrs = new float *[channels]; |
556 bufferPtrCount = channels; | 561 bufferPtrCount = channels; |
557 } | 562 } |
558 | 563 |
559 size_t generatorBlockSize = m_audioGenerator->getBlockSize(); | 564 size_t generatorBlockSize = m_audioGenerator->getBlockSize(); |
565 | |
566 if (resample && !m_converter) { | |
567 static bool warned = false; | |
568 if (!warned) { | |
569 std::cerr << "WARNING: sample rates differ, but no converter available!" << std::endl; | |
570 warned = true; | |
571 } | |
572 } | |
560 | 573 |
561 if (resample && m_converter) { | 574 if (resample && m_converter) { |
562 | 575 |
563 double ratio = | 576 double ratio = |
564 double(getTargetSampleRate()) / double(getSourceSampleRate()); | 577 double(getTargetSampleRate()) / double(getSourceSampleRate()); |