1 //============================================================================ 2 // 3 // SSSS tt lll lll 4 // SS SS tt ll ll 5 // SS tttttt eeee ll ll aaaa 6 // SSSS tt ee ee ll ll aa 7 // SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator" 8 // SS SS tt ee ll ll aa aa 9 // SSSS ttt eeeee llll llll aaaaa 10 // 11 // Copyright (c) 1995-2021 by Bradford W. Mott, Stephen Anthony 12 // and the Stella Team 13 // 14 // See the file "License.txt" for information on usage and redistribution of 15 // this file, and for a DISCLAIMER OF ALL WARRANTIES. 16 //============================================================================ 17 18 #ifndef RESAMPLER_HXX 19 #define RESAMPLER_HXX 20 21 #include <functional> 22 23 #include "bspf.hxx" 24 #include "StaggeredLogger.hxx" 25 26 class Resampler { 27 public: 28 29 using NextFragmentCallback = std::function<Int16*()>; 30 31 class Format { 32 public: 33 Format(uInt32 f_sampleRate,uInt32 f_fragmentSize,bool f_stereo)34 Format(uInt32 f_sampleRate, uInt32 f_fragmentSize, bool f_stereo) : 35 sampleRate(f_sampleRate), 36 fragmentSize(f_fragmentSize), 37 stereo(f_stereo) 38 {} 39 40 public: 41 42 uInt32 sampleRate{31400}; 43 uInt32 fragmentSize{512}; 44 bool stereo{false}; 45 46 private: 47 48 Format() = delete; 49 }; 50 51 public: 52 Resampler(Format formatFrom,Format formatTo,const NextFragmentCallback & nextFragmentCallback)53 Resampler(Format formatFrom, Format formatTo, 54 const NextFragmentCallback& nextFragmentCallback) 55 : myFormatFrom{formatFrom}, 56 myFormatTo{formatTo}, 57 myNextFragmentCallback{nextFragmentCallback}, 58 myUnderrunLogger{"audio buffer underrun", Logger::Level::INFO} { } 59 60 virtual void fillFragment(float* fragment, uInt32 length) = 0; 61 62 virtual ~Resampler() = default; 63 64 protected: 65 66 Format myFormatFrom; 67 Format myFormatTo; 68 69 NextFragmentCallback myNextFragmentCallback; 70 71 StaggeredLogger myUnderrunLogger; 72 73 private: 74 75 Resampler() = delete; 76 Resampler(const Resampler&) = delete; 77 Resampler(Resampler&&) = delete; 78 Resampler& operator=(const Resampler&) = delete; 79 Resampler& operator=(Resampler&&) = delete; 80 81 }; 82 83 #endif // RESAMPLER_HXX 84