changeset 1515:ffec849858a7 import-audio-data

Add sample-range support to CSVFormat
author Chris Cannam
date Fri, 07 Sep 2018 16:55:29 +0100
parents b7042aaecebe
children ad46f6e80369
files data/fileio/CSVFormat.cpp data/fileio/CSVFormat.h
diffstat 2 files changed, 60 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/data/fileio/CSVFormat.cpp	Fri Sep 07 16:13:48 2018 +0100
+++ b/data/fileio/CSVFormat.cpp	Fri Sep 07 16:55:29 2018 +0100
@@ -84,6 +84,7 @@
     }
 
     guessPurposes();
+    guessAudioSampleRange();
 }
 
 void
@@ -351,6 +352,55 @@
     SVDEBUG << "Estimated units: " << m_timeUnits << endl;
 }
 
+void
+CSVFormat::guessAudioSampleRange()
+{
+    AudioSampleRange range = SampleRangeSigned1;
+    
+    range = SampleRangeSigned1;
+    bool knownSigned = false;
+    bool knownNonIntegral = false;
+    
+    for (int i = 0; i < m_columnCount; ++i) {
+        if (!(m_columnQualities[i] & ColumnIntegral)) {
+            knownNonIntegral = true;
+            if (range == SampleRangeUnsigned255 ||
+                range == SampleRangeSigned32767) {
+                range = SampleRangeOther;
+            }
+        }
+        if (m_columnQualities[i] & ColumnLarge) {
+            if (range == SampleRangeSigned1 ||
+                range == SampleRangeUnsigned255) {
+                if (knownNonIntegral) {
+                    range = SampleRangeOther;
+                } else {
+                    range = SampleRangeSigned32767;
+                }
+            }
+        }
+        if (m_columnQualities[i] & ColumnSigned) {
+            knownSigned = true;
+            if (range == SampleRangeUnsigned255) {
+                range = SampleRangeSigned32767;
+            }
+        }
+        if (!(m_columnQualities[i] & ColumnSmall)) {
+            if (range == SampleRangeSigned1) {
+                if (knownNonIntegral) {
+                    range = SampleRangeOther;
+                } else if (knownSigned) {
+                    range = SampleRangeSigned32767;
+                } else {
+                    range = SampleRangeUnsigned255;
+                }
+            }
+        }
+    }
+
+    m_audioSampleRange = range;
+}
+
 CSVFormat::ColumnPurpose
 CSVFormat::getColumnPurpose(int i)
 {
--- a/data/fileio/CSVFormat.h	Fri Sep 07 16:13:48 2018 +0100
+++ b/data/fileio/CSVFormat.h	Fri Sep 07 16:55:29 2018 +0100
@@ -66,6 +66,13 @@
     };
     typedef unsigned int ColumnQualities;
 
+    enum AudioSampleRange {
+        SampleRangeSigned1 = 0, //     -1 .. 1
+        SampleRangeUnsigned255, //      0 .. 255
+        SampleRangeSigned32767, // -32768 .. 32767
+        SampleRangeOther        // Other/unknown: Normalise on load
+    };
+
     CSVFormat() : // arbitrary defaults
         m_modelType(TwoDimensionalModel),
         m_timingType(ExplicitTiming),
@@ -149,6 +156,8 @@
     QList<ColumnQualities> m_columnQualities;
     QList<ColumnPurpose> m_columnPurposes;
 
+    AudioSampleRange m_audioSampleRange;
+
     QList<float> m_prevValues;
 
     bool m_allowQuoting;
@@ -159,9 +168,7 @@
     void guessSeparator(QString line);
     void guessQualities(QString line, int lineno);
     void guessPurposes();
-
-    void guessFormatFor_Old(QString path);
- 
+    void guessAudioSampleRange();
 };
 
 #endif