diff data/fileio/CodedAudioFileReader.cpp @ 318:7a4bd2c8585c

* Some export fixes, and avoid clipping on resampling on import
author Chris Cannam
date Mon, 22 Oct 2007 09:45:35 +0000
parents 4fc6f49436b3
children 7623ecfd5891
line wrap: on
line diff
--- a/data/fileio/CodedAudioFileReader.cpp	Thu Oct 18 16:20:26 2007 +0000
+++ b/data/fileio/CodedAudioFileReader.cpp	Mon Oct 22 09:45:35 2007 +0000
@@ -291,6 +291,13 @@
 void
 CodedAudioFileReader::pushBuffer(float *buffer, size_t sz, bool final)
 {
+    for (size_t i = 0; i < sz; ++i) {
+        if (buffer[i] >  1.f) buffer[i] =  1.f;
+    }
+    for (size_t i = 0; i < sz; ++i) {
+        if (buffer[i] < -1.f) buffer[i] = -1.f;
+    }
+
     if (m_resampler) {
         
         float ratio = float(m_sampleRate) / float(m_fileRate);
@@ -303,14 +310,16 @@
                  ratio,
                  final);
 
-            for (size_t i = 0; i < out; ++i) {
-                if (m_resampleBuffer[i] >  1.f) m_resampleBuffer[i] =  1.f;
-                if (m_resampleBuffer[i] < -1.f) m_resampleBuffer[i] = -1.f;
-            }
-
             buffer = m_resampleBuffer;
             sz = out;
         }
+
+        for (size_t i = 0; i < sz; ++i) {
+            if (buffer[i] >  1.f) buffer[i] =  1.f;
+        }
+        for (size_t i = 0; i < sz; ++i) {
+            if (buffer[i] < -1.f) buffer[i] = -1.f;
+        }
     }
 
     m_frameCount += sz;