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

Method resample

choc/audio/choc_AudioFileFormat.h:557–581  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

555}
556
557inline void AudioFileData::resample (double targetSampleRate, uint64_t maxNumFrames)
558{
559 if (targetSampleRate != 0 && std::abs (targetSampleRate - sampleRate) > 1.0)
560 {
561 static constexpr double maxRatio = 64.0;
562
563 if (targetSampleRate > sampleRate * maxRatio || targetSampleRate < sampleRate / maxRatio)
564 throw std::runtime_error ("Resampling ratio is out-of-range");
565
566 auto ratio = targetSampleRate / sampleRate;
567 auto newFrameCount = static_cast<uint64_t> (ratio * static_cast<double> (frames.getNumFrames()) + 0.5);
568
569 if (maxNumFrames != 0 && newFrameCount > maxNumFrames)
570 throw std::runtime_error ("File too long");
571
572 if (newFrameCount != frames.getNumFrames())
573 {
574 using BufferType = decltype (frames);
575 BufferType resampled (frames.getNumChannels(), static_cast<uint32_t> (newFrameCount), false);
576 choc::interpolation::sincInterpolate<BufferType&, BufferType, 10> (resampled, frames);
577 frames = std::move (resampled);
578 sampleRate = targetSampleRate;
579 }
580 }
581}
582
583inline AudioFileData AudioFileFormatList::loadFileContent (std::shared_ptr<std::istream> fileReader,
584 double targetSampleRate,

Callers 1

loadFileContentMethod · 0.80

Calls 2

getNumFramesMethod · 0.45
getNumChannelsMethod · 0.45

Tested by

no test coverage detected