openMSX
SDLSoundDriver.hh
Go to the documentation of this file.
1#ifndef SDLSOUNDDRIVER_HH
2#define SDLSOUNDDRIVER_HH
3
4#include "SoundDriver.hh"
5#include "SDLSurfacePtr.hh"
6#include "MemBuffer.hh"
7#include <SDL.h>
8
9namespace openmsx {
10
11class Reactor;
12
13class SDLSoundDriver final : public SoundDriver
14{
15public:
18
19 SDLSoundDriver(Reactor& reactor, unsigned wantedFreq, unsigned samples);
20 ~SDLSoundDriver() override;
21
22 void mute() override;
23 void unmute() override;
24
25 [[nodiscard]] unsigned getFrequency() const override;
26 [[nodiscard]] unsigned getSamples() const override;
27
28 void uploadBuffer(std::span<const StereoFloat> buffer) override;
29
30private:
31 void reInit();
32 [[nodiscard]] unsigned getBufferFilled() const;
33 [[nodiscard]] unsigned getBufferFree() const;
34 static void audioCallbackHelper(void* userdata, uint8_t* strm, int len);
35 void audioCallback(std::span<StereoFloat> stream);
36
37private:
38 Reactor& reactor;
39 SDL_AudioDeviceID deviceID;
40 MemBuffer<StereoFloat> mixBuffer;
41 unsigned mixBufferSize;
42 unsigned frequency;
43 unsigned fragmentSize;
44 unsigned readIdx, writeIdx;
45 bool muted = true;
47};
48
49} // namespace openmsx
50
51#endif
This class manages the lifetime of a block of memory.
Definition: MemBuffer.hh:29
Contains the main loop of openMSX.
Definition: Reactor.hh:68
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=(const SDLSoundDriver &)=delete
unsigned getSamples() const override
Get the number of samples that should be created 'per fragment'.
This file implemented 3 utility functions:
Definition: Autofire.cc:9