Mercurial > hg > svcore
comparison data/model/WritableWaveFileModel.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 | cee1be4fb8c1 |
comparison
equal
deleted
inserted
replaced
1449:deabf9fd3d28 | 1450:a12fd0456f0c |
---|---|
35 const int WritableWaveFileModel::PROPORTION_UNKNOWN = -1; | 35 const int WritableWaveFileModel::PROPORTION_UNKNOWN = -1; |
36 | 36 |
37 //#define DEBUG_WRITABLE_WAVE_FILE_MODEL 1 | 37 //#define DEBUG_WRITABLE_WAVE_FILE_MODEL 1 |
38 | 38 |
39 WritableWaveFileModel::WritableWaveFileModel(sv_samplerate_t sampleRate, | 39 WritableWaveFileModel::WritableWaveFileModel(sv_samplerate_t sampleRate, |
40 int channels, | 40 int channels, |
41 QString path) : | 41 QString path) : |
42 m_model(0), | 42 m_model(0), |
43 m_writer(0), | 43 m_writer(0), |
44 m_reader(0), | 44 m_reader(0), |
45 m_sampleRate(sampleRate), | 45 m_sampleRate(sampleRate), |
46 m_channels(channels), | 46 m_channels(channels), |
52 try { | 52 try { |
53 QDir dir(TempDirectory::getInstance()->getPath()); | 53 QDir dir(TempDirectory::getInstance()->getPath()); |
54 path = dir.filePath(QString("written_%1.wav") | 54 path = dir.filePath(QString("written_%1.wav") |
55 .arg((intptr_t)this)); | 55 .arg((intptr_t)this)); |
56 } catch (DirectoryCreationFailed f) { | 56 } catch (DirectoryCreationFailed f) { |
57 cerr << "WritableWaveFileModel: Failed to create temporary directory" << endl; | 57 SVCERR << "WritableWaveFileModel: Failed to create temporary directory" << endl; |
58 return; | 58 return; |
59 } | 59 } |
60 } | 60 } |
61 | 61 |
62 // Write directly to the target file, so that we can do | 62 // Write directly to the target file, so that we can do |
63 // incremental writes and concurrent reads | 63 // incremental writes and concurrent reads |
64 m_writer = new WavFileWriter(path, sampleRate, channels, | 64 m_writer = new WavFileWriter(path, sampleRate, channels, |
65 WavFileWriter::WriteToTarget); | 65 WavFileWriter::WriteToTarget); |
66 if (!m_writer->isOK()) { | 66 if (!m_writer->isOK()) { |
67 cerr << "WritableWaveFileModel: Error in creating WAV file writer: " << m_writer->getError() << endl; | 67 SVCERR << "WritableWaveFileModel: Error in creating WAV file writer: " << m_writer->getError() << endl; |
68 delete m_writer; | 68 delete m_writer; |
69 m_writer = 0; | 69 m_writer = 0; |
70 return; | 70 return; |
71 } | 71 } |
72 | 72 |
73 FileSource source(m_writer->getPath()); | 73 FileSource source(m_writer->getPath()); |
74 | 74 |
75 m_reader = new WavFileReader(source, true); | 75 m_reader = new WavFileReader(source, true); |
76 if (!m_reader->getError().isEmpty()) { | 76 if (!m_reader->getError().isEmpty()) { |
77 cerr << "WritableWaveFileModel: Error in creating wave file reader" << endl; | 77 SVCERR << "WritableWaveFileModel: Error in creating wave file reader" << endl; |
78 delete m_reader; | 78 delete m_reader; |
79 m_reader = 0; | 79 m_reader = 0; |
80 return; | 80 return; |
81 } | 81 } |
82 | 82 |
83 m_model = new ReadOnlyWaveFileModel(source, m_reader); | 83 m_model = new ReadOnlyWaveFileModel(source, m_reader); |
84 if (!m_model->isOK()) { | 84 if (!m_model->isOK()) { |
85 cerr << "WritableWaveFileModel: Error in creating wave file model" << endl; | 85 SVCERR << "WritableWaveFileModel: Error in creating wave file model" << endl; |
86 delete m_model; | 86 delete m_model; |
87 m_model = 0; | 87 m_model = 0; |
88 delete m_reader; | 88 delete m_reader; |
89 m_reader = 0; | 89 m_reader = 0; |
90 return; | 90 return; |