23 #if SDL_AUDIO_DRIVER_FUSIONSOUND
34 #include "../SDL_audiomem.h"
35 #include "../SDL_audio_c.h"
38 #include <fusionsound/fusionsound_version.h>
42 #ifdef SDL_AUDIO_DRIVER_FUSIONSOUND_DYNAMIC
49 #if (FUSIONSOUND_MAJOR_VERSION == 1) && (FUSIONSOUND_MINOR_VERSION < 1)
50 typedef DFBResult DirectResult;
54 #define FUSION_BUFFERS (2)
56 #ifdef SDL_AUDIO_DRIVER_FUSIONSOUND_DYNAMIC
58 static const char *fs_library = SDL_AUDIO_DRIVER_FUSIONSOUND_DYNAMIC;
59 static void *fs_handle =
NULL;
61 static DirectResult (*
SDL_NAME(FusionSoundInit)) (
int *argc,
char *(*argv[]));
62 static DirectResult (*
SDL_NAME(FusionSoundCreate)) (IFusionSound **
65 #define SDL_FS_SYM(x) { #x, (void **) (char *) &SDL_NAME(x) }
72 SDL_FS_SYM(FusionSoundInit),
73 SDL_FS_SYM(FusionSoundCreate),
80 UnloadFusionSoundLibrary()
82 if (fs_handle !=
NULL) {
89 LoadFusionSoundLibrary(
void)
93 if (fs_handle ==
NULL) {
95 if (fs_handle !=
NULL) {
98 *fs_functions[
i].func =
100 if (!*fs_functions[i].
func) {
102 UnloadFusionSoundLibrary();
115 UnloadFusionSoundLibrary()
121 LoadFusionSoundLibrary(
void)
130 SDL_FS_WaitDevice(
_THIS)
132 this->hidden->stream->Wait(this->hidden->stream,
133 this->hidden->mixsamples);
137 SDL_FS_PlayDevice(
_THIS)
141 ret = this->hidden->stream->Write(this->hidden->stream,
142 this->hidden->mixbuf,
143 this->hidden->mixsamples);
149 fprintf(stderr,
"Wrote %d bytes of audio data\n", this->hidden->mixlen);
154 SDL_FS_WaitDone(
_THIS)
156 this->hidden->stream->Wait(this->hidden->stream,
157 this->hidden->mixsamples * FUSION_BUFFERS);
162 SDL_FS_GetDeviceBuf(
_THIS)
164 return (this->hidden->mixbuf);
169 SDL_FS_CloseDevice(
_THIS)
171 if (this->hidden !=
NULL) {
173 this->hidden->mixbuf =
NULL;
174 if (this->hidden->stream) {
175 this->hidden->stream->Release(this->hidden->stream);
176 this->hidden->stream =
NULL;
178 if (this->hidden->fs) {
179 this->hidden->fs->Release(this->hidden->fs);
180 this->hidden->fs =
NULL;
189 SDL_FS_OpenDevice(
_THIS,
const char *devname,
int iscapture)
193 FSSampleFormat fs_format;
194 FSStreamDescription desc;
200 if (this->hidden ==
NULL) {
203 SDL_memset(this->hidden, 0, (
sizeof *this->hidden));
207 !
format && test_format;) {
209 fprintf(stderr,
"Trying format 0x%4.4x\n", test_format);
211 switch (test_format) {
218 fs_format = FSSF_S16;
223 fs_format = FSSF_S32;
228 fs_format = FSSF_FLOAT;
242 SDL_FS_CloseDevice(
this);
243 return SDL_SetError(
"Couldn't find any hardware audio formats");
245 this->spec.format = test_format;
248 ret =
SDL_NAME(FusionSoundCreate) (&this->hidden->fs);
250 SDL_FS_CloseDevice(
this);
251 return SDL_SetError(
"Unable to initialize FusionSound: %d", ret);
254 this->hidden->mixsamples = this->spec.size / bytes / this->spec.channels;
257 desc.flags = FSSDF_SAMPLERATE | FSSDF_BUFFERSIZE |
258 FSSDF_CHANNELS | FSSDF_SAMPLEFORMAT | FSSDF_PREBUFFER;
259 desc.samplerate = this->spec.freq;
260 desc.buffersize = this->spec.size * FUSION_BUFFERS;
261 desc.channels = this->spec.channels;
263 desc.sampleformat = fs_format;
266 this->hidden->fs->CreateStream(this->hidden->fs, &desc,
267 &this->hidden->stream);
269 SDL_FS_CloseDevice(
this);
270 return SDL_SetError(
"Unable to create FusionSoundStream: %d", ret);
274 desc.flags = FSSDF_SAMPLERATE | FSSDF_BUFFERSIZE |
275 FSSDF_CHANNELS | FSSDF_SAMPLEFORMAT;
276 ret = this->hidden->stream->GetDescription(this->hidden->stream, &desc);
278 this->spec.freq = desc.samplerate;
280 desc.buffersize / FUSION_BUFFERS * bytes * desc.channels;
281 this->spec.channels = desc.channels;
287 this->hidden->mixlen = this->spec.size;
289 if (this->hidden->mixbuf ==
NULL) {
290 SDL_FS_CloseDevice(
this);
293 SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size);
301 SDL_FS_Deinitialize(
void)
303 UnloadFusionSoundLibrary();
310 if (LoadFusionSoundLibrary() < 0) {
317 UnloadFusionSoundLibrary();
319 (
"FusionSound: SDL_FS_init failed (FusionSoundInit: %d)",
340 "fusionsound",
"FusionSound", SDL_FS_Init, 0
void(* CloseDevice)(_THIS)
SDL_AudioFormat SDL_FirstAudioFormat(SDL_AudioFormat format)
void(* WaitDevice)(_THIS)
GLenum GLsizei const GLuint GLboolean enabled
Uint8 *(* GetDeviceBuf)(_THIS)
DECLSPEC void SDLCALL SDL_free(void *mem)
EGLImageKHR EGLint * name
Uint16 SDL_AudioFormat
Audio format flags.
int(* OpenDevice)(_THIS, const char *devname, int iscapture)
SDL_AudioFormat SDL_NextAudioFormat(void)
void(* PlayDevice)(_THIS)
int OnlyHasDefaultOutputDevice
DECLSPEC void *SDLCALL SDL_LoadObject(const char *sofile)
DECLSPEC void *SDLCALL SDL_memset(void *dst, int c, size_t len)
DECLSPEC void SDLCALL SDL_UnloadObject(void *handle)
GLint GLenum GLsizei GLsizei GLsizei GLint GLenum format
DECLSPEC int SDLCALL SDL_SetError(const char *fmt,...)
DECLSPEC void *SDLCALL SDL_malloc(size_t size)
void SDL_CalculateAudioSpec(SDL_AudioSpec *spec)
void(* Deinitialize)(void)
#define SDL_AllocAudioMem
#define SDL_OutOfMemory()
#define SDL_arraysize(array)
uint8_t Uint8
An unsigned 8-bit integer type.
DECLSPEC void *SDLCALL SDL_LoadFunction(void *handle, const char *name)
AudioBootStrap FUSIONSOUND_bootstrap