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 
9 namespace openmsx {
10 
11 class Reactor;
12 
13 class SDLSoundDriver final : public SoundDriver
14 {
15 public:
16  SDLSoundDriver(const SDLSoundDriver&) = delete;
17  SDLSoundDriver& operator=(const SDLSoundDriver&) = delete;
18 
19  SDLSoundDriver(Reactor& reactor, unsigned wantedFreq, unsigned samples);
20  ~SDLSoundDriver() override;
21 
22  void mute() override;
23  void unmute() override;
24 
25  unsigned getFrequency() const override;
26  unsigned getSamples() const override;
27 
28  void uploadBuffer(float* buffer, unsigned len) override;
29 
30 private:
31  void reInit();
32  unsigned getBufferFilled() const;
33  unsigned getBufferFree() const;
34  static void audioCallbackHelper(void* userdata, uint8_t* strm, int len);
35  void audioCallback(float* stream, unsigned len);
36 
37  Reactor& reactor;
38  SDL_AudioDeviceID deviceID;
39  MemBuffer<float> mixBuffer;
40  unsigned mixBufferSize;
41  unsigned frequency;
42  unsigned fragmentSize;
43  unsigned readIdx, writeIdx;
44  bool muted;
45  SDLSubSystemInitializer<SDL_INIT_AUDIO> audioInitializer;
46 };
47 
48 } // namespace openmsx
49 
50 #endif
bool getEnum() const noexcept
Definition: EnumSetting.hh:96
SDLSoundDriver(Reactor &reactor, unsigned wantedFreq, unsigned samples)
void mute() override
Mute the sound system.
void unmute() override
Unmute the sound system.
unsigned getSamples() const override
Get the number of samples that should be created &#39;per fragment&#39;.
void uploadBuffer(float *buffer, unsigned len) override
unsigned getFrequency() const override
Returns the actual sample frequency.
SDLSoundDriver & operator=(const SDLSoundDriver &)=delete
SDLSoundDriver(const SDLSoundDriver &)=delete