openMSX
SDLSoundDriver.hh
Go to the documentation of this file.
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
12namespace openmsx {
13
14class Reactor;
15
16class SDLSoundDriver final : public SoundDriver
17{
18public:
19 SDLSoundDriver(Reactor& reactor, unsigned wantedFreq, unsigned samples);
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
34private:
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
41private:
42 Reactor& reactor;
43 SDL_AudioDeviceID deviceID;
44 MemBuffer<StereoFloat> mixBuffer;
45 unsigned mixBufferSize;
46 unsigned frequency;
47 unsigned fragmentSize;
48 unsigned readIdx, writeIdx;
49 bool muted = true;
50 [[no_unique_address]] SDLSubSystemInitializer<SDL_INIT_AUDIO> audioInitializer;
51};
52
53} // namespace openmsx
54
55#endif
This class manages the lifetime of a block of memory.
Definition MemBuffer.hh:29
Contains the main loop of openMSX.
Definition Reactor.hh:74
void uploadBuffer(std::span< const StereoFloat > buffer) override
void unmute() override
Unmute the sound system.
void mute() override
Mute the sound system.
unsigned getFrequency() const override
Returns the actual sample frequency.
SDLSoundDriver(const SDLSoundDriver &)=delete
SDLSoundDriver & operator=(SDLSoundDriver &&)=delete
SDLSoundDriver & operator=(const SDLSoundDriver &)=delete
unsigned getSamples() const override
Get the number of samples that should be created 'per fragment'.
SDLSoundDriver(SDLSoundDriver &&)=delete
This file implemented 3 utility functions:
Definition Autofire.cc:11