MCPcopy Create free account
hub / github.com/bbc/audiowaveform / run

Method run

src/SndFileAudioFileReader.cpp:184–261  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

182//------------------------------------------------------------------------------
183
184bool SndFileAudioFileReader::run(AudioProcessor& processor)
185{
186 if (input_file_ == nullptr) {
187 return false;
188 }
189
190 ProgressReporter progress_reporter;
191
192 const int BUFFER_SIZE = 16384;
193
194 float float_buffer[BUFFER_SIZE];
195 short input_buffer[BUFFER_SIZE];
196
197 const int sub_type = info_.format & SF_FORMAT_SUBMASK;
198
199 const bool is_floating_point = sub_type == SF_FORMAT_FLOAT ||
200 sub_type == SF_FORMAT_DOUBLE;
201
202 sf_count_t frames_to_read = BUFFER_SIZE / info_.channels;
203 sf_count_t frames_read = frames_to_read;
204
205 sf_count_t total_frames_read = 0;
206
207 bool success = processor.init(info_.samplerate, info_.channels, info_.frames, BUFFER_SIZE);
208
209 if (success && processor.shouldContinue()) {
210 progress_reporter.update(0.0, 0, info_.frames);
211
212 while (success && frames_read == frames_to_read) {
213 if (is_floating_point) {
214 frames_read = sf_readf_float(
215 input_file_,
216 float_buffer,
217 frames_to_read
218 );
219
220 // Scale floating-point samples from [-1.0, 1.0] to 16-bit
221 // integer range. Note: we don't use SFC_SET_SCALE_FLOAT_INT_READ
222 // as this scales using the overall measured waveform peak
223 // amplitude, resulting in an unwanted amplitude change.
224
225 for (int i = 0; i < frames_read * info_.channels; ++i) {
226 input_buffer[i] = static_cast<short>(
227 float_buffer[i] * std::numeric_limits<short>::max()
228 );
229 }
230 }
231 else {
232 frames_read = sf_readf_short(
233 input_file_,
234 input_buffer,
235 frames_to_read
236 );
237 }
238
239 success = processor.process(
240 input_buffer,
241 static_cast<int>(frames_read)

Callers

nothing calls this directly

Calls 5

updateMethod · 0.80
initMethod · 0.45
shouldContinueMethod · 0.45
processMethod · 0.45
doneMethod · 0.45

Tested by

no test coverage detected