OXYGENHUB
◆ main openmsx / src / sound / SDLSoundDriver.hh
1.3 KiB · C++ · last changed chore(): initial commit 1 month ago source blame history raw
e8555c89 Andy McCall 1
#ifndef SDLSOUNDDRIVER_HH
2
#define SDLSOUNDDRIVER_HH
3
4
#include "SoundDriver.hh"
5
6
#include "SDLSurfacePtr.hh"
7
8
#include "MemBuffer.hh"
9
10
#include <SDL.h>
11
12
namespace openmsx {
13
14
class Reactor;
15
16
class SDLSoundDriver final : public SoundDriver
17
{
18
public:
19
	SDLSoundDriver(Reactor& reactor, unsigned wantedFreq, unsigned samples);
20
	SDLSoundDriver(const SDLSoundDriver&) = delete;
21
	SDLSoundDriver(SDLSoundDriver&&) = delete;
22
	SDLSoundDriver& operator=(const SDLSoundDriver&) = delete;
23
	SDLSoundDriver& operator=(SDLSoundDriver&&) = delete;
24
	~SDLSoundDriver() override;
25
26
	void mute() override;
27
	void unmute() override;
28
29
	[[nodiscard]] unsigned getFrequency() const override;
30
	[[nodiscard]] unsigned getSamples() const override;
31
32
	void uploadBuffer(std::span<const StereoFloat> buffer) override;
33
34
private:
35
	void reInit();
36
	[[nodiscard]] unsigned getBufferFilled() const;
37
	[[nodiscard]] unsigned getBufferFree() const;
38
	static void audioCallbackHelper(void* userdata, uint8_t* strm, int len);
39
	void audioCallback(std::span<StereoFloat> stream);
40
41
private:
42
	Reactor& reactor;
43
	SDL_AudioDeviceID deviceID;
44
	MemBuffer<StereoFloat> mixBuffer;
45
	unsigned frequency;
46
	unsigned fragmentSize;
47
	unsigned readIdx = 0, writeIdx = 0;
48
	bool muted = true;
49
	[[no_unique_address]] SDLSubSystemInitializer<SDL_INIT_AUDIO> audioInitializer;
50
};
51
52
} // namespace openmsx
53
54
#endif