diff data/fileio/WavFileWriter.cpp @ 1040:a1cd5abcb38b cxx11

Introduce and use a samplerate type
author Chris Cannam
date Wed, 04 Mar 2015 12:01:04 +0000
parents cc27f35aa75c
children 0559f25b99f2
line wrap: on
line diff
--- a/data/fileio/WavFileWriter.cpp	Tue Mar 03 17:09:19 2015 +0000
+++ b/data/fileio/WavFileWriter.cpp	Wed Mar 04 12:01:04 2015 +0000
@@ -25,7 +25,7 @@
 #include <iostream>
 
 WavFileWriter::WavFileWriter(QString path,
-			     int sampleRate,
+			     sv_samplerate_t sampleRate,
                              int channels,
                              FileWriteMode mode) :
     m_path(path),
@@ -35,7 +35,14 @@
     m_file(0)
 {
     SF_INFO fileInfo;
-    fileInfo.samplerate = m_sampleRate;
+
+    int fileRate = int(round(m_sampleRate));
+    if (m_sampleRate != sv_samplerate_t(fileRate)) {
+        cerr << "WavFileWriter: WARNING: Non-integer sample rate "
+             << m_sampleRate << " presented, rounding to " << fileRate
+             << endl;
+    }
+    fileInfo.samplerate = fileRate;
     fileInfo.channels = m_channels;
     fileInfo.format = SF_FORMAT_WAV | SF_FORMAT_FLOAT;