Mercurial > hg > svcore
comparison data/model/WritableWaveFileModel.h @ 1522:b7cb203ee344
Merge from branch import-audio-data
author | Chris Cannam |
---|---|
date | Wed, 12 Sep 2018 15:57:49 +0100 |
parents | 954d0cf29ca7 |
children | c01cbe41aeb5 |
comparison
equal
deleted
inserted
replaced
1506:a250a54c11cc | 1522:b7cb203ee344 |
---|---|
26 class WritableWaveFileModel : public WaveFileModel | 26 class WritableWaveFileModel : public WaveFileModel |
27 { | 27 { |
28 Q_OBJECT | 28 Q_OBJECT |
29 | 29 |
30 public: | 30 public: |
31 WritableWaveFileModel(sv_samplerate_t sampleRate, int channels, QString path = ""); | 31 enum class Normalisation { None, Peak }; |
32 | |
33 /** | |
34 * Create a WritableWaveFileModel of the given sample rate and | |
35 * channel count, storing data in a new float-type extended WAV | |
36 * file with the given path. If path is the empty string, the data | |
37 * will be stored in a newly-created temporary file. | |
38 * | |
39 * If normalisation == None, sample values will be written | |
40 * verbatim, and will be ready to read as soon as they have been | |
41 * written. Otherwise samples will be normalised on writing; this | |
42 * will require an additional pass and temporary file, and no | |
43 * samples will be available to read until after writeComplete() | |
44 * has returned. | |
45 */ | |
46 WritableWaveFileModel(QString path, | |
47 sv_samplerate_t sampleRate, | |
48 int channels, | |
49 Normalisation normalisation); | |
50 | |
51 /** | |
52 * Create a WritableWaveFileModel of the given sample rate and | |
53 * channel count, storing data in a new float-type extended WAV | |
54 * file in a temporary location. This is equivalent to passing an | |
55 * empty path to the constructor above. | |
56 * | |
57 * If normalisation == None, sample values will be written | |
58 * verbatim, and will be ready to read as soon as they have been | |
59 * written. Otherwise samples will be normalised on writing; this | |
60 * will require an additional pass and temporary file, and no | |
61 * samples will be available to read until after writeComplete() | |
62 * has returned. | |
63 */ | |
64 WritableWaveFileModel(sv_samplerate_t sampleRate, | |
65 int channels, | |
66 Normalisation normalisation); | |
67 | |
68 /** | |
69 * Create a WritableWaveFileModel of the given sample rate and | |
70 * channel count, storing data in a new float-type extended WAV | |
71 * file in a temporary location, and applying no normalisation. | |
72 * | |
73 * This is equivalent to passing an empty path and | |
74 * Normalisation::None to the first constructor above. | |
75 */ | |
76 WritableWaveFileModel(sv_samplerate_t sampleRate, | |
77 int channels); | |
78 | |
32 ~WritableWaveFileModel(); | 79 ~WritableWaveFileModel(); |
33 | 80 |
34 /** | 81 /** |
35 * Call addSamples to append a block of samples to the end of the | 82 * Call addSamples to append a block of samples to the end of the |
36 * file. | 83 * file. |
150 QString indent = "", | 197 QString indent = "", |
151 QString extraAttributes = "") const; | 198 QString extraAttributes = "") const; |
152 | 199 |
153 protected: | 200 protected: |
154 ReadOnlyWaveFileModel *m_model; | 201 ReadOnlyWaveFileModel *m_model; |
155 WavFileWriter *m_writer; | 202 |
203 /** When normalising, this writer is used to write verbatim | |
204 * samples to the temporary file prior to | |
205 * normalisation. Otherwise it's null | |
206 */ | |
207 WavFileWriter *m_temporaryWriter; | |
208 QString m_temporaryPath; | |
209 | |
210 /** When not normalising, this writer is used to write verbatim | |
211 * samples direct to the target file. When normalising, it is | |
212 * used to write normalised samples to the target after the | |
213 * temporary file has been completed. But it is still created on | |
214 * initialisation, so that there is a file header ready for the | |
215 * reader to address. | |
216 */ | |
217 WavFileWriter *m_targetWriter; | |
218 QString m_targetPath; | |
219 | |
156 WavFileReader *m_reader; | 220 WavFileReader *m_reader; |
221 Normalisation m_normalisation; | |
157 sv_samplerate_t m_sampleRate; | 222 sv_samplerate_t m_sampleRate; |
158 int m_channels; | 223 int m_channels; |
159 sv_frame_t m_frameCount; | 224 sv_frame_t m_frameCount; |
160 sv_frame_t m_startFrame; | 225 sv_frame_t m_startFrame; |
161 int m_proportion; | 226 int m_proportion; |
227 | |
228 private: | |
229 void init(QString path = ""); | |
230 void normaliseToTarget(); | |
162 }; | 231 }; |
163 | 232 |
164 #endif | 233 #endif |
165 | 234 |