comparison data/model/WritableWaveFileModel.h @ 1520:954d0cf29ca7 import-audio-data

Switch the normalisation option in WritableWaveFileModel from normalising on read to normalising on write, so that the saved file is already normalised and therefore can be read again without having to remember to normalise it
author Chris Cannam
date Wed, 12 Sep 2018 13:56:56 +0100
parents 925d205c39b4
children c01cbe41aeb5
comparison
equal deleted inserted replaced
1519:fbe8afdfa8a6 1520:954d0cf29ca7
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 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 */
31 WritableWaveFileModel(sv_samplerate_t sampleRate, 64 WritableWaveFileModel(sv_samplerate_t sampleRate,
32 int channels, 65 int channels,
33 QString path = "", 66 Normalisation normalisation);
34 bool normaliseOnRead = false); 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
35 ~WritableWaveFileModel(); 79 ~WritableWaveFileModel();
36 80
37 /** 81 /**
38 * 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
39 * file. 83 * file.
153 QString indent = "", 197 QString indent = "",
154 QString extraAttributes = "") const; 198 QString extraAttributes = "") const;
155 199
156 protected: 200 protected:
157 ReadOnlyWaveFileModel *m_model; 201 ReadOnlyWaveFileModel *m_model;
158 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
159 WavFileReader *m_reader; 220 WavFileReader *m_reader;
221 Normalisation m_normalisation;
160 sv_samplerate_t m_sampleRate; 222 sv_samplerate_t m_sampleRate;
161 int m_channels; 223 int m_channels;
162 sv_frame_t m_frameCount; 224 sv_frame_t m_frameCount;
163 sv_frame_t m_startFrame; 225 sv_frame_t m_startFrame;
164 int m_proportion; 226 int m_proportion;
227
228 private:
229 void init(QString path = "");
230 void normaliseToTarget();
165 }; 231 };
166 232
167 #endif 233 #endif
168 234