MCPcopy Create free account
hub / github.com/Tracktion/choc / loadFileContent

Method loadFileContent

choc/audio/choc_AudioFileFormat.h:468–496  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

466}
467
468inline AudioFileData AudioFileReader::loadFileContent (double targetSampleRate,
469 uint64_t maxNumFrames,
470 uint32_t maxNumChannels)
471{
472 const auto& props = getProperties();
473
474 auto rate = props.sampleRate;
475 auto numFrames = props.numFrames;
476 auto numChannels = props.numChannels;
477
478 if (rate <= 0) throw std::runtime_error ("Cannot open file");
479 if (numFrames > maxNumFrames) throw std::runtime_error ("File is too long");
480 if (numChannels > maxNumChannels) throw std::runtime_error ("File contains too many channels");
481
482 if (numFrames == 0)
483 return {};
484
485 AudioFileData data;
486 data.frames.resize ({ numChannels, static_cast<choc::buffer::FrameCount> (numFrames) });
487 data.sampleRate = rate;
488
489 if (! readFrames (0, data.frames.getView()))
490 throw std::runtime_error ("Failed to read from file");
491
492 if (targetSampleRate > 0)
493 data.resample (targetSampleRate, maxNumFrames);
494
495 return data;
496}
497
498inline uint64_t copyAudioData (AudioFileWriter& dest, AudioFileReader& source, uint64_t maxNumFramesToCopy)
499{

Callers 1

mainFunction · 0.80

Calls 3

getViewMethod · 0.80
resampleMethod · 0.80
resizeMethod · 0.45

Tested by

no test coverage detected