| 466 | } |
| 467 | |
| 468 | inline 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 | |
| 498 | inline uint64_t copyAudioData (AudioFileWriter& dest, AudioFileReader& source, uint64_t maxNumFramesToCopy) |
| 499 | { |