xref: /qemu/audio/sdlaudio.c (revision 6086a565b0efe3eb66c5bf65a715a2c84425e47f)
185571bc7Sbellard /*
21d14ffa9Sbellard  * QEMU SDL audio driver
385571bc7Sbellard  *
41d14ffa9Sbellard  * Copyright (c) 2004-2005 Vassili Karpov (malc)
585571bc7Sbellard  *
685571bc7Sbellard  * Permission is hereby granted, free of charge, to any person obtaining a copy
785571bc7Sbellard  * of this software and associated documentation files (the "Software"), to deal
885571bc7Sbellard  * in the Software without restriction, including without limitation the rights
985571bc7Sbellard  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1085571bc7Sbellard  * copies of the Software, and to permit persons to whom the Software is
1185571bc7Sbellard  * furnished to do so, subject to the following conditions:
1285571bc7Sbellard  *
1385571bc7Sbellard  * The above copyright notice and this permission notice shall be included in
1485571bc7Sbellard  * all copies or substantial portions of the Software.
1585571bc7Sbellard  *
1685571bc7Sbellard  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1785571bc7Sbellard  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1885571bc7Sbellard  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
1985571bc7Sbellard  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2085571bc7Sbellard  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2185571bc7Sbellard  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2285571bc7Sbellard  * THE SOFTWARE.
2385571bc7Sbellard  */
24*6086a565SPeter Maydell #include "qemu/osdep.h"
259f059ecaSbellard #include <SDL.h>
269f059ecaSbellard #include <SDL_thread.h>
2787ecb68bSpbrook #include "qemu-common.h"
2887ecb68bSpbrook #include "audio.h"
2985571bc7Sbellard 
30e784ba70Sths #ifndef _WIN32
31e784ba70Sths #ifdef __sun__
32e784ba70Sths #define _POSIX_PTHREAD_SEMANTICS 1
33c5e97233Sblueswir1 #elif defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__DragonFly__)
349b4c14c3Sblueswir1 #include <pthread.h>
35e784ba70Sths #endif
36e784ba70Sths #endif
37e784ba70Sths 
381d14ffa9Sbellard #define AUDIO_CAP "sdl"
391d14ffa9Sbellard #include "audio_int.h"
40fb065187Sbellard 
411d14ffa9Sbellard typedef struct SDLVoiceOut {
421d14ffa9Sbellard     HWVoiceOut hw;
431d14ffa9Sbellard     int live;
44ff541499Smalc     int rpos;
451d14ffa9Sbellard     int decr;
461d14ffa9Sbellard } SDLVoiceOut;
4785571bc7Sbellard 
4885571bc7Sbellard static struct {
4985571bc7Sbellard     int nb_samples;
5085571bc7Sbellard } conf = {
511a40d5e2SJuan Quintela     .nb_samples = 1024
5285571bc7Sbellard };
5385571bc7Sbellard 
54b1d8e52eSblueswir1 static struct SDLAudioState {
5585571bc7Sbellard     int exit;
5685571bc7Sbellard     SDL_mutex *mutex;
5785571bc7Sbellard     SDL_sem *sem;
5885571bc7Sbellard     int initialized;
5981ebb07cSKővágó, Zoltán     bool driver_created;
6085571bc7Sbellard } glob_sdl;
6185571bc7Sbellard typedef struct SDLAudioState SDLAudioState;
6285571bc7Sbellard 
631d14ffa9Sbellard static void GCC_FMT_ATTR (1, 2) sdl_logerr (const char *fmt, ...)
6485571bc7Sbellard {
651d14ffa9Sbellard     va_list ap;
661d14ffa9Sbellard 
671d14ffa9Sbellard     va_start (ap, fmt);
681d14ffa9Sbellard     AUD_vlog (AUDIO_CAP, fmt, ap);
691d14ffa9Sbellard     va_end (ap);
701d14ffa9Sbellard 
711d14ffa9Sbellard     AUD_log (AUDIO_CAP, "Reason: %s\n", SDL_GetError ());
7285571bc7Sbellard }
7385571bc7Sbellard 
741d14ffa9Sbellard static int sdl_lock (SDLAudioState *s, const char *forfn)
7585571bc7Sbellard {
7685571bc7Sbellard     if (SDL_LockMutex (s->mutex)) {
771d14ffa9Sbellard         sdl_logerr ("SDL_LockMutex for %s failed\n", forfn);
7885571bc7Sbellard         return -1;
7985571bc7Sbellard     }
8085571bc7Sbellard     return 0;
8185571bc7Sbellard }
8285571bc7Sbellard 
831d14ffa9Sbellard static int sdl_unlock (SDLAudioState *s, const char *forfn)
8485571bc7Sbellard {
8585571bc7Sbellard     if (SDL_UnlockMutex (s->mutex)) {
861d14ffa9Sbellard         sdl_logerr ("SDL_UnlockMutex for %s failed\n", forfn);
8785571bc7Sbellard         return -1;
8885571bc7Sbellard     }
8985571bc7Sbellard     return 0;
9085571bc7Sbellard }
9185571bc7Sbellard 
921d14ffa9Sbellard static int sdl_post (SDLAudioState *s, const char *forfn)
9385571bc7Sbellard {
9485571bc7Sbellard     if (SDL_SemPost (s->sem)) {
951d14ffa9Sbellard         sdl_logerr ("SDL_SemPost for %s failed\n", forfn);
9685571bc7Sbellard         return -1;
9785571bc7Sbellard     }
9885571bc7Sbellard     return 0;
9985571bc7Sbellard }
10085571bc7Sbellard 
1011d14ffa9Sbellard static int sdl_wait (SDLAudioState *s, const char *forfn)
10285571bc7Sbellard {
10385571bc7Sbellard     if (SDL_SemWait (s->sem)) {
1041d14ffa9Sbellard         sdl_logerr ("SDL_SemWait for %s failed\n", forfn);
10585571bc7Sbellard         return -1;
10685571bc7Sbellard     }
10785571bc7Sbellard     return 0;
10885571bc7Sbellard }
10985571bc7Sbellard 
1101d14ffa9Sbellard static int sdl_unlock_and_post (SDLAudioState *s, const char *forfn)
11185571bc7Sbellard {
1121d14ffa9Sbellard     if (sdl_unlock (s, forfn)) {
11385571bc7Sbellard         return -1;
11485571bc7Sbellard     }
11585571bc7Sbellard 
1161d14ffa9Sbellard     return sdl_post (s, forfn);
11785571bc7Sbellard }
11885571bc7Sbellard 
1196c557ab9SSerge Ziryukin static int aud_to_sdlfmt (audfmt_e fmt)
12085571bc7Sbellard {
1211d14ffa9Sbellard     switch (fmt) {
1221d14ffa9Sbellard     case AUD_FMT_S8:
1231d14ffa9Sbellard         return AUDIO_S8;
1241d14ffa9Sbellard 
1251d14ffa9Sbellard     case AUD_FMT_U8:
1261d14ffa9Sbellard         return AUDIO_U8;
1271d14ffa9Sbellard 
1281d14ffa9Sbellard     case AUD_FMT_S16:
1291d14ffa9Sbellard         return AUDIO_S16LSB;
1301d14ffa9Sbellard 
1311d14ffa9Sbellard     case AUD_FMT_U16:
1321d14ffa9Sbellard         return AUDIO_U16LSB;
1331d14ffa9Sbellard 
13485571bc7Sbellard     default:
1351d14ffa9Sbellard         dolog ("Internal logic error: Bad audio format %d\n", fmt);
1361d14ffa9Sbellard #ifdef DEBUG_AUDIO
1371d14ffa9Sbellard         abort ();
1381d14ffa9Sbellard #endif
1391d14ffa9Sbellard         return AUDIO_U8;
14085571bc7Sbellard     }
14185571bc7Sbellard }
14285571bc7Sbellard 
1434ff9786cSStefan Weil static int sdl_to_audfmt(int sdlfmt, audfmt_e *fmt, int *endianness)
14485571bc7Sbellard {
1451d14ffa9Sbellard     switch (sdlfmt) {
1461d14ffa9Sbellard     case AUDIO_S8:
1474ff9786cSStefan Weil         *endianness = 0;
1481d14ffa9Sbellard         *fmt = AUD_FMT_S8;
1491d14ffa9Sbellard         break;
1501d14ffa9Sbellard 
1511d14ffa9Sbellard     case AUDIO_U8:
1524ff9786cSStefan Weil         *endianness = 0;
1531d14ffa9Sbellard         *fmt = AUD_FMT_U8;
1541d14ffa9Sbellard         break;
1551d14ffa9Sbellard 
1561d14ffa9Sbellard     case AUDIO_S16LSB:
1574ff9786cSStefan Weil         *endianness = 0;
1581d14ffa9Sbellard         *fmt = AUD_FMT_S16;
1591d14ffa9Sbellard         break;
1601d14ffa9Sbellard 
1611d14ffa9Sbellard     case AUDIO_U16LSB:
1624ff9786cSStefan Weil         *endianness = 0;
1631d14ffa9Sbellard         *fmt = AUD_FMT_U16;
1641d14ffa9Sbellard         break;
1651d14ffa9Sbellard 
1661d14ffa9Sbellard     case AUDIO_S16MSB:
1674ff9786cSStefan Weil         *endianness = 1;
1681d14ffa9Sbellard         *fmt = AUD_FMT_S16;
1691d14ffa9Sbellard         break;
1701d14ffa9Sbellard 
1711d14ffa9Sbellard     case AUDIO_U16MSB:
1724ff9786cSStefan Weil         *endianness = 1;
1731d14ffa9Sbellard         *fmt = AUD_FMT_U16;
1741d14ffa9Sbellard         break;
1751d14ffa9Sbellard 
17685571bc7Sbellard     default:
1771d14ffa9Sbellard         dolog ("Unrecognized SDL audio format %d\n", sdlfmt);
1781d14ffa9Sbellard         return -1;
17985571bc7Sbellard     }
1801d14ffa9Sbellard 
1811d14ffa9Sbellard     return 0;
18285571bc7Sbellard }
18385571bc7Sbellard 
18485571bc7Sbellard static int sdl_open (SDL_AudioSpec *req, SDL_AudioSpec *obt)
18585571bc7Sbellard {
18685571bc7Sbellard     int status;
187e784ba70Sths #ifndef _WIN32
188d087bb3eSmalc     int err;
189e784ba70Sths     sigset_t new, old;
190e784ba70Sths 
191e784ba70Sths     /* Make sure potential threads created by SDL don't hog signals.  */
192d087bb3eSmalc     err = sigfillset (&new);
193d087bb3eSmalc     if (err) {
194d087bb3eSmalc         dolog ("sdl_open: sigfillset failed: %s\n", strerror (errno));
19560592eddSmalc         return -1;
196d087bb3eSmalc     }
197d087bb3eSmalc     err = pthread_sigmask (SIG_BLOCK, &new, &old);
198d087bb3eSmalc     if (err) {
199d087bb3eSmalc         dolog ("sdl_open: pthread_sigmask failed: %s\n", strerror (err));
200d087bb3eSmalc         return -1;
201d087bb3eSmalc     }
202e784ba70Sths #endif
20385571bc7Sbellard 
20485571bc7Sbellard     status = SDL_OpenAudio (req, obt);
20585571bc7Sbellard     if (status) {
2061d14ffa9Sbellard         sdl_logerr ("SDL_OpenAudio failed\n");
20785571bc7Sbellard     }
208e784ba70Sths 
209e784ba70Sths #ifndef _WIN32
210d087bb3eSmalc     err = pthread_sigmask (SIG_SETMASK, &old, NULL);
211d087bb3eSmalc     if (err) {
212d087bb3eSmalc         dolog ("sdl_open: pthread_sigmask (restore) failed: %s\n",
213d087bb3eSmalc                strerror (errno));
214d087bb3eSmalc         /* We have failed to restore original signal mask, all bets are off,
215d087bb3eSmalc            so exit the process */
216d087bb3eSmalc         exit (EXIT_FAILURE);
217d087bb3eSmalc     }
218e784ba70Sths #endif
21985571bc7Sbellard     return status;
22085571bc7Sbellard }
22185571bc7Sbellard 
22285571bc7Sbellard static void sdl_close (SDLAudioState *s)
22385571bc7Sbellard {
22485571bc7Sbellard     if (s->initialized) {
2251d14ffa9Sbellard         sdl_lock (s, "sdl_close");
22685571bc7Sbellard         s->exit = 1;
2271d14ffa9Sbellard         sdl_unlock_and_post (s, "sdl_close");
22885571bc7Sbellard         SDL_PauseAudio (1);
22985571bc7Sbellard         SDL_CloseAudio ();
23085571bc7Sbellard         s->initialized = 0;
23185571bc7Sbellard     }
23285571bc7Sbellard }
23385571bc7Sbellard 
23485571bc7Sbellard static void sdl_callback (void *opaque, Uint8 *buf, int len)
23585571bc7Sbellard {
2361d14ffa9Sbellard     SDLVoiceOut *sdl = opaque;
23785571bc7Sbellard     SDLAudioState *s = &glob_sdl;
2381d14ffa9Sbellard     HWVoiceOut *hw = &sdl->hw;
2391d14ffa9Sbellard     int samples = len >> hw->info.shift;
24085571bc7Sbellard 
24185571bc7Sbellard     if (s->exit) {
24285571bc7Sbellard         return;
24385571bc7Sbellard     }
24485571bc7Sbellard 
24585571bc7Sbellard     while (samples) {
2461d14ffa9Sbellard         int to_mix, decr;
24785571bc7Sbellard 
248ff541499Smalc         /* dolog ("in callback samples=%d\n", samples); */
2491d14ffa9Sbellard         sdl_wait (s, "sdl_callback");
25085571bc7Sbellard         if (s->exit) {
25185571bc7Sbellard             return;
25285571bc7Sbellard         }
25385571bc7Sbellard 
2541d14ffa9Sbellard         if (sdl_lock (s, "sdl_callback")) {
2551d14ffa9Sbellard             return;
2561d14ffa9Sbellard         }
257ff541499Smalc 
258ff541499Smalc         if (audio_bug (AUDIO_FUNC, sdl->live < 0 || sdl->live > hw->samples)) {
259ff541499Smalc             dolog ("sdl->live=%d hw->samples=%d\n",
260ff541499Smalc                    sdl->live, hw->samples);
261ff541499Smalc             return;
2621d14ffa9Sbellard         }
2631d14ffa9Sbellard 
264ff541499Smalc         if (!sdl->live) {
265ff541499Smalc             goto again;
266ff541499Smalc         }
267ff541499Smalc 
268ff541499Smalc         /* dolog ("in callback live=%d\n", live); */
269ff541499Smalc         to_mix = audio_MIN (samples, sdl->live);
270ff541499Smalc         decr = to_mix;
271ff541499Smalc         while (to_mix) {
272ff541499Smalc             int chunk = audio_MIN (to_mix, hw->samples - hw->rpos);
273ff541499Smalc             struct st_sample *src = hw->mix_buf + hw->rpos;
274ff541499Smalc 
275ff541499Smalc             /* dolog ("in callback to_mix %d, chunk %d\n", to_mix, chunk); */
276ff541499Smalc             hw->clip (buf, src, chunk);
277ff541499Smalc             sdl->rpos = (sdl->rpos + chunk) % hw->samples;
278ff541499Smalc             to_mix -= chunk;
279ff541499Smalc             buf += chunk << hw->info.shift;
280ff541499Smalc         }
28185571bc7Sbellard         samples -= decr;
282ff541499Smalc         sdl->live -= decr;
2831d14ffa9Sbellard         sdl->decr += decr;
28485571bc7Sbellard 
285ff541499Smalc     again:
2861d14ffa9Sbellard         if (sdl_unlock (s, "sdl_callback")) {
2871d14ffa9Sbellard             return;
2881d14ffa9Sbellard         }
28985571bc7Sbellard     }
290ff541499Smalc     /* dolog ("done len=%d\n", len); */
291ff541499Smalc }
29285571bc7Sbellard 
2931d14ffa9Sbellard static int sdl_write_out (SWVoiceOut *sw, void *buf, int len)
29485571bc7Sbellard {
2951d14ffa9Sbellard     return audio_pcm_sw_write (sw, buf, len);
2961d14ffa9Sbellard }
2971d14ffa9Sbellard 
298bdff253cSmalc static int sdl_run_out (HWVoiceOut *hw, int live)
2991d14ffa9Sbellard {
300bdff253cSmalc     int decr;
3011d14ffa9Sbellard     SDLVoiceOut *sdl = (SDLVoiceOut *) hw;
3021d14ffa9Sbellard     SDLAudioState *s = &glob_sdl;
3031d14ffa9Sbellard 
3043fd7f635Smalc     if (sdl_lock (s, "sdl_run_out")) {
3051d14ffa9Sbellard         return 0;
3061d14ffa9Sbellard     }
3071d14ffa9Sbellard 
308ff541499Smalc     if (sdl->decr > live) {
309ff541499Smalc         ldebug ("sdl->decr %d live %d sdl->live %d\n",
310ff541499Smalc                 sdl->decr,
311ff541499Smalc                 live,
312ff541499Smalc                 sdl->live);
313ff541499Smalc     }
314ff541499Smalc 
315ff541499Smalc     decr = audio_MIN (sdl->decr, live);
316ff541499Smalc     sdl->decr -= decr;
317ff541499Smalc 
318ff541499Smalc     sdl->live = live - decr;
319ff541499Smalc     hw->rpos = sdl->rpos;
3201d14ffa9Sbellard 
3211d14ffa9Sbellard     if (sdl->live > 0) {
3223fd7f635Smalc         sdl_unlock_and_post (s, "sdl_run_out");
3231d14ffa9Sbellard     }
3241d14ffa9Sbellard     else {
3253fd7f635Smalc         sdl_unlock (s, "sdl_run_out");
3261d14ffa9Sbellard     }
3271d14ffa9Sbellard     return decr;
3281d14ffa9Sbellard }
3291d14ffa9Sbellard 
3301d14ffa9Sbellard static void sdl_fini_out (HWVoiceOut *hw)
3311d14ffa9Sbellard {
3321d14ffa9Sbellard     (void) hw;
3331d14ffa9Sbellard 
33485571bc7Sbellard     sdl_close (&glob_sdl);
33585571bc7Sbellard }
33685571bc7Sbellard 
3375706db1dSKővágó, Zoltán static int sdl_init_out(HWVoiceOut *hw, struct audsettings *as,
3385706db1dSKővágó, Zoltán                         void *drv_opaque)
33985571bc7Sbellard {
3401d14ffa9Sbellard     SDLVoiceOut *sdl = (SDLVoiceOut *) hw;
34185571bc7Sbellard     SDLAudioState *s = &glob_sdl;
34285571bc7Sbellard     SDL_AudioSpec req, obt;
3434ff9786cSStefan Weil     int endianness;
3441d14ffa9Sbellard     int err;
3451d14ffa9Sbellard     audfmt_e effective_fmt;
3461ea879e5Smalc     struct audsettings obt_as;
34785571bc7Sbellard 
348c0fe3827Sbellard     req.freq = as->freq;
3496c557ab9SSerge Ziryukin     req.format = aud_to_sdlfmt (as->fmt);
350c0fe3827Sbellard     req.channels = as->nchannels;
35185571bc7Sbellard     req.samples = conf.nb_samples;
35285571bc7Sbellard     req.callback = sdl_callback;
35385571bc7Sbellard     req.userdata = sdl;
35485571bc7Sbellard 
3551d14ffa9Sbellard     if (sdl_open (&req, &obt)) {
35685571bc7Sbellard         return -1;
3571d14ffa9Sbellard     }
35885571bc7Sbellard 
3594ff9786cSStefan Weil     err = sdl_to_audfmt(obt.format, &effective_fmt, &endianness);
3601d14ffa9Sbellard     if (err) {
3611d14ffa9Sbellard         sdl_close (s);
3621d14ffa9Sbellard         return -1;
3631d14ffa9Sbellard     }
3641d14ffa9Sbellard 
365c0fe3827Sbellard     obt_as.freq = obt.freq;
366c0fe3827Sbellard     obt_as.nchannels = obt.channels;
367c0fe3827Sbellard     obt_as.fmt = effective_fmt;
3684ff9786cSStefan Weil     obt_as.endianness = endianness;
369c0fe3827Sbellard 
370d929eba5Sbellard     audio_pcm_init_info (&hw->info, &obt_as);
371c0fe3827Sbellard     hw->samples = obt.samples;
37285571bc7Sbellard 
37385571bc7Sbellard     s->initialized = 1;
37485571bc7Sbellard     s->exit = 0;
37585571bc7Sbellard     SDL_PauseAudio (0);
37685571bc7Sbellard     return 0;
37785571bc7Sbellard }
37885571bc7Sbellard 
3791d14ffa9Sbellard static int sdl_ctl_out (HWVoiceOut *hw, int cmd, ...)
38085571bc7Sbellard {
38185571bc7Sbellard     (void) hw;
38285571bc7Sbellard 
38385571bc7Sbellard     switch (cmd) {
38485571bc7Sbellard     case VOICE_ENABLE:
38585571bc7Sbellard         SDL_PauseAudio (0);
38685571bc7Sbellard         break;
38785571bc7Sbellard 
38885571bc7Sbellard     case VOICE_DISABLE:
38985571bc7Sbellard         SDL_PauseAudio (1);
39085571bc7Sbellard         break;
39185571bc7Sbellard     }
39285571bc7Sbellard     return 0;
39385571bc7Sbellard }
39485571bc7Sbellard 
39585571bc7Sbellard static void *sdl_audio_init (void)
39685571bc7Sbellard {
39785571bc7Sbellard     SDLAudioState *s = &glob_sdl;
39881ebb07cSKővágó, Zoltán     if (s->driver_created) {
39981ebb07cSKővágó, Zoltán         sdl_logerr("Can't create multiple sdl backends\n");
40081ebb07cSKővágó, Zoltán         return NULL;
40181ebb07cSKővágó, Zoltán     }
40285571bc7Sbellard 
40385571bc7Sbellard     if (SDL_InitSubSystem (SDL_INIT_AUDIO)) {
4041d14ffa9Sbellard         sdl_logerr ("SDL failed to initialize audio subsystem\n");
40585571bc7Sbellard         return NULL;
40685571bc7Sbellard     }
40785571bc7Sbellard 
40885571bc7Sbellard     s->mutex = SDL_CreateMutex ();
40985571bc7Sbellard     if (!s->mutex) {
4101d14ffa9Sbellard         sdl_logerr ("Failed to create SDL mutex\n");
41185571bc7Sbellard         SDL_QuitSubSystem (SDL_INIT_AUDIO);
41285571bc7Sbellard         return NULL;
41385571bc7Sbellard     }
41485571bc7Sbellard 
41585571bc7Sbellard     s->sem = SDL_CreateSemaphore (0);
41685571bc7Sbellard     if (!s->sem) {
4171d14ffa9Sbellard         sdl_logerr ("Failed to create SDL semaphore\n");
41885571bc7Sbellard         SDL_DestroyMutex (s->mutex);
41985571bc7Sbellard         SDL_QuitSubSystem (SDL_INIT_AUDIO);
42085571bc7Sbellard         return NULL;
42185571bc7Sbellard     }
42285571bc7Sbellard 
42381ebb07cSKővágó, Zoltán     s->driver_created = true;
42485571bc7Sbellard     return s;
42585571bc7Sbellard }
42685571bc7Sbellard 
42785571bc7Sbellard static void sdl_audio_fini (void *opaque)
42885571bc7Sbellard {
42985571bc7Sbellard     SDLAudioState *s = opaque;
43085571bc7Sbellard     sdl_close (s);
43185571bc7Sbellard     SDL_DestroySemaphore (s->sem);
43285571bc7Sbellard     SDL_DestroyMutex (s->mutex);
43385571bc7Sbellard     SDL_QuitSubSystem (SDL_INIT_AUDIO);
43481ebb07cSKővágó, Zoltán     s->driver_created = false;
43585571bc7Sbellard }
43685571bc7Sbellard 
4371d14ffa9Sbellard static struct audio_option sdl_options[] = {
43898f9f48cSmalc     {
43998f9f48cSmalc         .name  = "SAMPLES",
4402700efa3SJuan Quintela         .tag   = AUD_OPT_INT,
4412700efa3SJuan Quintela         .valp  = &conf.nb_samples,
44298f9f48cSmalc         .descr = "Size of SDL buffer in samples"
44398f9f48cSmalc     },
4442700efa3SJuan Quintela     { /* End of list */ }
44585571bc7Sbellard };
44685571bc7Sbellard 
44735f4b58cSblueswir1 static struct audio_pcm_ops sdl_pcm_ops = {
4481dd3e4d1SJuan Quintela     .init_out = sdl_init_out,
4491dd3e4d1SJuan Quintela     .fini_out = sdl_fini_out,
4501dd3e4d1SJuan Quintela     .run_out  = sdl_run_out,
4511dd3e4d1SJuan Quintela     .write    = sdl_write_out,
4521dd3e4d1SJuan Quintela     .ctl_out  = sdl_ctl_out,
4531d14ffa9Sbellard };
4541d14ffa9Sbellard 
4551d14ffa9Sbellard struct audio_driver sdl_audio_driver = {
456bee37f32SJuan Quintela     .name           = "sdl",
457bee37f32SJuan Quintela     .descr          = "SDL http://www.libsdl.org",
458bee37f32SJuan Quintela     .options        = sdl_options,
459bee37f32SJuan Quintela     .init           = sdl_audio_init,
460bee37f32SJuan Quintela     .fini           = sdl_audio_fini,
461bee37f32SJuan Quintela     .pcm_ops        = &sdl_pcm_ops,
462bee37f32SJuan Quintela     .can_be_default = 1,
463bee37f32SJuan Quintela     .max_voices_out = 1,
464bee37f32SJuan Quintela     .max_voices_in  = 0,
465bee37f32SJuan Quintela     .voice_size_out = sizeof (SDLVoiceOut),
466bee37f32SJuan Quintela     .voice_size_in  = 0
46785571bc7Sbellard };
468