Mercurial > hg > svcore
comparison data/fileio/WavFileWriter.cpp @ 1450:a12fd0456f0c streaming-csv-writer
Merge from default branch
author | Chris Cannam |
---|---|
date | Tue, 17 Apr 2018 10:35:42 +0100 |
parents | 48e9f538e6e9 |
children | b837ccdd4946 |
comparison
equal
deleted
inserted
replaced
1449:deabf9fd3d28 | 1450:a12fd0456f0c |
---|---|
17 | 17 |
18 #include "model/DenseTimeValueModel.h" | 18 #include "model/DenseTimeValueModel.h" |
19 #include "base/Selection.h" | 19 #include "base/Selection.h" |
20 #include "base/TempWriteFile.h" | 20 #include "base/TempWriteFile.h" |
21 #include "base/Exceptions.h" | 21 #include "base/Exceptions.h" |
22 #include "base/Debug.h" | |
22 | 23 |
23 #include <QFileInfo> | 24 #include <QFileInfo> |
24 | 25 |
25 #include <iostream> | 26 #include <iostream> |
26 #include <cmath> | 27 #include <cmath> |
28 #include <string> | |
27 | 29 |
28 using namespace std; | 30 using namespace std; |
29 | 31 |
30 WavFileWriter::WavFileWriter(QString path, | 32 WavFileWriter::WavFileWriter(QString path, |
31 sv_samplerate_t sampleRate, | 33 sv_samplerate_t sampleRate, |
39 { | 41 { |
40 SF_INFO fileInfo; | 42 SF_INFO fileInfo; |
41 | 43 |
42 int fileRate = int(round(m_sampleRate)); | 44 int fileRate = int(round(m_sampleRate)); |
43 if (m_sampleRate != sv_samplerate_t(fileRate)) { | 45 if (m_sampleRate != sv_samplerate_t(fileRate)) { |
44 cerr << "WavFileWriter: WARNING: Non-integer sample rate " | 46 SVCERR << "WavFileWriter: WARNING: Non-integer sample rate " |
45 << m_sampleRate << " presented, rounding to " << fileRate | 47 << m_sampleRate << " presented, rounding to " << fileRate |
46 << endl; | 48 << endl; |
47 } | 49 } |
48 fileInfo.samplerate = fileRate; | 50 fileInfo.samplerate = fileRate; |
49 fileInfo.channels = m_channels; | 51 fileInfo.channels = m_channels; |
59 m_file = sf_wchar_open((LPCWSTR)writePath.utf16(), SFM_WRITE, &fileInfo); | 61 m_file = sf_wchar_open((LPCWSTR)writePath.utf16(), SFM_WRITE, &fileInfo); |
60 #else | 62 #else |
61 m_file = sf_open(writePath.toLocal8Bit(), SFM_WRITE, &fileInfo); | 63 m_file = sf_open(writePath.toLocal8Bit(), SFM_WRITE, &fileInfo); |
62 #endif | 64 #endif |
63 if (!m_file) { | 65 if (!m_file) { |
64 cerr << "WavFileWriter: Failed to open file (" | 66 SVCERR << "WavFileWriter: Failed to open file (" |
65 << sf_strerror(m_file) << ")" << endl; | 67 << sf_strerror(m_file) << ")" << endl; |
66 m_error = QString("Failed to open audio file '%1' for writing") | 68 m_error = QString("Failed to open audio file '%1' for writing") |
67 .arg(writePath); | 69 .arg(writePath); |
68 } | 70 } |
69 } catch (FileOperationFailed &f) { | 71 } catch (FileOperationFailed &f) { |
130 sv_frame_t bs = 2048; | 132 sv_frame_t bs = 2048; |
131 | 133 |
132 for (MultiSelection::SelectionList::iterator i = | 134 for (MultiSelection::SelectionList::iterator i = |
133 selection->getSelections().begin(); | 135 selection->getSelections().begin(); |
134 i != selection->getSelections().end(); ++i) { | 136 i != selection->getSelections().end(); ++i) { |
135 | 137 |
136 sv_frame_t f0(i->getStartFrame()), f1(i->getEndFrame()); | 138 sv_frame_t f0(i->getStartFrame()), f1(i->getEndFrame()); |
137 | 139 |
138 for (sv_frame_t f = f0; f < f1; f += bs) { | 140 for (sv_frame_t f = f0; f < f1; f += bs) { |
139 | 141 |
140 sv_frame_t n = min(bs, f1 - f); | 142 sv_frame_t n = min(bs, f1 - f); |
141 floatvec_t interleaved(n * m_channels, 0.f); | 143 floatvec_t interleaved(n * m_channels, 0.f); |
142 | 144 |
143 for (int c = 0; c < int(m_channels); ++c) { | 145 for (int c = 0; c < int(m_channels); ++c) { |
144 auto chanbuf = source->getData(c, f, n); | 146 auto chanbuf = source->getData(c, f, n); |
159 | 161 |
160 if (ownSelection) delete selection; | 162 if (ownSelection) delete selection; |
161 | 163 |
162 return isOK(); | 164 return isOK(); |
163 } | 165 } |
164 | 166 |
165 bool | 167 bool |
166 WavFileWriter::writeSamples(const float *const *samples, sv_frame_t count) | 168 WavFileWriter::writeSamples(const float *const *samples, sv_frame_t count) |
167 { | 169 { |
168 if (!m_file) { | 170 if (!m_file) { |
169 m_error = QString("Failed to write model to audio file '%1': File not open") | 171 m_error = QString("Failed to write model to audio file '%1': File not open") |