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-2019 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
26class Resampler {
27 public:
28
29 using NextFragmentCallback = std::function<Int16*()>;
30
31 class Format {
32 public:
33
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;
43 uInt32 fragmentSize;
44 bool stereo;
45
46 private:
47
48 Format() = delete;
49 };
50
51 public:
52
53 Resampler(Format formatFrom, Format formatTo, NextFragmentCallback nextFragmentCallback) :
54 myFormatFrom(formatFrom),
55 myFormatTo(formatTo),
56 myNextFragmentCallback(nextFragmentCallback),
57 myUnderrunLogger("audio buffer underrun", Logger::Level::INFO)
58 {}
59
60 virtual void fillFragment(float* fragment, uInt32 length) = 0;
61
62 virtual ~Resampler() {}
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