From 0efbf96b4aef91d784244172bc9e9708db908046 Mon Sep 17 00:00:00 2001 From: Paul Ferrand Date: Wed, 4 Dec 2019 00:17:10 +0100 Subject: [PATCH] Move the oversampling primitives to the oversampling file. --- src/sfizz/FilePool.cpp | 43 +++-------------------------------------- src/sfizz/Oversampler.h | 40 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 40 deletions(-) diff --git a/src/sfizz/FilePool.cpp b/src/sfizz/FilePool.cpp index a28a188f..e637b83f 100644 --- a/src/sfizz/FilePool.cpp +++ b/src/sfizz/FilePool.cpp @@ -34,43 +34,6 @@ #include using namespace std::chrono_literals; -template -std::unique_ptr> upsample2x(const sfz::AudioBuffer& buffer) -{ - // auto tempBuffer = std::make_unique>(buffer.getNumFrames() * 2); - auto outputBuffer = std::make_unique>(buffer.getNumChannels(), buffer.getNumFrames() * 2); - for (int channelIdx = 0; channelIdx < buffer.getNumChannels(); channelIdx++) { - sfz::upsample2xStage(buffer.getConstSpan(channelIdx), outputBuffer->getSpan(channelIdx)); - } - return outputBuffer; -} - -template -std::unique_ptr> upsample4x(const sfz::AudioBuffer& buffer) -{ - auto tempBuffer = std::make_unique>(buffer.getNumFrames() * 2); - auto outputBuffer = std::make_unique>(buffer.getNumChannels(), buffer.getNumFrames() * 4); - for (int channelIdx = 0; channelIdx < buffer.getNumChannels(); channelIdx++) { - sfz::upsample2xStage(buffer.getConstSpan(channelIdx), absl::MakeSpan(*tempBuffer)); - sfz::upsample4xStage(absl::MakeConstSpan(*tempBuffer), outputBuffer->getSpan(channelIdx)); - } - return outputBuffer; -} - -template -std::unique_ptr> upsample8x(const sfz::AudioBuffer& buffer) -{ - auto tempBuffer2x = std::make_unique>(buffer.getNumFrames() * 2); - auto tempBuffer4x = std::make_unique>(buffer.getNumFrames() * 4); - auto outputBuffer = std::make_unique>(buffer.getNumChannels(), buffer.getNumFrames() * 8); - for (int channelIdx = 0; channelIdx < buffer.getNumChannels(); channelIdx++) { - sfz::upsample2xStage(buffer.getConstSpan(channelIdx), absl::MakeSpan(*tempBuffer2x)); - sfz::upsample4xStage(absl::MakeConstSpan(*tempBuffer2x), absl::MakeSpan(*tempBuffer4x)); - sfz::upsample8xStage(absl::MakeConstSpan(*tempBuffer4x), outputBuffer->getSpan(channelIdx)); - } - return outputBuffer; -} - template std::unique_ptr> readFromFile(SndfileHandle& sndFile, uint32_t numFrames, sfz::Oversampling factor) { @@ -88,11 +51,11 @@ std::unique_ptr> readFromFile(SndfileHandle& sndFile, uint32 case sfz::Oversampling::x1: return baseBuffer; case sfz::Oversampling::x2: - return upsample2x(*baseBuffer); + return sfz::upsample2x(*baseBuffer); case sfz::Oversampling::x4: - return upsample4x(*baseBuffer); + return sfz::upsample4x(*baseBuffer); case sfz::Oversampling::x8: - return upsample8x(*baseBuffer); + return sfz::upsample8x(*baseBuffer); default: return {}; } diff --git a/src/sfizz/Oversampler.h b/src/sfizz/Oversampler.h index 68953be6..b0fafa1b 100644 --- a/src/sfizz/Oversampler.h +++ b/src/sfizz/Oversampler.h @@ -23,8 +23,10 @@ #pragma once #include +#include #include "absl/types/span.h" #include "Debug.h" +#include "AudioBuffer.h" #include "Config.h" #include "hiir/Upsampler2xFpu.h" @@ -92,4 +94,42 @@ template<> inline void upsample4xStage(absl::Span input, absl::Span output); template<> inline void upsample8xStage(absl::Span input, absl::Span output); + +template +std::unique_ptr> upsample2x(const sfz::AudioBuffer& buffer) +{ + // auto tempBuffer = std::make_unique>(buffer.getNumFrames() * 2); + auto outputBuffer = std::make_unique>(buffer.getNumChannels(), buffer.getNumFrames() * 2); + for (int channelIdx = 0; channelIdx < buffer.getNumChannels(); channelIdx++) { + sfz::upsample2xStage(buffer.getConstSpan(channelIdx), outputBuffer->getSpan(channelIdx)); + } + return outputBuffer; +} + +template +std::unique_ptr> upsample4x(const sfz::AudioBuffer& buffer) +{ + auto tempBuffer = std::make_unique>(buffer.getNumFrames() * 2); + auto outputBuffer = std::make_unique>(buffer.getNumChannels(), buffer.getNumFrames() * 4); + for (int channelIdx = 0; channelIdx < buffer.getNumChannels(); channelIdx++) { + sfz::upsample2xStage(buffer.getConstSpan(channelIdx), absl::MakeSpan(*tempBuffer)); + sfz::upsample4xStage(absl::MakeConstSpan(*tempBuffer), outputBuffer->getSpan(channelIdx)); + } + return outputBuffer; +} + +template +std::unique_ptr> upsample8x(const sfz::AudioBuffer& buffer) +{ + auto tempBuffer2x = std::make_unique>(buffer.getNumFrames() * 2); + auto tempBuffer4x = std::make_unique>(buffer.getNumFrames() * 4); + auto outputBuffer = std::make_unique>(buffer.getNumChannels(), buffer.getNumFrames() * 8); + for (int channelIdx = 0; channelIdx < buffer.getNumChannels(); channelIdx++) { + sfz::upsample2xStage(buffer.getConstSpan(channelIdx), absl::MakeSpan(*tempBuffer2x)); + sfz::upsample4xStage(absl::MakeConstSpan(*tempBuffer2x), absl::MakeSpan(*tempBuffer4x)); + sfz::upsample8xStage(absl::MakeConstSpan(*tempBuffer4x), outputBuffer->getSpan(channelIdx)); + } + return outputBuffer; +} + }