comparison 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
comparison
equal deleted inserted replaced
1039:b14064bd1f97 1040:a1cd5abcb38b
23 #include <QFileInfo> 23 #include <QFileInfo>
24 24
25 #include <iostream> 25 #include <iostream>
26 26
27 WavFileWriter::WavFileWriter(QString path, 27 WavFileWriter::WavFileWriter(QString path,
28 int sampleRate, 28 sv_samplerate_t sampleRate,
29 int channels, 29 int channels,
30 FileWriteMode mode) : 30 FileWriteMode mode) :
31 m_path(path), 31 m_path(path),
32 m_sampleRate(sampleRate), 32 m_sampleRate(sampleRate),
33 m_channels(channels), 33 m_channels(channels),
34 m_temp(0), 34 m_temp(0),
35 m_file(0) 35 m_file(0)
36 { 36 {
37 SF_INFO fileInfo; 37 SF_INFO fileInfo;
38 fileInfo.samplerate = m_sampleRate; 38
39 int fileRate = int(round(m_sampleRate));
40 if (m_sampleRate != sv_samplerate_t(fileRate)) {
41 cerr << "WavFileWriter: WARNING: Non-integer sample rate "
42 << m_sampleRate << " presented, rounding to " << fileRate
43 << endl;
44 }
45 fileInfo.samplerate = fileRate;
39 fileInfo.channels = m_channels; 46 fileInfo.channels = m_channels;
40 fileInfo.format = SF_FORMAT_WAV | SF_FORMAT_FLOAT; 47 fileInfo.format = SF_FORMAT_WAV | SF_FORMAT_FLOAT;
41 48
42 try { 49 try {
43 if (mode == WriteToTemporary) { 50 if (mode == WriteToTemporary) {