changeset 349:8d7f39df44ed tony_integration

Quieter clip playback for note layers
author Chris Cannam
date Thu, 08 May 2014 15:04:42 +0100
parents f8e1ca25dd80
children aebee52e86b3 8b631ce73b1c
files audioio/AudioGenerator.cpp audioio/AudioGenerator.h audioio/ClipMixer.cpp audioio/ClipMixer.h
diffstat 4 files changed, 22 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/audioio/AudioGenerator.cpp	Wed May 07 16:51:04 2014 +0100
+++ b/audioio/AudioGenerator.cpp	Thu May 08 15:04:42 2014 +0100
@@ -173,6 +173,18 @@
 }
 
 bool
+AudioGenerator::wantsQuieterClips(const Model *model)
+{
+    // basically, anything that usually has sustain (like notes) or
+    // often has multiple sounds at once (like notes) wants to use a
+    // quieter level than simple click tracks
+    bool does = 
+        (qobject_cast<const NoteModel *>(model) ||
+         qobject_cast<const FlexiNoteModel *>(model));
+    return does;
+}
+
+bool
 AudioGenerator::usesContinuousSynth(const Model *model)
 {
     bool cont = 
@@ -209,7 +221,8 @@
 
     QString clipPath = QString("%1/%2.wav").arg(m_sampleDir).arg(clipId);
 
-    if (!mixer->loadClipData(clipPath, clipF0)) {
+    float level = wantsQuieterClips(model) ? 0.5 : 1.0;
+    if (!mixer->loadClipData(clipPath, clipF0, level)) {
         delete mixer;
         return 0;
     }
--- a/audioio/AudioGenerator.h	Wed May 07 16:51:04 2014 +0100
+++ b/audioio/AudioGenerator.h	Thu May 08 15:04:42 2014 +0100
@@ -135,6 +135,7 @@
     ContinuousSynthMap m_continuousSynthMap;
 
     bool usesClipMixer(const Model *);
+    bool wantsQuieterClips(const Model *);
     bool usesContinuousSynth(const Model *);
 
     ClipMixer *makeClipMixerFor(const Model *model);
--- a/audioio/ClipMixer.cpp	Wed May 07 16:51:04 2014 +0100
+++ b/audioio/ClipMixer.cpp	Thu May 08 15:04:42 2014 +0100
@@ -40,7 +40,7 @@
 }
 
 bool
-ClipMixer::loadClipData(QString path, float f0)
+ClipMixer::loadClipData(QString path, float f0, float level)
 {
     if (m_clipData) {
         cerr << "ClipMixer::loadClipData: Already have clip loaded" << endl;
@@ -81,7 +81,7 @@
 	int j;
 	m_clipData[i] = 0.0f;
 	for (j = 0; j < info.channels; ++j) {
-	    m_clipData[i] += tmpFrames[i * info.channels + j];
+	    m_clipData[i] += tmpFrames[i * info.channels + j] * level;
 	}
     }
 
--- a/audioio/ClipMixer.h	Wed May 07 16:51:04 2014 +0100
+++ b/audioio/ClipMixer.h	Thu May 08 15:04:42 2014 +0100
@@ -36,9 +36,12 @@
 
     /**
      * Load a sample clip from a wav file. This can only happen once:
-     * construct a new ClipMixer if you want a different clip.
+     * construct a new ClipMixer if you want a different clip. The
+     * clip was recorded at a pitch with fundamental frequency clipF0,
+     * and should be scaled by level (in the range 0-1) when playing
+     * back.
      */
-    bool loadClipData(QString clipFilePath, float clipF0);
+    bool loadClipData(QString clipFilePath, float clipF0, float level);
 
     void reset(); // discarding any playing notes