# HG changeset patch # User Chris Cannam # Date 1399557882 -3600 # Node ID 8d7f39df44edefb923903325ea0e813004953d86 # Parent f8e1ca25dd80a8f534c518c1bd81aed4b8c228c7 Quieter clip playback for note layers diff -r f8e1ca25dd80 -r 8d7f39df44ed audioio/AudioGenerator.cpp --- 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(model) || + qobject_cast(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; } diff -r f8e1ca25dd80 -r 8d7f39df44ed audioio/AudioGenerator.h --- 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); diff -r f8e1ca25dd80 -r 8d7f39df44ed audioio/ClipMixer.cpp --- 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; } } diff -r f8e1ca25dd80 -r 8d7f39df44ed audioio/ClipMixer.h --- 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