From 4b44b8b4fba5ddfe28e5c6bd418f48ba475eaa79 Mon Sep 17 00:00:00 2001 From: MerryMage Date: Sun, 12 Aug 2018 19:32:39 +0100 Subject: audio_core: Interpolate --- src/audio_core/algorithm/interpolate.h | 43 ++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/audio_core/algorithm/interpolate.h (limited to 'src/audio_core/algorithm/interpolate.h') diff --git a/src/audio_core/algorithm/interpolate.h b/src/audio_core/algorithm/interpolate.h new file mode 100644 index 000000000..c79c2eef4 --- /dev/null +++ b/src/audio_core/algorithm/interpolate.h @@ -0,0 +1,43 @@ +// Copyright 2018 yuzu Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include +#include +#include "audio_core/algorithm/filter.h" +#include "common/common_types.h" + +namespace AudioCore { + +struct InterpolationState { + static constexpr size_t lanczos_taps = 4; + static constexpr size_t history_size = lanczos_taps * 2 - 1; + + double current_ratio = 0.0; + CascadingFilter nyquist; + std::array, history_size> history = {}; + double position = 0; +}; + +/// Interpolates input signal to produce output signal. +/// @param input The signal to interpolate. +/// @param ratio Interpolation ratio. +/// ratio > 1.0 results in fewer output samples. +/// ratio < 1.0 results in more output samples. +/// @returns Output signal. +std::vector Interpolate(InterpolationState& state, std::vector input, double ratio); + +/// Interpolates input signal to produce output signal. +/// @param input The signal to interpolate. +/// @param input_rate The sample rate of input. +/// @param output_rate The desired sample rate of the output. +/// @returns Output signal. +inline std::vector Interpolate(InterpolationState& state, std::vector input, + u32 input_rate, u32 output_rate) { + const double ratio = static_cast(input_rate) / static_cast(output_rate); + return Interpolate(state, std::move(input), ratio); +} + +} // namespace AudioCore -- cgit v1.2.3