Mercurial > hg > svcore
comparison data/fileio/WavFileReader.cpp @ 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 | 75d92155fa20 |
children | 70e172e6cc59 f8e3dcbafb4d |
comparison
equal
deleted
inserted
replaced
1519:fbe8afdfa8a6 | 1520:954d0cf29ca7 |
---|---|
25 | 25 |
26 using namespace std; | 26 using namespace std; |
27 | 27 |
28 WavFileReader::WavFileReader(FileSource source, | 28 WavFileReader::WavFileReader(FileSource source, |
29 bool fileUpdating, | 29 bool fileUpdating, |
30 bool normalise) : | 30 Normalisation normalisation) : |
31 m_file(0), | 31 m_file(0), |
32 m_source(source), | 32 m_source(source), |
33 m_path(source.getLocalFilename()), | 33 m_path(source.getLocalFilename()), |
34 m_seekable(false), | 34 m_seekable(false), |
35 m_lastStart(0), | 35 m_lastStart(0), |
36 m_lastCount(0), | 36 m_lastCount(0), |
37 m_normalise(normalise), | 37 m_normalisation(normalisation), |
38 m_max(0.f), | 38 m_max(0.f), |
39 m_updating(fileUpdating) | 39 m_updating(fileUpdating) |
40 { | 40 { |
41 m_frameCount = 0; | 41 m_frameCount = 0; |
42 m_channelCount = 0; | 42 m_channelCount = 0; |
90 // are definitely seekable so, again cautiously, identify | 90 // are definitely seekable so, again cautiously, identify |
91 // and mark those (basically only non-adaptive WAVs). | 91 // and mark those (basically only non-adaptive WAVs). |
92 m_seekable = true; | 92 m_seekable = true; |
93 } | 93 } |
94 | 94 |
95 if (m_normalise && !m_updating) { | 95 if (m_normalisation != Normalisation::None && !m_updating) { |
96 m_max = getMax(); | 96 m_max = getMax(); |
97 } | 97 } |
98 } | 98 } |
99 | 99 |
100 SVDEBUG << "WavFileReader: Filename " << m_path << ", frame count " << m_frameCount << ", channel count " << m_channelCount << ", sample rate " << m_sampleRate << ", format " << m_fileInfo.format << ", seekable " << m_fileInfo.seekable << " adjusted to " << m_seekable << ", normalise " << m_normalise << endl; | 100 SVDEBUG << "WavFileReader: Filename " << m_path << ", frame count " << m_frameCount << ", channel count " << m_channelCount << ", sample rate " << m_sampleRate << ", format " << m_fileInfo.format << ", seekable " << m_fileInfo.seekable << " adjusted to " << m_seekable << ", normalisation " << int(m_normalisation) << endl; |
101 } | 101 } |
102 | 102 |
103 WavFileReader::~WavFileReader() | 103 WavFileReader::~WavFileReader() |
104 { | 104 { |
105 if (m_file) sf_close(m_file); | 105 if (m_file) sf_close(m_file); |
142 void | 142 void |
143 WavFileReader::updateDone() | 143 WavFileReader::updateDone() |
144 { | 144 { |
145 updateFrameCount(); | 145 updateFrameCount(); |
146 m_updating = false; | 146 m_updating = false; |
147 if (m_normalise) { | 147 if (m_normalisation != Normalisation::None) { |
148 m_max = getMax(); | 148 m_max = getMax(); |
149 } | 149 } |
150 } | 150 } |
151 | 151 |
152 floatvec_t | 152 floatvec_t |
153 WavFileReader::getInterleavedFrames(sv_frame_t start, sv_frame_t count) const | 153 WavFileReader::getInterleavedFrames(sv_frame_t start, sv_frame_t count) const |
154 { | 154 { |
155 floatvec_t frames = getInterleavedFramesUnnormalised(start, count); | 155 floatvec_t frames = getInterleavedFramesUnnormalised(start, count); |
156 | 156 |
157 if (!m_normalise || m_max == 0.f) { | 157 if (m_normalisation == Normalisation::None || m_max == 0.f) { |
158 return frames; | 158 return frames; |
159 } | 159 } |
160 | 160 |
161 for (int i = 0; in_range_for(frames, i); ++i) { | 161 for (int i = 0; in_range_for(frames, i); ++i) { |
162 frames[i] /= m_max; | 162 frames[i] /= m_max; |