changeset 544:c4391f6c7484 bqresample

Start pruning other resampler logic than bqresample
author Chris Cannam
date Mon, 05 Dec 2016 16:56:36 +0000
parents 167d37937436
children baa11365ebdd ec189ad4d38f
files audio/AudioCallbackPlaySource.cpp audio/AudioCallbackPlaySource.h
diffstat 2 files changed, 46 insertions(+), 53 deletions(-) [+]
line wrap: on
line diff
--- a/audio/AudioCallbackPlaySource.cpp	Mon Dec 05 16:39:03 2016 +0000
+++ b/audio/AudioCallbackPlaySource.cpp	Mon Dec 05 16:56:36 2016 +0000
@@ -78,7 +78,7 @@
     m_stretcherInputs(0),
     m_stretcherInputSizes(0),
     m_fillThread(0),
-    m_converter(0)
+    m_resampler(0)
 {
     m_viewManager->setAudioPlaySource(this);
 
@@ -230,12 +230,12 @@
     }
 
     if (buffersChanged || srChanged) {
-	if (m_converter) {
+	if (m_resampler) {
 #ifdef DEBUG_AUDIO_PLAY_SOURCE
-            cerr << "AudioCallbackPlaySource::addModel: Buffers or sample rate changed, deleting existing SR converter" << endl;
+            cerr << "AudioCallbackPlaySource::addModel: Buffers or sample rate changed, deleting existing resampler" << endl;
 #endif
-	    src_delete(m_converter);
-	    m_converter = 0;
+            delete m_resampler;
+	    m_resampler = 0;
 	}
     }
 
@@ -243,7 +243,7 @@
 
     m_mutex.unlock();
 
-    initialiseConverter();
+    initialiseResampler();
     
     m_audioGenerator->setTargetChannelCount(getTargetChannelCount());
 
@@ -301,12 +301,12 @@
     m_models.erase(model);
 
     if (m_models.empty()) {
-	if (m_converter) {
+	if (m_resampler) {
 #ifdef DEBUG_AUDIO_PLAY_SOURCE
-            cerr << "AudioCallbackPlaySource::removeModel: No models left, deleting SR converter" << endl;
+            cerr << "AudioCallbackPlaySource::removeModel: No models left, deleting resampler" << endl;
 #endif
-	    src_delete(m_converter);
-	    m_converter = 0;
+	    delete m_resampler;
+	    m_resampler = 0;
 	}
 	m_sourceSampleRate = 0;
     }
@@ -344,12 +344,12 @@
 
     m_models.clear();
 
-    if (m_converter) {
+    if (m_resampler) {
 #ifdef DEBUG_AUDIO_PLAY_SOURCE
-        cerr << "AudioCallbackPlaySource::clearModels: Deleting SR converter" << endl;
+        cerr << "AudioCallbackPlaySource::clearModels: Deleting resampler" << endl;
 #endif
-	src_delete(m_converter);
-	m_converter = 0;
+	delete m_resampler;
+	m_resampler = 0;
     }
 
     m_lastModelEndFrame = 0;
@@ -472,7 +472,9 @@
             if (rb) rb->reset();
         }
     }
-    if (m_converter) src_reset(m_converter);
+    if (m_resampler) {
+        m_resampler->reset();
+    }
 
     m_mutex.unlock();
 
@@ -945,7 +947,7 @@
     bool first = (m_targetSampleRate == 0);
 
     m_targetSampleRate = sr;
-    initialiseConverter();
+    initialiseResampler();
 
     if (first && (m_stretchRatio != 1.f)) {
         // couldn't create a stretcher before because we had no sample
@@ -955,43 +957,31 @@
 }
 
 void
-AudioCallbackPlaySource::initialiseConverter()
+AudioCallbackPlaySource::initialiseResampler()
 {
     m_mutex.lock();
 
 #ifdef DEBUG_AUDIO_PLAY_SOURCE
-    cerr << "AudioCallbackPlaySource::initialiseConverter(): from "
+    cerr << "AudioCallbackPlaySource::initialiseResampler(): from "
          << getSourceSampleRate() << " to " << getTargetSampleRate() << endl;
 #endif
     
-    if (m_converter) {
-        src_delete(m_converter);
-        m_converter = 0;
+    if (m_resampler) {
+        delete m_resampler;
+        m_resampler = 0;
     }
 
     if (getSourceSampleRate() != getTargetSampleRate()) {
 
-	int err = 0;
+        m_resampler = new breakfastquay::Resampler
+            (breakfastquay::Resampler::FastestTolerable,
+             getTargetChannelCount());
 
-	m_converter = src_new(SRC_SINC_FASTEST, getTargetChannelCount(), &err);
+        m_mutex.unlock();
 
-	if (!m_converter) {
-	    cerr << "AudioCallbackPlaySource::setModel: ERROR in creating samplerate converter: "
-                 << src_strerror(err) << endl;
-
-            m_mutex.unlock();
-
-            emit sampleRateMismatch(getSourceSampleRate(),
-                                    getTargetSampleRate(),
-                                    false);
-	} else {
-
-            m_mutex.unlock();
-
-            emit sampleRateMismatch(getSourceSampleRate(),
-                                    getTargetSampleRate(),
-                                    true);
-        }
+        emit sampleRateMismatch(getSourceSampleRate(),
+                                getTargetSampleRate(),
+                                true);
     } else {
         m_mutex.unlock();
     }
@@ -1365,6 +1355,9 @@
         return false;
     }
 
+    // space is now the number of samples that can be written on each
+    // channel's write ringbuffer
+    
     sv_frame_t f = m_writeBufferFill;
 	
     bool readWriteEqual = (m_readBuffers == m_writeBuffers);
@@ -1402,11 +1395,11 @@
 
     sv_frame_t generatorBlockSize = m_audioGenerator->getBlockSize();
 
-    if (resample && !m_converter) {
-        throw std::logic_error("Sample rates differ, but no converter available!");
+    if (resample && !m_resampler) {
+        throw std::logic_error("Sample rates differ, but no resampler available!");
     }
 
-    if (resample && m_converter) {
+    if (resample && m_resampler) {
 
 	double ratio =
 	    double(getTargetSampleRate()) / double(getSourceSampleRate());
@@ -1458,7 +1451,10 @@
 		intlv[channels * i + c] = sample;
 	    }
 	}
-		
+
+        sv_frame_t toCopy = m_resampler->resampleInterleaved
+            (intlv, srcout, got, ratio, false);
+        
 	SRC_DATA data;
 	data.data_in = intlv;
 	data.data_out = srcout;
--- a/audio/AudioCallbackPlaySource.h	Mon Dec 05 16:39:03 2016 +0000
+++ b/audio/AudioCallbackPlaySource.h	Mon Dec 05 16:56:36 2016 +0000
@@ -39,6 +39,10 @@
     class RubberBandStretcher;
 }
 
+namespace breakfastquay {
+    class Resampler;
+}
+
 class Model;
 class ViewManagerBase;
 class AudioGenerator;
@@ -226,12 +230,6 @@
     void setTimeStretch(double factor);
 
     /**
-     * Set the resampler quality, 0 - 2 where 0 is fastest and 2 is
-     * highest quality.
-     */
-    void setResampleQuality(int q);
-
-    /**
      * Set a single real-time plugin as a processing effect for
      * auditioning during playback.
      *
@@ -395,9 +393,8 @@
     QMutex m_mutex;
     QWaitCondition m_condition;
     FillThread *m_fillThread;
-    SRC_STATE *m_converter;
-    int m_resampleQuality;
-    void initialiseConverter();
+    breakfastquay::Resampler *m_resampler;
+    void initialiseResampler();
 };
 
 #endif