changeset 921:2896b8872834 tonioni

Add normalise preference and take it into account in WaveFileModel
author Chris Cannam
date Fri, 13 Jun 2014 16:12:00 +0100
parents f3cda3280398
children 9911b8cb53bc
files base/Preferences.cpp base/Preferences.h data/fileio/CodedAudioFileReader.cpp data/model/WaveFileModel.cpp
diffstat 4 files changed, 33 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/base/Preferences.cpp	Fri Jun 13 16:03:48 2014 +0100
+++ b/base/Preferences.cpp	Fri Jun 13 16:12:00 2014 +0100
@@ -45,6 +45,7 @@
     m_tempDirRoot(""),
     m_fixedSampleRate(0),
     m_resampleOnLoad(false),
+    m_normaliseAudio(false),
     m_viewFontSize(10),
     m_backgroundMode(BackgroundFromTheme),
     m_timeToTextMode(TimeToTextMs),
@@ -65,6 +66,7 @@
     m_resampleQuality = settings.value("resample-quality", 1).toInt();
     m_fixedSampleRate = settings.value("fixed-sample-rate", 0).toInt();
     m_resampleOnLoad = settings.value("resample-on-load", false).toBool();
+    m_normaliseAudio = settings.value("normalise-audio", false).toBool();
     m_backgroundMode = BackgroundMode
         (settings.value("background-mode", int(BackgroundFromTheme)).toInt());
     m_timeToTextMode = TimeToTextMode
@@ -95,6 +97,7 @@
     props.push_back("Resample Quality");
     props.push_back("Omit Temporaries from Recent Files");
     props.push_back("Resample On Load");
+    props.push_back("Normalise Audio");
     props.push_back("Fixed Sample Rate");
     props.push_back("Temporary Directory Root");
     props.push_back("Background Mode");
@@ -126,6 +129,9 @@
     if (name == "Resample Quality") {
         return tr("Playback resampler type");
     }
+    if (name == "Normalise Audio") {
+        return tr("Normalise audio signal when reading from audio file");
+    }
     if (name == "Omit Temporaries from Recent Files") {
         return tr("Omit temporaries from Recent Files menu");
     }
@@ -177,6 +183,9 @@
     if (name == "Resample Quality") {
         return ValueProperty;
     }
+    if (name == "Normalise Audio") {
+        return ToggleProperty;
+    }
     if (name == "Omit Temporaries from Recent Files") {
         return ToggleProperty;
     }
@@ -547,6 +556,19 @@
 }
 
 void
+Preferences::setNormaliseAudio(bool norm)
+{
+    if (m_normaliseAudio != norm) {
+        m_normaliseAudio = norm;
+        QSettings settings;
+        settings.beginGroup("Preferences");
+        settings.setValue("normalise-audio", norm);
+        settings.endGroup();
+        emit propertyChanged("Normalise Audio");
+    }
+}
+
+void
 Preferences::setBackgroundMode(BackgroundMode mode)
 {
     if (m_backgroundMode != mode) {
--- a/base/Preferences.h	Fri Jun 13 16:03:48 2014 +0100
+++ b/base/Preferences.h	Fri Jun 13 16:12:00 2014 +0100
@@ -72,6 +72,9 @@
     /// True if we should resample second or subsequent audio file to match first audio file's rate
     bool getResampleOnLoad() const { return m_resampleOnLoad; }    
     
+    /// True if audio files should be loaded with normalisation (max == 1)
+    bool getNormaliseAudio() const { return m_normaliseAudio; }
+
     enum BackgroundMode {
         BackgroundFromTheme,
         DarkBackground,
@@ -113,6 +116,7 @@
     void setTemporaryDirectoryRoot(QString tempDirRoot);
     void setFixedSampleRate(int);
     void setResampleOnLoad(bool);
+    void setNormaliseAudio(bool);
     void setBackgroundMode(BackgroundMode mode);
     void setTimeToTextMode(TimeToTextMode mode);
     void setOctaveOfMiddleC(int oct);
@@ -148,6 +152,7 @@
     QString m_tempDirRoot;
     int m_fixedSampleRate;
     bool m_resampleOnLoad;
+    bool m_normaliseAudio;
     int m_viewFontSize;
     BackgroundMode m_backgroundMode;
     TimeToTextMode m_timeToTextMode;
--- a/data/fileio/CodedAudioFileReader.cpp	Fri Jun 13 16:03:48 2014 +0100
+++ b/data/fileio/CodedAudioFileReader.cpp	Fri Jun 13 16:12:00 2014 +0100
@@ -46,7 +46,7 @@
     m_max(0.f),
     m_gain(1.f)
 {
-    SVDEBUG << "CodedAudioFileReader::CodedAudioFileReader: rate " << targetRate << ", normalised = " << normalised << endl;
+    cerr << "CodedAudioFileReader::CodedAudioFileReader: rate " << targetRate << ", normalised = " << normalised << endl;
 
     m_frameCount = 0;
     m_sampleRate = targetRate;
@@ -446,6 +446,7 @@
     }
 
     if (m_normalised) {
+        cerr << "CodedAudioFileReader::getInterleavedFrames: normalised, gain = " << m_gain << endl;
         for (int i = 0; i < (int)(count * m_channelCount); ++i) {
             frames[i] *= m_gain;
         }
--- a/data/model/WaveFileModel.cpp	Fri Jun 13 16:03:48 2014 +0100
+++ b/data/model/WaveFileModel.cpp	Fri Jun 13 16:12:00 2014 +0100
@@ -20,6 +20,8 @@
 
 #include "system/System.h"
 
+#include "base/Preferences.h"
+
 #include <QFileInfo>
 #include <QTextStream>
 
@@ -49,8 +51,9 @@
 {
     m_source.waitForData();
     if (m_source.isOK()) {
+        bool normalise = Preferences::getInstance()->getNormaliseAudio();
         m_reader = AudioFileReaderFactory::createThreadingReader
-            (m_source, targetRate);
+            (m_source, targetRate, normalise);
         if (m_reader) {
             SVDEBUG << "WaveFileModel::WaveFileModel: reader rate: "
                       << m_reader->getSampleRate() << endl;