changeset 418:8d2112977aa0 tonioni

Don't clear ring buffers & regenerate when adding a model that is muted anyway
author Chris Cannam
date Tue, 11 Nov 2014 16:34:22 +0000
parents d62a622a0e40
children 2185d52b4758
files audioio/AudioCallbackPlaySource.cpp audioio/AudioGenerator.cpp audioio/ContinuousSynth.cpp
diffstat 3 files changed, 17 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/audioio/AudioCallbackPlaySource.cpp	Mon Nov 10 09:20:33 2014 +0000
+++ b/audioio/AudioCallbackPlaySource.cpp	Tue Nov 11 16:34:22 2014 +0000
@@ -149,7 +149,7 @@
 {
     if (m_models.find(model) != m_models.end()) return;
 
-    bool canPlay = m_audioGenerator->addModel(model);
+    bool willPlay = m_audioGenerator->addModel(model);
 
     m_mutex.lock();
 
@@ -225,7 +225,7 @@
 	clearRingBuffers(true, getTargetChannelCount());
 	buffersChanged = true;
     } else {
-	if (canPlay) clearRingBuffers(true);
+	if (willPlay) clearRingBuffers(true);
     }
 
     if (buffersChanged || srChanged) {
--- a/audioio/AudioGenerator.cpp	Mon Nov 10 09:20:33 2014 +0000
+++ b/audioio/AudioGenerator.cpp	Tue Nov 11 16:34:22 2014 +0000
@@ -124,12 +124,20 @@
 	}
     }
 
+    const Playable *playable = model;
+    if (!playable || !playable->canPlay()) return 0;
+
+    PlayParameters *parameters =
+	PlayParameterRepository::getInstance()->getPlayParameters(playable);
+
+    bool willPlay = !parameters->isPlayMuted();
+    
     if (usesClipMixer(model)) {
         ClipMixer *mixer = makeClipMixerFor(model);
         if (mixer) {
             QMutexLocker locker(&m_mutex);
             m_clipMixerMap[model] = mixer;
-            return true;
+            return willPlay;
         }
     }
 
@@ -138,7 +146,7 @@
         if (synth) {
             QMutexLocker locker(&m_mutex);
             m_continuousSynthMap[model] = synth;
-            return true;
+            return willPlay;
         }
     }
 
--- a/audioio/ContinuousSynth.cpp	Mon Nov 10 09:20:33 2014 +0000
+++ b/audioio/ContinuousSynth.cpp	Tue Nov 11 16:34:22 2014 +0000
@@ -48,8 +48,8 @@
     bool nowOn = (f0 > 0.f);
 
     if (!nowOn && !wasOn) {
-    m_phase = 0;
-    return;
+        m_phase = 0;
+        return;
     }
 
     int fadeLength = 100; // samples
@@ -57,11 +57,11 @@
     float *levels = new float[m_channels];
     
     for (int c = 0; c < m_channels; ++c) {
-    levels[c] = gain * 0.5; // scale gain otherwise too loud compared to source
+        levels[c] = gain * 0.5; // scale gain otherwise too loud compared to source
     }
     if (pan != 0.0 && m_channels == 2) {
-    levels[0] *= 1.0 - pan;
-    levels[1] *= pan + 1.0;
+        levels[0] *= 1.0 - pan;
+        levels[1] *= pan + 1.0;
     }
 
 //    cerr << "ContinuousSynth::mix: f0 = " << f0 << " (from " << m_prevF0 << "), phase = " << m_phase << endl;