Mercurial > hg > svcore
comparison data/model/WritableWaveFileModel.h @ 1527:710e6250a401 zoom
Merge from default branch
author | Chris Cannam |
---|---|
date | Mon, 17 Sep 2018 13:51:14 +0100 |
parents | 954d0cf29ca7 |
children | c01cbe41aeb5 |
comparison
equal
deleted
inserted
replaced
1324:d4a28d1479a8 | 1527:710e6250a401 |
---|---|
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. Caller should also call setWriteProportion() to update | 83 * file. |
37 * the progress of this file, if it has a known end point, and | 84 * |
38 * should call writeComplete() when the file has been written. | 85 * This function only appends the samples to the file being |
39 */ | 86 * written; it does not update the model's view of the samples in |
40 virtual bool addSamples(float **samples, sv_frame_t count); | 87 * that file. That is, it updates the file on disc but the model |
41 | 88 * itself does not change its content. This is because re-reading |
89 * the file to update the model may be more expensive than adding | |
90 * the samples in the first place. If you are writing small | |
91 * numbers of samples repeatedly, you probably only want the model | |
92 * to update periodically rather than after every write. | |
93 * | |
94 * Call updateModel() periodically to tell the model to update its | |
95 * own view of the samples in the file being written. | |
96 * | |
97 * Call setWriteProportion() periodically if the file being | |
98 * written has known duration and you want the model to be able to | |
99 * report the write progress as a percentage. | |
100 * | |
101 * Call writeComplete() when the file has been completely written. | |
102 */ | |
103 virtual bool addSamples(const float *const *samples, sv_frame_t count); | |
104 | |
105 /** | |
106 * Tell the model to update its own (read) view of the (written) | |
107 * file. May cause modelChanged() and modelChangedWithin() to be | |
108 * emitted. See the comment to addSamples above for rationale. | |
109 */ | |
110 void updateModel(); | |
111 | |
42 /** | 112 /** |
43 * Set the proportion of the file which has been written so far, | 113 * Set the proportion of the file which has been written so far, |
44 * as a percentage. This may be used to indicate progress. | 114 * as a percentage. This may be used to indicate progress. |
45 * | 115 * |
46 * Note that this differs from the "completion" percentage | 116 * Note that this differs from the "completion" percentage |
54 */ | 124 */ |
55 void setWriteProportion(int proportion); | 125 void setWriteProportion(int proportion); |
56 | 126 |
57 /** | 127 /** |
58 * Indicate that writing is complete. You should call this even if | 128 * Indicate that writing is complete. You should call this even if |
59 * you have never called setWriteProportion(). | 129 * you have never called setWriteProportion() or updateModel(). |
60 */ | 130 */ |
61 void writeComplete(); | 131 void writeComplete(); |
62 | 132 |
63 static const int PROPORTION_UNKNOWN; | 133 static const int PROPORTION_UNKNOWN; |
64 | 134 |
108 virtual sv_frame_t getStartFrame() const { return m_startFrame; } | 178 virtual sv_frame_t getStartFrame() const { return m_startFrame; } |
109 virtual sv_frame_t getEndFrame() const { return m_startFrame + getFrameCount(); } | 179 virtual sv_frame_t getEndFrame() const { return m_startFrame + getFrameCount(); } |
110 | 180 |
111 void setStartFrame(sv_frame_t startFrame); | 181 void setStartFrame(sv_frame_t startFrame); |
112 | 182 |
113 virtual std::vector<float> getData(int channel, sv_frame_t start, sv_frame_t count) const; | 183 virtual floatvec_t getData(int channel, sv_frame_t start, sv_frame_t count) const; |
114 | 184 |
115 virtual std::vector<std::vector<float>> getMultiChannelData(int fromchannel, int tochannel, sv_frame_t start, sv_frame_t count) const; | 185 virtual std::vector<floatvec_t> getMultiChannelData(int fromchannel, int tochannel, sv_frame_t start, sv_frame_t count) const; |
116 | 186 |
117 virtual int getSummaryBlockSize(int desired) const; | 187 virtual int getSummaryBlockSize(int desired) const; |
118 | 188 |
119 virtual void getSummaries(int channel, sv_frame_t start, sv_frame_t count, | 189 virtual void getSummaries(int channel, sv_frame_t start, sv_frame_t count, |
120 RangeBlock &ranges, int &blockSize) const; | 190 RangeBlock &ranges, int &blockSize) const; |
127 QString indent = "", | 197 QString indent = "", |
128 QString extraAttributes = "") const; | 198 QString extraAttributes = "") const; |
129 | 199 |
130 protected: | 200 protected: |
131 ReadOnlyWaveFileModel *m_model; | 201 ReadOnlyWaveFileModel *m_model; |
132 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 | |
133 WavFileReader *m_reader; | 220 WavFileReader *m_reader; |
221 Normalisation m_normalisation; | |
134 sv_samplerate_t m_sampleRate; | 222 sv_samplerate_t m_sampleRate; |
135 int m_channels; | 223 int m_channels; |
136 sv_frame_t m_frameCount; | 224 sv_frame_t m_frameCount; |
137 sv_frame_t m_startFrame; | 225 sv_frame_t m_startFrame; |
138 int m_proportion; | 226 int m_proportion; |
227 | |
228 private: | |
229 void init(QString path = ""); | |
230 void normaliseToTarget(); | |
139 }; | 231 }; |
140 | 232 |
141 #endif | 233 #endif |
142 | 234 |