24 #if SDL_AUDIO_DRIVER_SNDIO
39 #include "../SDL_audiomem.h"
40 #include "../SDL_audio_c.h"
43 #ifdef SDL_AUDIO_DRIVER_SNDIO_DYNAMIC
47 static struct sio_hdl * (*SNDIO_sio_open)(
const char *,
unsigned int,
int);
48 static void (*SNDIO_sio_close)(
struct sio_hdl *);
49 static int (*SNDIO_sio_setpar)(
struct sio_hdl *,
struct sio_par *);
50 static int (*SNDIO_sio_getpar)(
struct sio_hdl *,
struct sio_par *);
51 static int (*SNDIO_sio_start)(
struct sio_hdl *);
52 static int (*SNDIO_sio_stop)(
struct sio_hdl *);
53 static size_t (*SNDIO_sio_read)(
struct sio_hdl *,
void *,
size_t);
54 static size_t (*SNDIO_sio_write)(
struct sio_hdl *,
const void *,
size_t);
55 static void (*SNDIO_sio_initpar)(
struct sio_par *);
57 #ifdef SDL_AUDIO_DRIVER_SNDIO_DYNAMIC
58 static const char *sndio_library = SDL_AUDIO_DRIVER_SNDIO_DYNAMIC;
59 static void *sndio_handle =
NULL;
62 load_sndio_sym(
const char *fn,
void **
addr)
74 #define SDL_SNDIO_SYM(x) \
75 if (!load_sndio_sym(#x, (void **) (char *) &SNDIO_##x)) return -1
77 #define SDL_SNDIO_SYM(x) SNDIO_##x = x
83 SDL_SNDIO_SYM(sio_open);
84 SDL_SNDIO_SYM(sio_close);
85 SDL_SNDIO_SYM(sio_setpar);
86 SDL_SNDIO_SYM(sio_getpar);
87 SDL_SNDIO_SYM(sio_start);
88 SDL_SNDIO_SYM(sio_stop);
89 SDL_SNDIO_SYM(sio_read);
90 SDL_SNDIO_SYM(sio_write);
91 SDL_SNDIO_SYM(sio_initpar);
97 #ifdef SDL_AUDIO_DRIVER_SNDIO_DYNAMIC
100 UnloadSNDIOLibrary(
void)
102 if (sndio_handle !=
NULL) {
109 LoadSNDIOLibrary(
void)
112 if (sndio_handle ==
NULL) {
114 if (sndio_handle ==
NULL) {
118 retval = load_sndio_syms();
120 UnloadSNDIOLibrary();
130 UnloadSNDIOLibrary(
void)
135 LoadSNDIOLibrary(
void)
147 SNDIO_WaitDevice(
_THIS)
153 SNDIO_PlayDevice(
_THIS)
155 const int written = SNDIO_sio_write(this->hidden->dev,
156 this->hidden->mixbuf,
157 this->hidden->mixlen);
160 if ( written == 0 ) {
164 fprintf(stderr,
"Wrote %d bytes of audio data\n", written);
169 SNDIO_GetDeviceBuf(
_THIS)
171 return this->hidden->mixbuf;
175 SNDIO_WaitDone(
_THIS)
177 SNDIO_sio_stop(this->hidden->dev);
181 SNDIO_CloseDevice(
_THIS)
183 if (this->hidden !=
NULL) {
185 this->hidden->mixbuf =
NULL;
186 if ( this->hidden->dev !=
NULL ) {
187 SNDIO_sio_close(this->hidden->dev);
188 this->hidden->dev =
NULL;
196 SNDIO_OpenDevice(
_THIS,
const char *devname,
int iscapture)
204 if (this->hidden ==
NULL) {
207 SDL_memset(this->hidden, 0,
sizeof(*this->hidden));
209 this->hidden->mixlen = this->spec.size;
212 if ((this->hidden->dev = SNDIO_sio_open(
NULL, SIO_PLAY, 0)) ==
NULL) {
213 SNDIO_CloseDevice(
this);
217 SNDIO_sio_initpar(&par);
219 par.rate = this->spec.freq;
220 par.pchan = this->spec.channels;
221 par.round = this->spec.samples;
222 par.appbufsz = par.round * 2;
226 while (test_format && (status < 0)) {
232 if (SNDIO_sio_setpar(this->hidden->dev, &par) == 1) {
241 SNDIO_CloseDevice(
this);
242 return SDL_SetError(
"sndio: Couldn't find any hardware audio formats");
245 if (SNDIO_sio_getpar(this->hidden->dev, &par) == 0) {
246 SNDIO_CloseDevice(
this);
250 if ((par.bits == 32) && (par.sig) && (par.le))
252 else if ((par.bits == 32) && (par.sig) && (!par.le))
254 else if ((par.bits == 16) && (par.sig) && (par.le))
256 else if ((par.bits == 16) && (par.sig) && (!par.le))
258 else if ((par.bits == 16) && (!par.sig) && (par.le))
260 else if ((par.bits == 16) && (!par.sig) && (!par.le))
262 else if ((par.bits == 8) && (par.sig))
264 else if ((par.bits == 8) && (!par.sig))
267 SNDIO_CloseDevice(
this);
268 return SDL_SetError(
"sndio: Got unsupported hardware audio format.");
271 this->spec.freq = par.rate;
272 this->spec.channels = par.pchan;
273 this->spec.samples = par.round;
279 this->hidden->mixlen = this->spec.size;
281 if (this->hidden->mixbuf ==
NULL) {
282 SNDIO_CloseDevice(
this);
285 SDL_memset(this->hidden->mixbuf, this->spec.silence, this->hidden->mixlen);
287 if (!SNDIO_sio_start(this->hidden->dev)) {
296 SNDIO_Deinitialize(
void)
298 UnloadSNDIOLibrary();
304 if (LoadSNDIOLibrary() < 0) {
322 "sndio",
"OpenBSD sndio", SNDIO_Init, 0
void(* CloseDevice)(_THIS)
#define SDL_AUDIO_ISLITTLEENDIAN(x)
SDL_AudioFormat SDL_FirstAudioFormat(SDL_AudioFormat format)
GLvoid **typedef void(GLAPIENTRY *PFNGLGETVERTEXATTRIBDVPROC)(GLuint
void(* WaitDevice)(_THIS)
GLenum GLsizei const GLuint GLboolean enabled
Uint8 *(* GetDeviceBuf)(_THIS)
DECLSPEC void SDLCALL SDL_free(void *mem)
#define SDL_AUDIO_ISSIGNED(x)
Uint16 SDL_AudioFormat
Audio format flags.
int(* OpenDevice)(_THIS, const char *devname, int iscapture)
SDL_AudioFormat SDL_NextAudioFormat(void)
#define SDL_AUDIO_ISFLOAT(x)
void(* PlayDevice)(_THIS)
int OnlyHasDefaultOutputDevice
DECLSPEC void *SDLCALL SDL_LoadObject(const char *sofile)
#define SDL_AUDIO_BITSIZE(x)
DECLSPEC void *SDLCALL SDL_memset(void *dst, int c, size_t len)
DECLSPEC void SDLCALL SDL_UnloadObject(void *handle)
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()
uint8_t Uint8
An unsigned 8-bit integer type.
DECLSPEC void *SDLCALL SDL_LoadFunction(void *handle, const char *name)
AudioBootStrap SNDIO_bootstrap