comparison data/model/WritableWaveFileModel.cpp @ 1126:39019ce29178 tony-2.0-integration

Merge through to branch for Tony 2.0
author Chris Cannam
date Thu, 20 Aug 2015 14:54:21 +0100
parents efea94b04d5a
children e994747fb9dd
comparison
equal deleted inserted replaced
1119:e22bfe8ca248 1126:39019ce29178
13 COPYING included with this distribution for more information. 13 COPYING included with this distribution for more information.
14 */ 14 */
15 15
16 #include "WritableWaveFileModel.h" 16 #include "WritableWaveFileModel.h"
17 17
18 #include "ReadOnlyWaveFileModel.h"
19
18 #include "base/TempDirectory.h" 20 #include "base/TempDirectory.h"
19 #include "base/Exceptions.h" 21 #include "base/Exceptions.h"
20 22
21 #include "fileio/WavFileWriter.h" 23 #include "fileio/WavFileWriter.h"
22 #include "fileio/WavFileReader.h" 24 #include "fileio/WavFileReader.h"
25 #include <QTextStream> 27 #include <QTextStream>
26 28
27 #include <cassert> 29 #include <cassert>
28 #include <iostream> 30 #include <iostream>
29 #include <stdint.h> 31 #include <stdint.h>
32
33 using namespace std;
30 34
31 //#define DEBUG_WRITABLE_WAVE_FILE_MODEL 1 35 //#define DEBUG_WRITABLE_WAVE_FILE_MODEL 1
32 36
33 WritableWaveFileModel::WritableWaveFileModel(sv_samplerate_t sampleRate, 37 WritableWaveFileModel::WritableWaveFileModel(sv_samplerate_t sampleRate,
34 int channels, 38 int channels,
72 delete m_reader; 76 delete m_reader;
73 m_reader = 0; 77 m_reader = 0;
74 return; 78 return;
75 } 79 }
76 80
77 m_model = new WaveFileModel(source, m_reader); 81 m_model = new ReadOnlyWaveFileModel(source, m_reader);
78 if (!m_model->isOK()) { 82 if (!m_model->isOK()) {
79 cerr << "WritableWaveFileModel: Error in creating wave file model" << endl; 83 cerr << "WritableWaveFileModel: Error in creating wave file model" << endl;
80 delete m_model; 84 delete m_model;
81 m_model = 0; 85 m_model = 0;
82 delete m_reader; 86 delete m_reader;
167 { 171 {
168 // SVDEBUG << "WritableWaveFileModel::getFrameCount: count = " << m_frameCount << endl; 172 // SVDEBUG << "WritableWaveFileModel::getFrameCount: count = " << m_frameCount << endl;
169 return m_frameCount; 173 return m_frameCount;
170 } 174 }
171 175
172 sv_frame_t 176 vector<float>
173 WritableWaveFileModel::getData(int channel, sv_frame_t start, sv_frame_t count, 177 WritableWaveFileModel::getData(int channel, sv_frame_t start, sv_frame_t count) const
174 float *buffer) const 178 {
175 { 179 if (!m_model || m_model->getChannelCount() == 0) return {};
176 if (!m_model || m_model->getChannelCount() == 0) return 0; 180 return m_model->getData(channel, start, count);
177 return m_model->getData(channel, start, count, buffer); 181 }
178 } 182
179 183 vector<vector<float>>
180 sv_frame_t 184 WritableWaveFileModel::getMultiChannelData(int fromchannel, int tochannel,
181 WritableWaveFileModel::getData(int channel, sv_frame_t start, sv_frame_t count, 185 sv_frame_t start, sv_frame_t count) const
182 double *buffer) const 186 {
183 { 187 if (!m_model || m_model->getChannelCount() == 0) return {};
184 if (!m_model || m_model->getChannelCount() == 0) return 0; 188 return m_model->getMultiChannelData(fromchannel, tochannel, start, count);
185 return m_model->getData(channel, start, count, buffer);
186 }
187
188 sv_frame_t
189 WritableWaveFileModel::getData(int fromchannel, int tochannel,
190 sv_frame_t start, sv_frame_t count,
191 float **buffers) const
192 {
193 if (!m_model || m_model->getChannelCount() == 0) return 0;
194 return m_model->getData(fromchannel, tochannel, start, count, buffers);
195 } 189 }
196 190
197 int 191 int
198 WritableWaveFileModel::getSummaryBlockSize(int desired) const 192 WritableWaveFileModel::getSummaryBlockSize(int desired) const
199 { 193 {
221 void 215 void
222 WritableWaveFileModel::toXml(QTextStream &out, 216 WritableWaveFileModel::toXml(QTextStream &out,
223 QString indent, 217 QString indent,
224 QString extraAttributes) const 218 QString extraAttributes) const
225 { 219 {
226 // We don't actually write the data to XML. We just write a brief 220 // The assumption here is that the underlying wave file has
227 // description of the model. Any code that uses this class is 221 // already been saved somewhere (its location is available through
228 // going to need to be aware that it will have to make separate 222 // getLocation()) and that the code that uses this class is
229 // arrangements for the audio file itself. 223 // dealing with the problem of making sure it remains available.
224 // We just write this out as if it were a normal wave file.
230 225
231 Model::toXml 226 Model::toXml
232 (out, indent, 227 (out, indent,
233 QString("type=\"writablewavefile\" file=\"%1\" channels=\"%2\" %3") 228 QString("type=\"wavefile\" file=\"%1\" subtype=\"writable\" %2")
234 .arg(encodeEntities(m_writer->getPath())) 229 .arg(encodeEntities(m_writer->getPath()))
235 .arg(m_model->getChannelCount()).arg(extraAttributes)); 230 .arg(extraAttributes));
236 } 231 }
237 232