annotate src/audio/alsa/SDL_alsa_audio.c @ 3833:de857f0708f5 SDL-ryan-multiple-audio-device

Whoops, changed that symbol name...
author Ryan C. Gordon <icculus@icculus.org>
date Sat, 07 Oct 2006 20:23:02 +0000
parents 25052dd25810
children ee5dfa7f7993
rev   line source
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1 /*
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2 SDL - Simple DirectMedia Layer
769
b8d311d90021 Updated copyright information for 2004 (Happy New Year!)
Sam Lantinga <slouken@libsdl.org>
parents: 765
diff changeset
3 Copyright (C) 1997-2004 Sam Lantinga
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
4
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
5 This library is free software; you can redistribute it and/or
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
6 modify it under the terms of the GNU Library General Public
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
8 version 2 of the License, or (at your option) any later version.
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
9
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
13 Library General Public License for more details.
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
14
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
15 You should have received a copy of the GNU Library General Public
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
16 License along with this library; if not, write to the Free
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
18
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
19 Sam Lantinga
252
e8157fcb3114 Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents: 0
diff changeset
20 slouken@libsdl.org
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
21 */
1402
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1379
diff changeset
22 #include "SDL_config.h"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
23
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
24 /* Allow access to a raw mixing buffer */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
25
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
26 #include <sys/types.h>
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
27 #include <signal.h> /* For kill() */
3818
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
28 #include <dlfcn.h>
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
29 #include <errno.h>
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
30 #include <string.h>
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
31
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
32 #include "SDL_timer.h"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
33 #include "SDL_audio.h"
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
34 #include "../SDL_audiomem.h"
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
35 #include "../SDL_audio_c.h"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
36 #include "SDL_alsa_audio.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
37
865
92615154bb68 Date: Sun, 29 Feb 2004 15:14:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
38
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
39 /* The tag name used by ALSA audio */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
40 #define DRIVER_NAME "alsa"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
41
354
30935e76acb5 Updated ALSA audio support for ALSA 0.9
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
42 /* The default ALSA audio driver */
765
4c2ba6161939 Editors Note: The original patch was modified to use SDL_Delay() instead of
Sam Lantinga <slouken@libsdl.org>
parents: 547
diff changeset
43 #define DEFAULT_DEVICE "default"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
44
3818
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
45 static int (*ALSA_snd_pcm_open)
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
46 (snd_pcm_t **, const char *, snd_pcm_stream_t, int);
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
47 static int (*ALSA_snd_pcm_close)(snd_pcm_t * pcm);
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
48 static snd_pcm_sframes_t(*ALSA_snd_pcm_writei)
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
49 (snd_pcm_t *,const void *, snd_pcm_uframes_t);
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
50 static int (*ALSA_snd_pcm_resume)(snd_pcm_t *);
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
51 static int (*ALSA_snd_pcm_prepare)(snd_pcm_t *);
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
52 static int (*ALSA_snd_pcm_drain)(snd_pcm_t *);
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
53 static const char *(*ALSA_snd_strerror)(int);
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
54 static size_t(*ALSA_snd_pcm_hw_params_sizeof)(void);
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
55 static size_t(*ALSA_snd_pcm_sw_params_sizeof)(void);
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
56 static int (*ALSA_snd_pcm_hw_params_any)(snd_pcm_t *, snd_pcm_hw_params_t *);
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
57 static int (*ALSA_snd_pcm_hw_params_set_access)
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
58 (snd_pcm_t *, snd_pcm_hw_params_t *, snd_pcm_access_t);
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
59 static int (*ALSA_snd_pcm_hw_params_set_format)
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
60 (snd_pcm_t *, snd_pcm_hw_params_t *, snd_pcm_format_t);
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
61 static int (*ALSA_snd_pcm_hw_params_set_channels)
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
62 (snd_pcm_t *, snd_pcm_hw_params_t *, unsigned int);
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
63 static int (*ALSA_snd_pcm_hw_params_get_channels)(const snd_pcm_hw_params_t *);
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
64 static unsigned int (*ALSA_snd_pcm_hw_params_set_rate_near)
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
65 (snd_pcm_t *, snd_pcm_hw_params_t *, unsigned int, int *);
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
66 static snd_pcm_uframes_t (*ALSA_snd_pcm_hw_params_set_period_size_near)
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
67 (snd_pcm_t *, snd_pcm_hw_params_t *, snd_pcm_uframes_t, int *);
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
68 static snd_pcm_sframes_t (*ALSA_snd_pcm_hw_params_get_period_size)
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
69 (const snd_pcm_hw_params_t *);
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
70 static unsigned int (*ALSA_snd_pcm_hw_params_set_periods_near)
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
71 (snd_pcm_t *,snd_pcm_hw_params_t *, unsigned int, int *);
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
72 static int (*ALSA_snd_pcm_hw_params_get_periods)(snd_pcm_hw_params_t *);
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
73 static int (*ALSA_snd_pcm_hw_params)(snd_pcm_t *, snd_pcm_hw_params_t *);
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
74 static int (*ALSA_snd_pcm_sw_params_current)(snd_pcm_t*, snd_pcm_sw_params_t*);
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
75 static int (*ALSA_snd_pcm_sw_params_set_start_threshold)
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
76 (snd_pcm_t *, snd_pcm_sw_params_t *, snd_pcm_uframes_t);
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
77 static int (*ALSA_snd_pcm_sw_params_set_avail_min)
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
78 (snd_pcm_t *, snd_pcm_sw_params_t *, snd_pcm_uframes_t);
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
79 static int (*ALSA_snd_pcm_sw_params)(snd_pcm_t *, snd_pcm_sw_params_t *);
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
80 static int (*ALSA_snd_pcm_nonblock)(snd_pcm_t *, int);
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
81 #define snd_pcm_hw_params_sizeof ALSA_snd_pcm_hw_params_sizeof
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
82 #define snd_pcm_sw_params_sizeof ALSA_snd_pcm_sw_params_sizeof
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
83
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
84
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
85 #ifdef SDL_AUDIO_DRIVER_ALSA_DYNAMIC
865
92615154bb68 Date: Sun, 29 Feb 2004 15:14:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
86
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
87 static const char *alsa_library = SDL_AUDIO_DRIVER_ALSA_DYNAMIC;
865
92615154bb68 Date: Sun, 29 Feb 2004 15:14:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
88 static void *alsa_handle = NULL;
92615154bb68 Date: Sun, 29 Feb 2004 15:14:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
89
3818
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
90 static int
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
91 load_alsa_sym(const char *fn, void **addr)
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
92 {
3824
25052dd25810 Minor ALSA dynamic loading fix.
Ryan C. Gordon <icculus@icculus.org>
parents: 3819
diff changeset
93 /*
25052dd25810 Minor ALSA dynamic loading fix.
Ryan C. Gordon <icculus@icculus.org>
parents: 3819
diff changeset
94 * !!! FIXME:
25052dd25810 Minor ALSA dynamic loading fix.
Ryan C. Gordon <icculus@icculus.org>
parents: 3819
diff changeset
95 * Eventually, this will deal with fallbacks, version changes, and
25052dd25810 Minor ALSA dynamic loading fix.
Ryan C. Gordon <icculus@icculus.org>
parents: 3819
diff changeset
96 * missing symbols we can workaround. But for now, it doesn't.
25052dd25810 Minor ALSA dynamic loading fix.
Ryan C. Gordon <icculus@icculus.org>
parents: 3819
diff changeset
97 */
25052dd25810 Minor ALSA dynamic loading fix.
Ryan C. Gordon <icculus@icculus.org>
parents: 3819
diff changeset
98
3818
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
99 #if HAVE_DLVSYM
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
100 *addr = dlvsym(alsa_handle, fn, "ALSA_0.9");
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
101 if (*addr == NULL)
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
102 #endif
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
103 {
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
104 *addr = dlsym(alsa_handle, fn);
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
105 if (*addr == NULL) {
3824
25052dd25810 Minor ALSA dynamic loading fix.
Ryan C. Gordon <icculus@icculus.org>
parents: 3819
diff changeset
106 SDL_SetError("dlsym('%s') failed: %s", fn, strerror(errno));
3818
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
107 return 0;
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
108 }
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
109 }
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
110
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
111 return 1;
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
112 }
865
92615154bb68 Date: Sun, 29 Feb 2004 15:14:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
113
1161
05d4b93b911e Placate gcc's strict aliasing rules with an extra cast.
Ryan C. Gordon <icculus@icculus.org>
parents: 942
diff changeset
114 /* cast funcs to char* first, to please GCC's strict aliasing rules. */
3818
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
115 #define SDL_ALSA_SYM(x) \
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
116 if (!load_alsa_sym(#x, (void **) (char *) &ALSA_##x)) return -1
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
117 #else
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
118 #define SDL_ALSA_SYM(x) ALSA_##x = x
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
119 #endif
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
120
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
121 static int load_alsa_syms(void)
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
122 {
3818
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
123 SDL_ALSA_SYM(snd_pcm_open);
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
124 SDL_ALSA_SYM(snd_pcm_close);
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
125 SDL_ALSA_SYM(snd_pcm_writei);
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
126 SDL_ALSA_SYM(snd_pcm_resume);
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
127 SDL_ALSA_SYM(snd_pcm_prepare);
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
128 SDL_ALSA_SYM(snd_pcm_drain);
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
129 SDL_ALSA_SYM(snd_strerror);
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
130 SDL_ALSA_SYM(snd_pcm_hw_params_sizeof);
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
131 SDL_ALSA_SYM(snd_pcm_sw_params_sizeof);
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
132 SDL_ALSA_SYM(snd_pcm_hw_params_any);
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
133 SDL_ALSA_SYM(snd_pcm_hw_params_set_access);
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
134 SDL_ALSA_SYM(snd_pcm_hw_params_set_format);
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
135 SDL_ALSA_SYM(snd_pcm_hw_params_set_channels);
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
136 SDL_ALSA_SYM(snd_pcm_hw_params_get_channels);
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
137 SDL_ALSA_SYM(snd_pcm_hw_params_set_rate_near);
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
138 SDL_ALSA_SYM(snd_pcm_hw_params_set_period_size_near);
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
139 SDL_ALSA_SYM(snd_pcm_hw_params_get_period_size);
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
140 SDL_ALSA_SYM(snd_pcm_hw_params_set_periods_near);
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
141 SDL_ALSA_SYM(snd_pcm_hw_params_get_periods);
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
142 SDL_ALSA_SYM(snd_pcm_hw_params);
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
143 SDL_ALSA_SYM(snd_pcm_sw_params_current);
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
144 SDL_ALSA_SYM(snd_pcm_sw_params_set_start_threshold);
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
145 SDL_ALSA_SYM(snd_pcm_sw_params_set_avail_min);
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
146 SDL_ALSA_SYM(snd_pcm_sw_params);
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
147 SDL_ALSA_SYM(snd_pcm_nonblock);
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
148 return 0;
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
149 }
3824
25052dd25810 Minor ALSA dynamic loading fix.
Ryan C. Gordon <icculus@icculus.org>
parents: 3819
diff changeset
150 #undef SDL_ALSA_SYM
865
92615154bb68 Date: Sun, 29 Feb 2004 15:14:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
151
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
152 #ifdef SDL_AUDIO_DRIVER_ALSA_DYNAMIC
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
153
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
154 static int library_load_count = 0;
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
155
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
156 static void
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
157 UnloadALSALibrary(void)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
158 {
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
159 if ((alsa_handle != NULL) && (--library_load_count == 0)) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
160 dlclose(alsa_handle);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
161 alsa_handle = NULL;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
162 }
865
92615154bb68 Date: Sun, 29 Feb 2004 15:14:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
163 }
92615154bb68 Date: Sun, 29 Feb 2004 15:14:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
164
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
165 static int
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
166 LoadALSALibrary(void)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
167 {
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
168 int retval = 0;
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
169 if (library_load_count++ == 0) {
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
170 alsa_handle = dlopen(alsa_library, RTLD_NOW);
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
171 if (alsa_handle == NULL) {
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
172 library_load_count--;
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
173 retval = -1;
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
174 SDL_SetError("ALSA: dlopen('%s') failed: %s\n",
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
175 alsa_library, strerror(errno));
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
176 } else {
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
177 retval = load_alsa_syms();
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
178 if (retval < 0) {
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
179 UnloadALSALibrary();
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
180 }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
181 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
182 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
183 return retval;
865
92615154bb68 Date: Sun, 29 Feb 2004 15:14:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
184 }
92615154bb68 Date: Sun, 29 Feb 2004 15:14:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
185
92615154bb68 Date: Sun, 29 Feb 2004 15:14:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
186 #else
92615154bb68 Date: Sun, 29 Feb 2004 15:14:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
187
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
188 static void
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
189 UnloadALSALibrary(void)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
190 {
865
92615154bb68 Date: Sun, 29 Feb 2004 15:14:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
191 }
92615154bb68 Date: Sun, 29 Feb 2004 15:14:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
192
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
193 static int
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
194 LoadALSALibrary(void)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
195 {
3818
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
196 load_alsa_syms();
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
197 return 0;
865
92615154bb68 Date: Sun, 29 Feb 2004 15:14:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
198 }
92615154bb68 Date: Sun, 29 Feb 2004 15:14:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
199
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
200 #endif /* SDL_AUDIO_DRIVER_ALSA_DYNAMIC */
865
92615154bb68 Date: Sun, 29 Feb 2004 15:14:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
201
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
202 static const char *
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
203 get_audio_device(int channels)
354
30935e76acb5 Updated ALSA audio support for ALSA 0.9
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
204 {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
205 const char *device;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
206
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
207 device = SDL_getenv("AUDIODEV"); /* Is there a standard variable name? */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
208 if (device == NULL) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
209 if (channels == 6)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
210 device = "surround51";
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
211 else if (channels == 4)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
212 device = "surround40";
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
213 else
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
214 device = DEFAULT_DEVICE;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
215 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
216 return device;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
217 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
218
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
219
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
220 static int
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
221 ALSA_Available(void)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
222 {
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
223 int available = 0;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
224 int status;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
225 snd_pcm_t *handle;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
226
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
227 if (LoadALSALibrary() >= 0) {
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
228 int status = ALSA_snd_pcm_open(&handle, get_audio_device(2),
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
229 SND_PCM_STREAM_PLAYBACK,
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
230 SND_PCM_NONBLOCK);
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
231 if (status >= 0) {
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
232 available = 1;
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
233 ALSA_snd_pcm_close(handle);
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
234 }
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
235 UnloadALSALibrary();
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
236 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
237 return (available);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
238 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
239
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
240
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
241
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
242 /* This function waits until it is possible to write a full sound buffer */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
243 static void
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
244 ALSA_WaitDevice(_THIS)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
245 {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
246 /* Check to see if the thread-parent process is still alive */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
247 {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
248 static int cnt = 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
249 /* Note that this only works with thread implementations
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
250 that use a different process id for each thread.
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
251 */
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
252 /* Check every 10 loops */
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
253 if (this->hidden->parent && (((++cnt) % 10) == 0)) {
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
254 if (kill(this->hidden->parent, 0) < 0) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
255 this->enabled = 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
256 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
257 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
258 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
259 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
260
1878
d7c9d7f42881 Swizzle ALSA channels for 5.1 output to match DirectSound and CoreAudio.
Ryan C. Gordon <icculus@icculus.org>
parents: 1553
diff changeset
261
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
262 /* !!! FIXME: is there a channel swizzler in alsalib instead? */
1878
d7c9d7f42881 Swizzle ALSA channels for 5.1 output to match DirectSound and CoreAudio.
Ryan C. Gordon <icculus@icculus.org>
parents: 1553
diff changeset
263 /*
d7c9d7f42881 Swizzle ALSA channels for 5.1 output to match DirectSound and CoreAudio.
Ryan C. Gordon <icculus@icculus.org>
parents: 1553
diff changeset
264 * http://bugzilla.libsdl.org/show_bug.cgi?id=110
d7c9d7f42881 Swizzle ALSA channels for 5.1 output to match DirectSound and CoreAudio.
Ryan C. Gordon <icculus@icculus.org>
parents: 1553
diff changeset
265 * "For Linux ALSA, this is FL-FR-RL-RR-C-LFE
d7c9d7f42881 Swizzle ALSA channels for 5.1 output to match DirectSound and CoreAudio.
Ryan C. Gordon <icculus@icculus.org>
parents: 1553
diff changeset
266 * and for Windows DirectX [and CoreAudio], this is FL-FR-C-LFE-RL-RR"
d7c9d7f42881 Swizzle ALSA channels for 5.1 output to match DirectSound and CoreAudio.
Ryan C. Gordon <icculus@icculus.org>
parents: 1553
diff changeset
267 */
d7c9d7f42881 Swizzle ALSA channels for 5.1 output to match DirectSound and CoreAudio.
Ryan C. Gordon <icculus@icculus.org>
parents: 1553
diff changeset
268 #define SWIZ6(T) \
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
269 T *ptr = (T *) this->hidden->mixbuf; \
1878
d7c9d7f42881 Swizzle ALSA channels for 5.1 output to match DirectSound and CoreAudio.
Ryan C. Gordon <icculus@icculus.org>
parents: 1553
diff changeset
270 const Uint32 count = (this->spec.samples / 6); \
d7c9d7f42881 Swizzle ALSA channels for 5.1 output to match DirectSound and CoreAudio.
Ryan C. Gordon <icculus@icculus.org>
parents: 1553
diff changeset
271 Uint32 i; \
d7c9d7f42881 Swizzle ALSA channels for 5.1 output to match DirectSound and CoreAudio.
Ryan C. Gordon <icculus@icculus.org>
parents: 1553
diff changeset
272 for (i = 0; i < count; i++, ptr += 6) { \
d7c9d7f42881 Swizzle ALSA channels for 5.1 output to match DirectSound and CoreAudio.
Ryan C. Gordon <icculus@icculus.org>
parents: 1553
diff changeset
273 T tmp; \
d7c9d7f42881 Swizzle ALSA channels for 5.1 output to match DirectSound and CoreAudio.
Ryan C. Gordon <icculus@icculus.org>
parents: 1553
diff changeset
274 tmp = ptr[2]; ptr[2] = ptr[4]; ptr[4] = tmp; \
d7c9d7f42881 Swizzle ALSA channels for 5.1 output to match DirectSound and CoreAudio.
Ryan C. Gordon <icculus@icculus.org>
parents: 1553
diff changeset
275 tmp = ptr[3]; ptr[3] = ptr[5]; ptr[5] = tmp; \
d7c9d7f42881 Swizzle ALSA channels for 5.1 output to match DirectSound and CoreAudio.
Ryan C. Gordon <icculus@icculus.org>
parents: 1553
diff changeset
276 }
d7c9d7f42881 Swizzle ALSA channels for 5.1 output to match DirectSound and CoreAudio.
Ryan C. Gordon <icculus@icculus.org>
parents: 1553
diff changeset
277
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
278 static __inline__ void
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
279 swizzle_alsa_channels_6_64bit(_THIS)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
280 {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
281 SWIZ6(Uint64);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
282 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
283 static __inline__ void
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
284 swizzle_alsa_channels_6_32bit(_THIS)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
285 {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
286 SWIZ6(Uint32);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
287 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
288 static __inline__ void
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
289 swizzle_alsa_channels_6_16bit(_THIS)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
290 {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
291 SWIZ6(Uint16);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
292 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
293 static __inline__ void
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
294 swizzle_alsa_channels_6_8bit(_THIS)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
295 {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
296 SWIZ6(Uint8);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
297 }
1878
d7c9d7f42881 Swizzle ALSA channels for 5.1 output to match DirectSound and CoreAudio.
Ryan C. Gordon <icculus@icculus.org>
parents: 1553
diff changeset
298
d7c9d7f42881 Swizzle ALSA channels for 5.1 output to match DirectSound and CoreAudio.
Ryan C. Gordon <icculus@icculus.org>
parents: 1553
diff changeset
299 #undef SWIZ6
d7c9d7f42881 Swizzle ALSA channels for 5.1 output to match DirectSound and CoreAudio.
Ryan C. Gordon <icculus@icculus.org>
parents: 1553
diff changeset
300
d7c9d7f42881 Swizzle ALSA channels for 5.1 output to match DirectSound and CoreAudio.
Ryan C. Gordon <icculus@icculus.org>
parents: 1553
diff changeset
301
d7c9d7f42881 Swizzle ALSA channels for 5.1 output to match DirectSound and CoreAudio.
Ryan C. Gordon <icculus@icculus.org>
parents: 1553
diff changeset
302 /*
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
303 * Called right before feeding this->hidden->mixbuf to the hardware. Swizzle
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
304 * channels from Windows/Mac order to the format alsalib will want.
1878
d7c9d7f42881 Swizzle ALSA channels for 5.1 output to match DirectSound and CoreAudio.
Ryan C. Gordon <icculus@icculus.org>
parents: 1553
diff changeset
305 */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
306 static __inline__ void
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
307 swizzle_alsa_channels(_THIS)
1878
d7c9d7f42881 Swizzle ALSA channels for 5.1 output to match DirectSound and CoreAudio.
Ryan C. Gordon <icculus@icculus.org>
parents: 1553
diff changeset
308 {
d7c9d7f42881 Swizzle ALSA channels for 5.1 output to match DirectSound and CoreAudio.
Ryan C. Gordon <icculus@icculus.org>
parents: 1553
diff changeset
309 if (this->spec.channels == 6) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
310 const Uint16 fmtsize = (this->spec.format & 0xFF); /* bits/channel. */
1878
d7c9d7f42881 Swizzle ALSA channels for 5.1 output to match DirectSound and CoreAudio.
Ryan C. Gordon <icculus@icculus.org>
parents: 1553
diff changeset
311 if (fmtsize == 16)
d7c9d7f42881 Swizzle ALSA channels for 5.1 output to match DirectSound and CoreAudio.
Ryan C. Gordon <icculus@icculus.org>
parents: 1553
diff changeset
312 swizzle_alsa_channels_6_16bit(this);
d7c9d7f42881 Swizzle ALSA channels for 5.1 output to match DirectSound and CoreAudio.
Ryan C. Gordon <icculus@icculus.org>
parents: 1553
diff changeset
313 else if (fmtsize == 8)
d7c9d7f42881 Swizzle ALSA channels for 5.1 output to match DirectSound and CoreAudio.
Ryan C. Gordon <icculus@icculus.org>
parents: 1553
diff changeset
314 swizzle_alsa_channels_6_8bit(this);
d7c9d7f42881 Swizzle ALSA channels for 5.1 output to match DirectSound and CoreAudio.
Ryan C. Gordon <icculus@icculus.org>
parents: 1553
diff changeset
315 else if (fmtsize == 32)
d7c9d7f42881 Swizzle ALSA channels for 5.1 output to match DirectSound and CoreAudio.
Ryan C. Gordon <icculus@icculus.org>
parents: 1553
diff changeset
316 swizzle_alsa_channels_6_32bit(this);
d7c9d7f42881 Swizzle ALSA channels for 5.1 output to match DirectSound and CoreAudio.
Ryan C. Gordon <icculus@icculus.org>
parents: 1553
diff changeset
317 else if (fmtsize == 64)
d7c9d7f42881 Swizzle ALSA channels for 5.1 output to match DirectSound and CoreAudio.
Ryan C. Gordon <icculus@icculus.org>
parents: 1553
diff changeset
318 swizzle_alsa_channels_6_64bit(this);
d7c9d7f42881 Swizzle ALSA channels for 5.1 output to match DirectSound and CoreAudio.
Ryan C. Gordon <icculus@icculus.org>
parents: 1553
diff changeset
319 }
d7c9d7f42881 Swizzle ALSA channels for 5.1 output to match DirectSound and CoreAudio.
Ryan C. Gordon <icculus@icculus.org>
parents: 1553
diff changeset
320
d7c9d7f42881 Swizzle ALSA channels for 5.1 output to match DirectSound and CoreAudio.
Ryan C. Gordon <icculus@icculus.org>
parents: 1553
diff changeset
321 /* !!! FIXME: update this for 7.1 if needed, later. */
d7c9d7f42881 Swizzle ALSA channels for 5.1 output to match DirectSound and CoreAudio.
Ryan C. Gordon <icculus@icculus.org>
parents: 1553
diff changeset
322 }
d7c9d7f42881 Swizzle ALSA channels for 5.1 output to match DirectSound and CoreAudio.
Ryan C. Gordon <icculus@icculus.org>
parents: 1553
diff changeset
323
d7c9d7f42881 Swizzle ALSA channels for 5.1 output to match DirectSound and CoreAudio.
Ryan C. Gordon <icculus@icculus.org>
parents: 1553
diff changeset
324
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
325 static void
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
326 ALSA_PlayDevice(_THIS)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
327 {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
328 int status;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
329 int sample_len;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
330 signed short *sample_buf;
765
4c2ba6161939 Editors Note: The original patch was modified to use SDL_Delay() instead of
Sam Lantinga <slouken@libsdl.org>
parents: 547
diff changeset
331
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
332 swizzle_alsa_channels(this);
1878
d7c9d7f42881 Swizzle ALSA channels for 5.1 output to match DirectSound and CoreAudio.
Ryan C. Gordon <icculus@icculus.org>
parents: 1553
diff changeset
333
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
334 sample_len = this->spec.samples;
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
335 sample_buf = (signed short *) this->hidden->mixbuf;
1878
d7c9d7f42881 Swizzle ALSA channels for 5.1 output to match DirectSound and CoreAudio.
Ryan C. Gordon <icculus@icculus.org>
parents: 1553
diff changeset
336
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
337 while (sample_len > 0) {
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
338 status = ALSA_snd_pcm_writei(this->hidden->pcm_handle,
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
339 sample_buf, sample_len);
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
340
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
341 if (status < 0) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
342 if (status == -EAGAIN) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
343 SDL_Delay(1);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
344 continue;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
345 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
346 if (status == -ESTRPIPE) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
347 do {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
348 SDL_Delay(1);
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
349 status = ALSA_snd_pcm_resume(this->hidden->pcm_handle);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
350 } while (status == -EAGAIN);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
351 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
352 if (status < 0) {
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
353 status = ALSA_snd_pcm_prepare(this->hidden->pcm_handle);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
354 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
355 if (status < 0) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
356 /* Hmm, not much we can do - abort */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
357 this->enabled = 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
358 return;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
359 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
360 continue;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
361 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
362 sample_buf += status * this->spec.channels;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
363 sample_len -= status;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
364 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
365 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
366
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
367 static Uint8 *
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
368 ALSA_GetDeviceBuf(_THIS)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
369 {
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
370 return (this->hidden->mixbuf);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
371 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
372
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
373 static void
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
374 ALSA_CloseDevice(_THIS)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
375 {
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
376 if (this->hidden != NULL) {
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
377 if (this->hidden->mixbuf != NULL) {
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
378 SDL_FreeAudioMem(this->hidden->mixbuf);
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
379 this->hidden->mixbuf = NULL;
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
380 }
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
381 if (this->hidden->pcm_handle) {
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
382 ALSA_snd_pcm_drain(this->hidden->pcm_handle);
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
383 ALSA_snd_pcm_close(this->hidden->pcm_handle);
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
384 this->hidden->pcm_handle = NULL;
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
385 }
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
386 SDL_free(this->hidden);
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
387 this->hidden = NULL;
3824
25052dd25810 Minor ALSA dynamic loading fix.
Ryan C. Gordon <icculus@icculus.org>
parents: 3819
diff changeset
388 UnloadALSALibrary();
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
389 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
390 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
391
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
392 static int
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
393 ALSA_OpenDevice(_THIS, const char *devname, int iscapture)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
394 {
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
395 int status = 0;
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
396 snd_pcm_t *pcm_handle = NULL;
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
397 snd_pcm_hw_params_t *hwparams = NULL;
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
398 snd_pcm_sw_params_t *swparams = NULL;
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
399 snd_pcm_format_t format = 0;
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
400 snd_pcm_uframes_t frames = 0;
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
401 SDL_AudioFormat test_format = 0;
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
402
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
403 /* Initialize all variables that we clean on shutdown */
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
404 this->hidden = (struct SDL_PrivateAudioData *)
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
405 SDL_malloc((sizeof *this->hidden));
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
406 if (this->hidden == NULL) {
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
407 SDL_OutOfMemory();
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
408 return 0;
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
409 }
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
410 SDL_memset(this->hidden, 0, (sizeof *this->hidden));
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
411
3824
25052dd25810 Minor ALSA dynamic loading fix.
Ryan C. Gordon <icculus@icculus.org>
parents: 3819
diff changeset
412 if (LoadALSALibrary() < 0) {
25052dd25810 Minor ALSA dynamic loading fix.
Ryan C. Gordon <icculus@icculus.org>
parents: 3819
diff changeset
413 ALSA_CloseDevice(this);
25052dd25810 Minor ALSA dynamic loading fix.
Ryan C. Gordon <icculus@icculus.org>
parents: 3819
diff changeset
414 return 0;
25052dd25810 Minor ALSA dynamic loading fix.
Ryan C. Gordon <icculus@icculus.org>
parents: 3819
diff changeset
415 }
25052dd25810 Minor ALSA dynamic loading fix.
Ryan C. Gordon <icculus@icculus.org>
parents: 3819
diff changeset
416
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
417 /* Open the audio device */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
418 /* Name of device should depend on # channels in spec */
3818
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
419 status = ALSA_snd_pcm_open(&pcm_handle,
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
420 get_audio_device(this->spec.channels),
3818
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
421 SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK);
942
41a59de7f2ed Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents: 939
diff changeset
422
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
423 if (status < 0) {
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
424 ALSA_CloseDevice(this);
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
425 SDL_SetError("ALSA: Couldn't open audio device: %s",
3818
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
426 ALSA_snd_strerror(status));
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
427 return 0;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
428 }
354
30935e76acb5 Updated ALSA audio support for ALSA 0.9
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
429
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
430 this->hidden->pcm_handle = pcm_handle;
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
431
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
432 /* Figure out what the hardware is capable of */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
433 snd_pcm_hw_params_alloca(&hwparams);
3818
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
434 status = ALSA_snd_pcm_hw_params_any(pcm_handle, hwparams);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
435 if (status < 0) {
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
436 ALSA_CloseDevice(this);
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
437 SDL_SetError("ALSA: Couldn't get hardware config: %s",
3818
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
438 ALSA_snd_strerror(status));
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
439 return 0;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
440 }
354
30935e76acb5 Updated ALSA audio support for ALSA 0.9
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
441
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
442 /* SDL only uses interleaved sample output */
3818
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
443 status = ALSA_snd_pcm_hw_params_set_access(pcm_handle, hwparams,
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
444 SND_PCM_ACCESS_RW_INTERLEAVED);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
445 if (status < 0) {
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
446 ALSA_CloseDevice(this);
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
447 SDL_SetError("ALSA: Couldn't set interleaved access: %s",
3818
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
448 ALSA_snd_strerror(status));
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
449 return 0;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
450 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
451
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
452 /* Try for a closest match on audio format */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
453 status = -1;
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
454 for (test_format = SDL_FirstAudioFormat(this->spec.format);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
455 test_format && (status < 0);) {
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
456 status = 0; /* if we can't support a format, it'll become -1. */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
457 switch (test_format) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
458 case AUDIO_U8:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
459 format = SND_PCM_FORMAT_U8;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
460 break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
461 case AUDIO_S8:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
462 format = SND_PCM_FORMAT_S8;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
463 break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
464 case AUDIO_S16LSB:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
465 format = SND_PCM_FORMAT_S16_LE;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
466 break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
467 case AUDIO_S16MSB:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
468 format = SND_PCM_FORMAT_S16_BE;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
469 break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
470 case AUDIO_U16LSB:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
471 format = SND_PCM_FORMAT_U16_LE;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
472 break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
473 case AUDIO_U16MSB:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
474 format = SND_PCM_FORMAT_U16_BE;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
475 break;
1995
0ca6ba107642 ALSA backend can handle int32 and float32 data directly.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
476 case AUDIO_S32LSB:
2010
39897da56f63 Whoops, wrong tokens for int32 support in ALSA driver (specified unsigned
Ryan C. Gordon <icculus@icculus.org>
parents: 2009
diff changeset
477 format = SND_PCM_FORMAT_S32_LE;
1995
0ca6ba107642 ALSA backend can handle int32 and float32 data directly.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
478 break;
0ca6ba107642 ALSA backend can handle int32 and float32 data directly.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
479 case AUDIO_S32MSB:
2010
39897da56f63 Whoops, wrong tokens for int32 support in ALSA driver (specified unsigned
Ryan C. Gordon <icculus@icculus.org>
parents: 2009
diff changeset
480 format = SND_PCM_FORMAT_S32_BE;
1995
0ca6ba107642 ALSA backend can handle int32 and float32 data directly.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
481 break;
0ca6ba107642 ALSA backend can handle int32 and float32 data directly.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
482 case AUDIO_F32LSB:
0ca6ba107642 ALSA backend can handle int32 and float32 data directly.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
483 format = SND_PCM_FORMAT_FLOAT_LE;
0ca6ba107642 ALSA backend can handle int32 and float32 data directly.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
484 break;
0ca6ba107642 ALSA backend can handle int32 and float32 data directly.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
485 case AUDIO_F32MSB:
0ca6ba107642 ALSA backend can handle int32 and float32 data directly.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
486 format = SND_PCM_FORMAT_FLOAT_BE;
0ca6ba107642 ALSA backend can handle int32 and float32 data directly.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
487 break;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
488 default:
2009
f2058fb367e4 ALSA was testing if (format) was set to zero as an error condition, but
Ryan C. Gordon <icculus@icculus.org>
parents: 1995
diff changeset
489 status = -1;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
490 break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
491 }
2009
f2058fb367e4 ALSA was testing if (format) was set to zero as an error condition, but
Ryan C. Gordon <icculus@icculus.org>
parents: 1995
diff changeset
492 if (status >= 0) {
3818
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
493 status = ALSA_snd_pcm_hw_params_set_format(pcm_handle,
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
494 hwparams, format);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
495 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
496 if (status < 0) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
497 test_format = SDL_NextAudioFormat();
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
498 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
499 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
500 if (status < 0) {
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
501 ALSA_CloseDevice(this);
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
502 SDL_SetError("ALSA: Couldn't find any hardware audio formats");
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
503 return 0;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
504 }
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
505 this->spec.format = test_format;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
506
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
507 /* Set the number of channels */
3818
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
508 status = ALSA_snd_pcm_hw_params_set_channels(pcm_handle, hwparams,
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
509 this->spec.channels);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
510 if (status < 0) {
3818
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
511 status = ALSA_snd_pcm_hw_params_get_channels(hwparams);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
512 if ((status <= 0) || (status > 2)) {
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
513 ALSA_CloseDevice(this);
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
514 SDL_SetError("ALSA: Couldn't set audio channels");
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
515 return 0;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
516 }
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
517 this->spec.channels = status;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
518 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
519
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
520 /* Set the audio rate */
3818
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
521 status = ALSA_snd_pcm_hw_params_set_rate_near(pcm_handle, hwparams,
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
522 this->spec.freq, NULL);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
523 if (status < 0) {
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
524 ALSA_CloseDevice(this);
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
525 SDL_SetError("ALSA: Couldn't set audio frequency: %s",
3818
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
526 ALSA_snd_strerror(status));
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
527 return 0;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
528 }
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
529 this->spec.freq = status;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
530
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
531 /* Set the buffer size, in samples */
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
532 frames = this->spec.samples;
3818
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
533 frames = ALSA_snd_pcm_hw_params_set_period_size_near(pcm_handle, hwparams,
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
534 frames, NULL);
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
535 this->spec.samples = frames;
3818
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
536 ALSA_snd_pcm_hw_params_set_periods_near(pcm_handle, hwparams, 2, NULL);
354
30935e76acb5 Updated ALSA audio support for ALSA 0.9
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
537
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
538 /* "set" the hardware with the desired parameters */
3818
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
539 status = ALSA_snd_pcm_hw_params(pcm_handle, hwparams);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
540 if (status < 0) {
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
541 ALSA_CloseDevice(this);
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
542 SDL_SetError("ALSA: Couldn't set hardware audio parameters: %s",
3818
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
543 ALSA_snd_strerror(status));
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
544 return 0;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
545 }
1552
b2462b772cce Fixed bug #79
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
546
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
547 #if AUDIO_DEBUG
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
548 {
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
549 snd_pcm_sframes_t bufsize;
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
550 int fragments;
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
551 bufsize = ALSA_snd_pcm_hw_params_get_period_size(hwparams);
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
552 fragments = ALSA_snd_pcm_hw_params_get_periods(hwparams);
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
553 fprintf(stderr,"ALSA: bufsize = %ld, fragments = %d\n",bufsize,fragments);
1552
b2462b772cce Fixed bug #79
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
554 }
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
555 #endif
1552
b2462b772cce Fixed bug #79
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
556
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
557 /* Set the software parameters */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
558 snd_pcm_sw_params_alloca(&swparams);
3818
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
559 status = ALSA_snd_pcm_sw_params_current(pcm_handle, swparams);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
560 if (status < 0) {
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
561 ALSA_CloseDevice(this);
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
562 SDL_SetError("ALSA: Couldn't get software config: %s",
3818
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
563 ALSA_snd_strerror(status));
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
564 return 0;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
565 }
3818
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
566 status = ALSA_snd_pcm_sw_params_set_start_threshold(pcm_handle,swparams,0);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
567 if (status < 0) {
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
568 ALSA_CloseDevice(this);
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
569 SDL_SetError("ALSA: Couldn't set start threshold: %s",
3818
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
570 ALSA_snd_strerror(status));
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
571 return 0;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
572 }
3818
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
573 status = ALSA_snd_pcm_sw_params_set_avail_min(pcm_handle, swparams, frames);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
574 if (status < 0) {
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
575 ALSA_CloseDevice(this);
3818
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
576 SDL_SetError("Couldn't set avail min: %s", ALSA_snd_strerror(status));
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
577 return 0;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
578 }
3818
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
579 status = ALSA_snd_pcm_sw_params(pcm_handle, swparams);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
580 if (status < 0) {
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
581 ALSA_CloseDevice(this);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
582 SDL_SetError("Couldn't set software audio parameters: %s",
3818
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
583 ALSA_snd_strerror(status));
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
584 return 0;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
585 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
586
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
587 /* Calculate the final parameters for this audio specification */
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
588 SDL_CalculateAudioSpec(&this->spec);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
589
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
590 /* Allocate mixing buffer */
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
591 this->hidden->mixlen = this->spec.size;
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
592 this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen);
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
593 if (this->hidden->mixbuf == NULL) {
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
594 ALSA_CloseDevice(this);
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
595 SDL_OutOfMemory();
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
596 return 0;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
597 }
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
598 SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
599
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
600 /* Get the parent process id (we're the parent of the audio thread) */
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
601 this->hidden->parent = getpid();
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
602
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
603 /* Switch to blocking mode for playback */
3818
49eadd6e8962 Mangled ALSA dynamic loading...static loading will still work if you have the
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
604 ALSA_snd_pcm_nonblock(pcm_handle, 0);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
605
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
606 /* We're ready to rock and roll. :-) */
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
607 return 1;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
608 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
609
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
610 static int
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
611 ALSA_Init(SDL_AudioDriverImpl *impl)
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
612 {
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
613 /* Set the function pointers */
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
614 impl->OpenDevice = ALSA_OpenDevice;
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
615 impl->WaitDevice = ALSA_WaitDevice;
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
616 impl->GetDeviceBuf = ALSA_GetDeviceBuf;
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
617 impl->PlayDevice = ALSA_PlayDevice;
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
618 impl->CloseDevice = ALSA_CloseDevice;
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
619 impl->OnlyHasDefaultOutputDevice = 1; /* !!! FIXME: Add device enum! */
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
620
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
621 return 1;
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
622 }
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
623
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
624
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
625 AudioBootStrap ALSA_bootstrap = {
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
626 DRIVER_NAME, "ALSA 0.9 PCM audio",
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
627 ALSA_Available, ALSA_Init, 0
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
628 };
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 3818
diff changeset
629
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
630 /* vi: set ts=4 sw=4 expandtab: */