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;
46 };
47 
48 } // namespace openmsx
49 
50 #endif
openmsx::SDLSoundDriver::~SDLSoundDriver
~SDLSoundDriver() override
Definition: SDLSoundDriver.cc:44
openmsx::SDLSoundDriver::mute
void mute() override
Mute the sound system.
Definition: SDLSoundDriver.cc:57
openmsx::SDLSoundDriver::unmute
void unmute() override
Unmute the sound system.
Definition: SDLSoundDriver.cc:65
openmsx::SoundDriver
Definition: SoundDriver.hh:6
openmsx::Reactor
Contains the main loop of openMSX.
Definition: Reactor.hh:66
SDLSurfacePtr.hh
openmsx::MemBuffer< float >
openmsx::SDLSoundDriver::getSamples
unsigned getSamples() const override
Get the number of samples that should be created 'per fragment'.
Definition: SDLSoundDriver.cc:79
MemBuffer.hh
openmsx::SDLSoundDriver::operator=
SDLSoundDriver & operator=(const SDLSoundDriver &)=delete
openmsx::SDLSoundDriver
Definition: SDLSoundDriver.hh:13
openmsx::SDLSoundDriver::SDLSoundDriver
SDLSoundDriver(const SDLSoundDriver &)=delete
SoundDriver.hh
SDLSubSystemInitializer< SDL_INIT_AUDIO >
openmsx::SDLSoundDriver::getFrequency
unsigned getFrequency() const override
Returns the actual sample frequency.
Definition: SDLSoundDriver.cc:74
openmsx::SDLSoundDriver::uploadBuffer
void uploadBuffer(float *buffer, unsigned len) override
Definition: SDLSoundDriver.cc:132
openmsx
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5