// SONIC ROBO BLAST 2 //----------------------------------------------------------------------------- // Copyright (C) 2022-2023 by Ronald "Eidolon" Kinard // // This program is free software distributed under the // terms of the GNU General Public License, version 2. // See the 'LICENSE' file for more details. //----------------------------------------------------------------------------- #ifndef __SRB2_AUDIO_RESAMPLE_HPP__ #define __SRB2_AUDIO_RESAMPLE_HPP__ #include #include #include #include #include #include #include "sound_chunk.hpp" #include "source.hpp" namespace srb2::audio { template class Resampler : public Source { public: Resampler(std::shared_ptr>&& source_, float ratio); Resampler(const Resampler& r) = delete; Resampler(Resampler&& r); virtual ~Resampler(); virtual std::size_t generate(tcb::span> buffer); void ratio(float new_ratio); Resampler& operator=(const Resampler& r) = delete; Resampler& operator=(Resampler&& r); private: std::shared_ptr> source_; float ratio_ {1.f}; std::vector> buf_; Sample last_; int pos_ {0}; float pos_frac_ {0.f}; void advance(float samples) { pos_frac_ += samples; float integer; std::modf(pos_frac_, &integer); pos_ += integer; pos_frac_ -= integer; } void refill(); }; extern template class Resampler<1>; extern template class Resampler<2>; } // namespace srb2::audio #endif // __SRB2_AUDIO_RESAMPLE_HPP__