(svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
This commit is contained in:
@@ -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 */
|
||||
|
@@ -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 */
|
||||
|
@@ -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;
|
||||
|
@@ -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 */
|
||||
|
@@ -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 */
|
||||
|
@@ -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 */
|
||||
|
27
src/sound/sound_driver.hpp
Normal file
27
src/sound/sound_driver.hpp
Normal file
@@ -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 */
|
@@ -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,
|
||||
};
|
||||
|
@@ -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 */
|
||||
|
Reference in New Issue
Block a user