summaryrefslogtreecommitdiff
path: root/src/sound
diff options
context:
space:
mode:
authorpeter1138 <peter1138@openttd.org>2007-07-05 12:23:54 +0000
committerpeter1138 <peter1138@openttd.org>2007-07-05 12:23:54 +0000
commit68c6add8ccd9aa32eb799a433aa8a3b05ec84a57 (patch)
tree52e0cc5b1e4eb6cf9aed8556873ee6833662e11f /src/sound
parentb5079071762021ebfbb66a14eaa598e48d6a3234 (diff)
downloadopenttd-68c6add8ccd9aa32eb799a433aa8a3b05ec84a57.tar.xz
(svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
Diffstat (limited to 'src/sound')
-rw-r--r--src/sound/cocoa_s.cpp11
-rw-r--r--src/sound/cocoa_s.h18
-rw-r--r--src/sound/null_s.cpp8
-rw-r--r--src/sound/null_s.h18
-rw-r--r--src/sound/sdl_s.cpp11
-rw-r--r--src/sound/sdl_s.h18
-rw-r--r--src/sound/sound_driver.hpp27
-rw-r--r--src/sound/win32_s.cpp11
-rw-r--r--src/sound/win32_s.h18
9 files changed, 103 insertions, 37 deletions
diff --git a/src/sound/cocoa_s.cpp b/src/sound/cocoa_s.cpp
index 246cbcecf..0c1e793f9 100644
--- a/src/sound/cocoa_s.cpp
+++ b/src/sound/cocoa_s.cpp
@@ -36,6 +36,7 @@
#undef Point
#undef Rect
+static FSoundDriver_Cocoa iFSoundDriver_Cocoa;
static AudioUnit _outputAudioUnit;
@@ -48,7 +49,7 @@ static OSStatus audioCallback(void *inRefCon, AudioUnitRenderActionFlags inActio
}
-static const char *CocoaSoundStart(const char * const *parm)
+const char *SoundDriver_Cocoa::Start(const char * const *parm)
{
Component comp;
ComponentDescription desc;
@@ -116,7 +117,7 @@ static const char *CocoaSoundStart(const char * const *parm)
}
-static void CocoaSoundStop()
+void SoundDriver_Cocoa::Stop()
{
struct AudioUnitInputCallback callback;
@@ -140,10 +141,4 @@ static void CocoaSoundStop()
}
}
-
-const HalSoundDriver _cocoa_sound_driver = {
- CocoaSoundStart,
- CocoaSoundStop,
-};
-
#endif /* WITH_COCOA */
diff --git a/src/sound/cocoa_s.h b/src/sound/cocoa_s.h
index 92f67cb10..96e24522f 100644
--- a/src/sound/cocoa_s.h
+++ b/src/sound/cocoa_s.h
@@ -3,8 +3,22 @@
#ifndef SOUND_COCOA_H
#define SOUND_COCOA_H
-#include "../hal.h"
+#include "sound_driver.hpp"
-extern const HalSoundDriver _cocoa_sound_driver;
+class SoundDriver_Cocoa: public SoundDriver {
+public:
+ /* virtual */ bool CanProbe() { return true; }
+
+ /* virtual */ const char *Start(const char * const *param);
+
+ /* virtual */ void Stop();
+};
+
+class FSoundDriver_Cocoa: public SoundDriverFactory<FSoundDriver_Cocoa> {
+public:
+ /* virtual */ const char *GetName() { return "cocoa"; }
+ /* virtual */ const char *GetDescription() { return "Cocoa Sound Driver"; }
+ /* virtual */ Driver *CreateInstance() { return new SoundDriver_Cocoa(); }
+};
#endif /* SOUND_COCOA_H */
diff --git a/src/sound/null_s.cpp b/src/sound/null_s.cpp
index 00eab496f..c8fe22ca3 100644
--- a/src/sound/null_s.cpp
+++ b/src/sound/null_s.cpp
@@ -3,10 +3,4 @@
#include "../stdafx.h"
#include "null_s.h"
-static const char *NullSoundStart(const char * const *parm) { return NULL; }
-static void NullSoundStop() {}
-
-const HalSoundDriver _null_sound_driver = {
- NullSoundStart,
- NullSoundStop,
-};
+static FSoundDriver_Null iFSoundDriver_Null;
diff --git a/src/sound/null_s.h b/src/sound/null_s.h
index 204c58376..2f5c79841 100644
--- a/src/sound/null_s.h
+++ b/src/sound/null_s.h
@@ -3,8 +3,22 @@
#ifndef SOUND_NULL_H
#define SOUND_NULL_H
-#include "../hal.h"
+#include "sound_driver.hpp"
-extern const HalSoundDriver _null_sound_driver;
+class SoundDriver_Null: public SoundDriver {
+public:
+ /* virtual */ bool CanProbe() { return false; }
+
+ /* virtual */ const char *Start(const char * const *param) { return NULL; }
+
+ /* virtual */ void Stop() { }
+};
+
+class FSoundDriver_Null: public SoundDriverFactory<FSoundDriver_Null> {
+public:
+ /* virtual */ const char *GetName() { return "null"; }
+ /* virtual */ const char *GetDescription() { return "Null Sound Driver"; }
+ /* virtual */ Driver *CreateInstance() { return new SoundDriver_Null(); }
+};
#endif /* SOUND_NULL_H */
diff --git a/src/sound/sdl_s.cpp b/src/sound/sdl_s.cpp
index b90336866..f9f40d4e3 100644
--- a/src/sound/sdl_s.cpp
+++ b/src/sound/sdl_s.cpp
@@ -10,12 +10,14 @@
#include "sdl_s.h"
#include <SDL.h>
+static FSoundDriver_SDL iFSoundDriver_SDL;
+
static void CDECL fill_sound_buffer(void *userdata, Uint8 *stream, int len)
{
MxMixSamples(stream, len / 4);
}
-static const char *SdlSoundStart(const char * const *parm)
+const char *SoundDriver_SDL::Start(const char * const *parm)
{
SDL_AudioSpec spec;
@@ -32,15 +34,10 @@ static const char *SdlSoundStart(const char * const *parm)
return NULL;
}
-static void SdlSoundStop()
+void SoundDriver_SDL::Stop()
{
SDL_CALL SDL_CloseAudio();
SdlClose(SDL_INIT_AUDIO);
}
-const HalSoundDriver _sdl_sound_driver = {
- SdlSoundStart,
- SdlSoundStop,
-};
-
#endif /* WITH_SDL */
diff --git a/src/sound/sdl_s.h b/src/sound/sdl_s.h
index a667e137a..97a9036eb 100644
--- a/src/sound/sdl_s.h
+++ b/src/sound/sdl_s.h
@@ -3,8 +3,22 @@
#ifndef SOUND_SDL_H
#define SOUND_SDL_H
-#include "../hal.h"
+#include "sound_driver.hpp"
-extern const HalSoundDriver _sdl_sound_driver;
+class SoundDriver_SDL: public SoundDriver {
+public:
+ /* virtual */ bool CanProbe() { return true; }
+
+ /* virtual */ const char *Start(const char * const *param);
+
+ /* virtual */ void Stop();
+};
+
+class FSoundDriver_SDL: public SoundDriverFactory<FSoundDriver_SDL> {
+public:
+ /* virtual */ const char *GetName() { return "sdl"; }
+ /* virtual */ const char *GetDescription() { return "SDL Sound Driver"; }
+ /* virtual */ Driver *CreateInstance() { return new SoundDriver_SDL(); }
+};
#endif /* SOUND_SDL_H */
diff --git a/src/sound/sound_driver.hpp b/src/sound/sound_driver.hpp
new file mode 100644
index 000000000..de1a19ac8
--- /dev/null
+++ b/src/sound/sound_driver.hpp
@@ -0,0 +1,27 @@
+/* $Id$ */
+
+#ifndef SOUND_SOUND_DRIVER_HPP
+#define SOUND_SOUND_DRIVER_HPP
+
+#include "../driver.h"
+
+class SoundDriver: public Driver {
+};
+
+class SoundDriverFactoryBase: public DriverFactoryBase {
+};
+
+template <class T>
+class SoundDriverFactory: public SoundDriverFactoryBase {
+public:
+ SoundDriverFactory() { this->RegisterDriver(((T *)this)->GetName(), Driver::DT_SOUND); }
+
+ /**
+ * Get the long, human readable, name for the Driver-class.
+ */
+ const char *GetName();
+};
+
+extern SoundDriver *_sound_driver;
+
+#endif /* SOUND_SOUND_DRIVER_HPP */
diff --git a/src/sound/win32_s.cpp b/src/sound/win32_s.cpp
index 61b9ce9eb..578011986 100644
--- a/src/sound/win32_s.cpp
+++ b/src/sound/win32_s.cpp
@@ -10,6 +10,8 @@
#include <windows.h>
#include <mmsystem.h>
+static FSoundDriver_Win32 iFSoundDriver_Win32;
+
static HWAVEOUT _waveout;
static WAVEHDR _wave_hdr[2];
static int _bufsize;
@@ -48,7 +50,7 @@ static void CALLBACK waveOutProc(HWAVEOUT hwo, UINT uMsg, DWORD_PTR dwInstance,
}
}
-static const char *Win32SoundStart(const char* const* parm)
+const char *SoundDriver_Win32::Start(const char* const* parm)
{
WAVEFORMATEX wfex;
wfex.wFormatTag = WAVE_FORMAT_PCM;
@@ -69,7 +71,7 @@ static const char *Win32SoundStart(const char* const* parm)
return NULL;
}
-static void Win32SoundStop()
+void SoundDriver_Win32::Stop()
{
HWAVEOUT waveout = _waveout;
@@ -79,8 +81,3 @@ static void Win32SoundStop()
waveOutUnprepareHeader(waveout, &_wave_hdr[1], sizeof(WAVEHDR));
waveOutClose(waveout);
}
-
-const HalSoundDriver _win32_sound_driver = {
- Win32SoundStart,
- Win32SoundStop,
-};
diff --git a/src/sound/win32_s.h b/src/sound/win32_s.h
index b91495edd..10a1f7502 100644
--- a/src/sound/win32_s.h
+++ b/src/sound/win32_s.h
@@ -3,8 +3,22 @@
#ifndef SOUND_WIN32_H
#define SOUND_WIN32_H
-#include "../hal.h"
+#include "sound_driver.hpp"
-extern const HalSoundDriver _win32_sound_driver;
+class SoundDriver_Win32: public SoundDriver {
+public:
+ /* virtual */ bool CanProbe() { return true; }
+
+ /* virtual */ const char *Start(const char * const *param);
+
+ /* virtual */ void Stop();
+};
+
+class FSoundDriver_Win32: public SoundDriverFactory<FSoundDriver_Win32> {
+public:
+ /* virtual */ const char *GetName() { return "win32"; }
+ /* virtual */ const char *GetDescription() { return "Win32 Sound Driver"; }
+ /* virtual */ Driver *CreateInstance() { return new SoundDriver_Win32(); }
+};
#endif /* SOUND_WIN32_H */