Mercurial > sdl-ios-xcode
annotate src/audio/alsa/SDL_alsa_audio.c @ 2049:5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Tue, 17 Oct 2006 09:15:21 +0000 |
parents | adf732f1f016 |
children | 866052b01ee5 |
rev | line source |
---|---|
0 | 1 /* |
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 | 4 |
5 This library is free software; you can redistribute it and/or | |
6 modify it under the terms of the GNU Library General Public | |
7 License as published by the Free Software Foundation; either | |
8 version 2 of the License, or (at your option) any later version. | |
9 | |
10 This library is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 Library General Public License for more details. | |
14 | |
15 You should have received a copy of the GNU Library General Public | |
16 License along with this library; if not, write to the Free | |
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | |
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 | 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 | 23 |
24 /* Allow access to a raw mixing buffer */ | |
25 | |
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() */ |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
28 #include <dlfcn.h> |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
29 #include <errno.h> |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
30 #include <string.h> |
0 | 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 | 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 | 36 #include "SDL_alsa_audio.h" |
37 | |
865
92615154bb68
Date: Sun, 29 Feb 2004 15:14:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
38 |
0 | 39 /* The tag name used by ALSA audio */ |
40 #define DRIVER_NAME "alsa" | |
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 | 44 |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
45 static int (*ALSA_snd_pcm_open) |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
46 (snd_pcm_t **, const char *, snd_pcm_stream_t, int); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
47 static int (*ALSA_snd_pcm_close)(snd_pcm_t * pcm); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
48 static snd_pcm_sframes_t(*ALSA_snd_pcm_writei) |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
49 (snd_pcm_t *,const void *, snd_pcm_uframes_t); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
50 static int (*ALSA_snd_pcm_resume)(snd_pcm_t *); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
51 static int (*ALSA_snd_pcm_prepare)(snd_pcm_t *); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
52 static int (*ALSA_snd_pcm_drain)(snd_pcm_t *); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
53 static const char *(*ALSA_snd_strerror)(int); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
54 static size_t(*ALSA_snd_pcm_hw_params_sizeof)(void); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
55 static size_t(*ALSA_snd_pcm_sw_params_sizeof)(void); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
56 static int (*ALSA_snd_pcm_hw_params_any)(snd_pcm_t *, snd_pcm_hw_params_t *); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
57 static int (*ALSA_snd_pcm_hw_params_set_access) |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
58 (snd_pcm_t *, snd_pcm_hw_params_t *, snd_pcm_access_t); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
59 static int (*ALSA_snd_pcm_hw_params_set_format) |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
60 (snd_pcm_t *, snd_pcm_hw_params_t *, snd_pcm_format_t); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
61 static int (*ALSA_snd_pcm_hw_params_set_channels) |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
62 (snd_pcm_t *, snd_pcm_hw_params_t *, unsigned int); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
63 static int (*ALSA_snd_pcm_hw_params_get_channels)(const snd_pcm_hw_params_t *); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
64 static unsigned int (*ALSA_snd_pcm_hw_params_set_rate_near) |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
65 (snd_pcm_t *, snd_pcm_hw_params_t *, unsigned int, int *); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
66 static snd_pcm_uframes_t (*ALSA_snd_pcm_hw_params_set_period_size_near) |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
67 (snd_pcm_t *, snd_pcm_hw_params_t *, snd_pcm_uframes_t, int *); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
68 static snd_pcm_sframes_t (*ALSA_snd_pcm_hw_params_get_period_size) |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
69 (const snd_pcm_hw_params_t *); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
70 static unsigned int (*ALSA_snd_pcm_hw_params_set_periods_near) |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
71 (snd_pcm_t *,snd_pcm_hw_params_t *, unsigned int, int *); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
72 static int (*ALSA_snd_pcm_hw_params_get_periods)(snd_pcm_hw_params_t *); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
73 static int (*ALSA_snd_pcm_hw_params)(snd_pcm_t *, snd_pcm_hw_params_t *); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
74 static int (*ALSA_snd_pcm_sw_params_current)(snd_pcm_t*, snd_pcm_sw_params_t*); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
75 static int (*ALSA_snd_pcm_sw_params_set_start_threshold) |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
76 (snd_pcm_t *, snd_pcm_sw_params_t *, snd_pcm_uframes_t); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
77 static int (*ALSA_snd_pcm_sw_params_set_avail_min) |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
78 (snd_pcm_t *, snd_pcm_sw_params_t *, snd_pcm_uframes_t); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
79 static int (*ALSA_snd_pcm_sw_params)(snd_pcm_t *, snd_pcm_sw_params_t *); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
80 static int (*ALSA_snd_pcm_nonblock)(snd_pcm_t *, int); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
81 #define snd_pcm_hw_params_sizeof ALSA_snd_pcm_hw_params_sizeof |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
82 #define snd_pcm_sw_params_sizeof ALSA_snd_pcm_sw_params_sizeof |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
83 |
0 | 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; |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
89 |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
90 static int |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
91 load_alsa_sym(const char *fn, void **addr) |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
92 { |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
93 /* |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
94 * !!! FIXME: |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
95 * Eventually, this will deal with fallbacks, version changes, and |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
96 * missing symbols we can workaround. But for now, it doesn't. |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
97 */ |
865
92615154bb68
Date: Sun, 29 Feb 2004 15:14:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
98 |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
99 #if HAVE_DLVSYM |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
100 *addr = dlvsym(alsa_handle, fn, "ALSA_0.9"); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
101 if (*addr == NULL) |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
102 #endif |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
103 { |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
104 *addr = dlsym(alsa_handle, fn); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
105 if (*addr == NULL) { |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
106 SDL_SetError("dlsym('%s') failed: %s", fn, strerror(errno)); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
107 return 0; |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
108 } |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
109 } |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
110 |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
111 return 1; |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
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. */ |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
115 #define SDL_ALSA_SYM(x) \ |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
116 if (!load_alsa_sym(#x, (void **) (char *) &ALSA_##x)) return -1 |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
117 #else |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
118 #define SDL_ALSA_SYM(x) ALSA_##x = x |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
119 #endif |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
120 |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
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 { |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
123 SDL_ALSA_SYM(snd_pcm_open); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
124 SDL_ALSA_SYM(snd_pcm_close); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
125 SDL_ALSA_SYM(snd_pcm_writei); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
126 SDL_ALSA_SYM(snd_pcm_resume); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
127 SDL_ALSA_SYM(snd_pcm_prepare); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
128 SDL_ALSA_SYM(snd_pcm_drain); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
129 SDL_ALSA_SYM(snd_strerror); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
130 SDL_ALSA_SYM(snd_pcm_hw_params_sizeof); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
131 SDL_ALSA_SYM(snd_pcm_sw_params_sizeof); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
132 SDL_ALSA_SYM(snd_pcm_hw_params_any); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
133 SDL_ALSA_SYM(snd_pcm_hw_params_set_access); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
134 SDL_ALSA_SYM(snd_pcm_hw_params_set_format); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
135 SDL_ALSA_SYM(snd_pcm_hw_params_set_channels); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
136 SDL_ALSA_SYM(snd_pcm_hw_params_get_channels); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
137 SDL_ALSA_SYM(snd_pcm_hw_params_set_rate_near); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
138 SDL_ALSA_SYM(snd_pcm_hw_params_set_period_size_near); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
139 SDL_ALSA_SYM(snd_pcm_hw_params_get_period_size); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
140 SDL_ALSA_SYM(snd_pcm_hw_params_set_periods_near); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
141 SDL_ALSA_SYM(snd_pcm_hw_params_get_periods); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
142 SDL_ALSA_SYM(snd_pcm_hw_params); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
143 SDL_ALSA_SYM(snd_pcm_sw_params_current); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
144 SDL_ALSA_SYM(snd_pcm_sw_params_set_start_threshold); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
145 SDL_ALSA_SYM(snd_pcm_sw_params_set_avail_min); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
146 SDL_ALSA_SYM(snd_pcm_sw_params); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
147 SDL_ALSA_SYM(snd_pcm_nonblock); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
148 return 0; |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
149 } |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
150 #undef SDL_ALSA_SYM |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
151 |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
152 #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
|
153 |
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
|
154 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
|
155 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
|
156 { |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
157 if (alsa_handle != 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
|
158 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
|
159 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
|
160 } |
865
92615154bb68
Date: Sun, 29 Feb 2004 15:14:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
161 } |
92615154bb68
Date: Sun, 29 Feb 2004 15:14:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
162 |
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
|
163 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
|
164 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
|
165 { |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
166 int retval = 0; |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
167 if (alsa_handle == NULL) { |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
168 alsa_handle = dlopen(alsa_library, RTLD_NOW); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
169 if (alsa_handle == NULL) { |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
170 retval = -1; |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
171 SDL_SetError("ALSA: dlopen('%s') failed: %s\n", |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
172 alsa_library, strerror(errno)); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
173 } else { |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
174 retval = load_alsa_syms(); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
175 if (retval < 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
|
176 UnloadALSALibrary(); |
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
|
177 } |
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
|
178 } |
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
|
179 } |
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
|
180 return retval; |
865
92615154bb68
Date: Sun, 29 Feb 2004 15:14:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
181 } |
92615154bb68
Date: Sun, 29 Feb 2004 15:14:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
182 |
92615154bb68
Date: Sun, 29 Feb 2004 15:14:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
183 #else |
92615154bb68
Date: Sun, 29 Feb 2004 15:14:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
184 |
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
|
185 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
|
186 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
|
187 { |
865
92615154bb68
Date: Sun, 29 Feb 2004 15:14:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
188 } |
92615154bb68
Date: Sun, 29 Feb 2004 15:14:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
189 |
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
|
190 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
|
191 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
|
192 { |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
193 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
|
194 return 0; |
865
92615154bb68
Date: Sun, 29 Feb 2004 15:14:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
195 } |
92615154bb68
Date: Sun, 29 Feb 2004 15:14:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
196 |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
197 #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
|
198 |
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
|
199 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
|
200 get_audio_device(int channels) |
354
30935e76acb5
Updated ALSA audio support for ALSA 0.9
Sam Lantinga <slouken@libsdl.org>
parents:
297
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 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
|
203 |
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
|
204 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
|
205 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
|
206 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
|
207 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
|
208 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
|
209 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
|
210 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
|
211 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
|
212 } |
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 return device; |
0 | 214 } |
215 | |
216 | |
217 /* 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
|
218 static void |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
219 ALSA_WaitDevice(_THIS) |
0 | 220 { |
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
|
221 /* 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
|
222 { |
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
|
223 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
|
224 /* 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
|
225 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
|
226 */ |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
227 /* Check every 10 loops */ |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
228 if (this->hidden->parent && (((++cnt) % 10) == 0)) { |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
229 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
|
230 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
|
231 } |
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
|
232 } |
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
|
233 } |
0 | 234 } |
235 | |
1878
d7c9d7f42881
Swizzle ALSA channels for 5.1 output to match DirectSound and CoreAudio.
Ryan C. Gordon <icculus@icculus.org>
parents:
1553
diff
changeset
|
236 |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
237 /* !!! 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
|
238 /* |
d7c9d7f42881
Swizzle ALSA channels for 5.1 output to match DirectSound and CoreAudio.
Ryan C. Gordon <icculus@icculus.org>
parents:
1553
diff
changeset
|
239 * 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
|
240 * "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
|
241 * 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
|
242 */ |
d7c9d7f42881
Swizzle ALSA channels for 5.1 output to match DirectSound and CoreAudio.
Ryan C. Gordon <icculus@icculus.org>
parents:
1553
diff
changeset
|
243 #define SWIZ6(T) \ |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
244 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
|
245 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
|
246 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
|
247 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
|
248 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
|
249 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
|
250 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
|
251 } |
d7c9d7f42881
Swizzle ALSA channels for 5.1 output to match DirectSound and CoreAudio.
Ryan C. Gordon <icculus@icculus.org>
parents:
1553
diff
changeset
|
252 |
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
|
253 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
|
254 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
|
255 { |
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 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
|
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 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
|
259 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
|
260 { |
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
|
261 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
|
262 } |
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
|
263 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
|
264 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
|
265 { |
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
|
266 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
|
267 } |
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
|
268 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
|
269 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
|
270 { |
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
|
271 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
|
272 } |
1878
d7c9d7f42881
Swizzle ALSA channels for 5.1 output to match DirectSound and CoreAudio.
Ryan C. Gordon <icculus@icculus.org>
parents:
1553
diff
changeset
|
273 |
d7c9d7f42881
Swizzle ALSA channels for 5.1 output to match DirectSound and CoreAudio.
Ryan C. Gordon <icculus@icculus.org>
parents:
1553
diff
changeset
|
274 #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
|
275 |
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 /* |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
278 * Called right before feeding this->hidden->mixbuf to the hardware. Swizzle |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
279 * 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
|
280 */ |
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
|
281 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
|
282 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
|
283 { |
d7c9d7f42881
Swizzle ALSA channels for 5.1 output to match DirectSound and CoreAudio.
Ryan C. Gordon <icculus@icculus.org>
parents:
1553
diff
changeset
|
284 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
|
285 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
|
286 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
|
287 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
|
288 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
|
289 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
|
290 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
|
291 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
|
292 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
|
293 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
|
294 } |
d7c9d7f42881
Swizzle ALSA channels for 5.1 output to match DirectSound and CoreAudio.
Ryan C. Gordon <icculus@icculus.org>
parents:
1553
diff
changeset
|
295 |
d7c9d7f42881
Swizzle ALSA channels for 5.1 output to match DirectSound and CoreAudio.
Ryan C. Gordon <icculus@icculus.org>
parents:
1553
diff
changeset
|
296 /* !!! 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
|
297 } |
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 |
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
|
300 static void |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
301 ALSA_PlayDevice(_THIS) |
0 | 302 { |
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
|
303 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
|
304 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
|
305 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
|
306 |
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
|
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 |
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
|
309 sample_len = this->spec.samples; |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
310 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
|
311 |
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
|
312 while (sample_len > 0) { |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
313 status = ALSA_snd_pcm_writei(this->hidden->pcm_handle, |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
314 sample_buf, sample_len); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
315 |
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
|
316 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
|
317 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
|
318 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
|
319 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
|
320 } |
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
|
321 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
|
322 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
|
323 SDL_Delay(1); |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
324 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
|
325 } 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
|
326 } |
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
|
327 if (status < 0) { |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
328 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
|
329 } |
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 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
|
331 /* 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
|
332 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
|
333 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
|
334 } |
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
|
335 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
|
336 } |
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 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
|
338 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
|
339 } |
0 | 340 } |
341 | |
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
|
342 static Uint8 * |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
343 ALSA_GetDeviceBuf(_THIS) |
0 | 344 { |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
345 return (this->hidden->mixbuf); |
0 | 346 } |
347 | |
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
|
348 static void |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
349 ALSA_CloseDevice(_THIS) |
0 | 350 { |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
351 if (this->hidden != NULL) { |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
352 if (this->hidden->mixbuf != NULL) { |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
353 SDL_FreeAudioMem(this->hidden->mixbuf); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
354 this->hidden->mixbuf = NULL; |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
355 } |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
356 if (this->hidden->pcm_handle) { |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
357 ALSA_snd_pcm_drain(this->hidden->pcm_handle); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
358 ALSA_snd_pcm_close(this->hidden->pcm_handle); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
359 this->hidden->pcm_handle = NULL; |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
360 } |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
361 SDL_free(this->hidden); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
362 this->hidden = 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
|
363 } |
0 | 364 } |
365 | |
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
|
366 static int |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
367 ALSA_OpenDevice(_THIS, const char *devname, int iscapture) |
0 | 368 { |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
369 int status = 0; |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
370 snd_pcm_t *pcm_handle = NULL; |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
371 snd_pcm_hw_params_t *hwparams = NULL; |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
372 snd_pcm_sw_params_t *swparams = NULL; |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
373 snd_pcm_format_t format = 0; |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
374 snd_pcm_uframes_t frames = 0; |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
375 SDL_AudioFormat test_format = 0; |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
376 |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
377 /* Initialize all variables that we clean on shutdown */ |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
378 this->hidden = (struct SDL_PrivateAudioData *) |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
379 SDL_malloc((sizeof *this->hidden)); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
380 if (this->hidden == NULL) { |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
381 SDL_OutOfMemory(); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
382 return 0; |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
383 } |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
384 SDL_memset(this->hidden, 0, (sizeof *this->hidden)); |
0 | 385 |
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
|
386 /* 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
|
387 /* Name of device should depend on # channels in spec */ |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
388 status = ALSA_snd_pcm_open(&pcm_handle, |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
389 get_audio_device(this->spec.channels), |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
390 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
|
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 if (status < 0) { |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
393 ALSA_CloseDevice(this); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
394 SDL_SetError("ALSA: Couldn't open audio device: %s", |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
395 ALSA_snd_strerror(status)); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
396 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
|
397 } |
354
30935e76acb5
Updated ALSA audio support for ALSA 0.9
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
398 |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
399 this->hidden->pcm_handle = pcm_handle; |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
400 |
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
|
401 /* 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
|
402 snd_pcm_hw_params_alloca(&hwparams); |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
403 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
|
404 if (status < 0) { |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
405 ALSA_CloseDevice(this); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
406 SDL_SetError("ALSA: Couldn't get hardware config: %s", |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
407 ALSA_snd_strerror(status)); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
408 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
|
409 } |
354
30935e76acb5
Updated ALSA audio support for ALSA 0.9
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
410 |
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
|
411 /* SDL only uses interleaved sample output */ |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
412 status = ALSA_snd_pcm_hw_params_set_access(pcm_handle, hwparams, |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
413 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
|
414 if (status < 0) { |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
415 ALSA_CloseDevice(this); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
416 SDL_SetError("ALSA: Couldn't set interleaved access: %s", |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
417 ALSA_snd_strerror(status)); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
418 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
|
419 } |
0 | 420 |
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
|
421 /* 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
|
422 status = -1; |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
423 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
|
424 test_format && (status < 0);) { |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
425 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
|
426 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
|
427 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
|
428 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
|
429 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
|
430 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
|
431 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
|
432 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
|
433 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
|
434 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
|
435 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
|
436 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
|
437 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
|
438 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
|
439 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
|
440 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
|
441 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
|
442 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
|
443 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
|
444 break; |
1995
0ca6ba107642
ALSA backend can handle int32 and float32 data directly.
Ryan C. Gordon <icculus@icculus.org>
parents:
1982
diff
changeset
|
445 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
|
446 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
|
447 break; |
0ca6ba107642
ALSA backend can handle int32 and float32 data directly.
Ryan C. Gordon <icculus@icculus.org>
parents:
1982
diff
changeset
|
448 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
|
449 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
|
450 break; |
0ca6ba107642
ALSA backend can handle int32 and float32 data directly.
Ryan C. Gordon <icculus@icculus.org>
parents:
1982
diff
changeset
|
451 case AUDIO_F32LSB: |
0ca6ba107642
ALSA backend can handle int32 and float32 data directly.
Ryan C. Gordon <icculus@icculus.org>
parents:
1982
diff
changeset
|
452 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
|
453 break; |
0ca6ba107642
ALSA backend can handle int32 and float32 data directly.
Ryan C. Gordon <icculus@icculus.org>
parents:
1982
diff
changeset
|
454 case AUDIO_F32MSB: |
0ca6ba107642
ALSA backend can handle int32 and float32 data directly.
Ryan C. Gordon <icculus@icculus.org>
parents:
1982
diff
changeset
|
455 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
|
456 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
|
457 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
|
458 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
|
459 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
|
460 } |
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
|
461 if (status >= 0) { |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
462 status = ALSA_snd_pcm_hw_params_set_format(pcm_handle, |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
463 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
|
464 } |
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 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
|
466 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
|
467 } |
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 } |
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 if (status < 0) { |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
470 ALSA_CloseDevice(this); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
471 SDL_SetError("ALSA: Couldn't find any hardware audio formats"); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
472 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
|
473 } |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
474 this->spec.format = test_format; |
0 | 475 |
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
|
476 /* Set the number of channels */ |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
477 status = ALSA_snd_pcm_hw_params_set_channels(pcm_handle, hwparams, |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
478 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
|
479 if (status < 0) { |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
480 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
|
481 if ((status <= 0) || (status > 2)) { |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
482 ALSA_CloseDevice(this); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
483 SDL_SetError("ALSA: Couldn't set audio channels"); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
484 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
|
485 } |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
486 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
|
487 } |
0 | 488 |
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
|
489 /* Set the audio rate */ |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
490 status = ALSA_snd_pcm_hw_params_set_rate_near(pcm_handle, hwparams, |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
491 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
|
492 if (status < 0) { |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
493 ALSA_CloseDevice(this); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
494 SDL_SetError("ALSA: Couldn't set audio frequency: %s", |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
495 ALSA_snd_strerror(status)); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
496 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
|
497 } |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
498 this->spec.freq = status; |
0 | 499 |
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
|
500 /* Set the buffer size, in samples */ |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
501 frames = this->spec.samples; |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
502 frames = ALSA_snd_pcm_hw_params_set_period_size_near(pcm_handle, hwparams, |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
503 frames, NULL); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
504 this->spec.samples = frames; |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
505 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
|
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 hardware with the desired parameters */ |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
508 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
|
509 if (status < 0) { |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
510 ALSA_CloseDevice(this); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
511 SDL_SetError("ALSA: Couldn't set hardware audio parameters: %s", |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
512 ALSA_snd_strerror(status)); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
513 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
|
514 } |
1552 | 515 |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
516 #if AUDIO_DEBUG |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
517 { |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
518 snd_pcm_sframes_t bufsize; |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
519 int fragments; |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
520 bufsize = ALSA_snd_pcm_hw_params_get_period_size(hwparams); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
521 fragments = ALSA_snd_pcm_hw_params_get_periods(hwparams); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
522 fprintf(stderr,"ALSA: bufsize = %ld, fragments = %d\n",bufsize,fragments); |
1552 | 523 } |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
524 #endif |
1552 | 525 |
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
|
526 /* 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
|
527 snd_pcm_sw_params_alloca(&swparams); |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
528 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
|
529 if (status < 0) { |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
530 ALSA_CloseDevice(this); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
531 SDL_SetError("ALSA: Couldn't get software config: %s", |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
532 ALSA_snd_strerror(status)); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
533 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
|
534 } |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
535 status = ALSA_snd_pcm_sw_params_set_start_threshold(pcm_handle,swparams,0); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
536 if (status < 0) { |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
537 ALSA_CloseDevice(this); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
538 SDL_SetError("ALSA: Couldn't set start threshold: %s", |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
539 ALSA_snd_strerror(status)); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
540 return 0; |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
541 } |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
542 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
|
543 if (status < 0) { |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
544 ALSA_CloseDevice(this); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
545 SDL_SetError("Couldn't set avail min: %s", ALSA_snd_strerror(status)); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
546 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
|
547 } |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
548 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
|
549 if (status < 0) { |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
550 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
|
551 SDL_SetError("Couldn't set software audio parameters: %s", |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
552 ALSA_snd_strerror(status)); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
553 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
|
554 } |
0 | 555 |
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
|
556 /* Calculate the final parameters for this audio specification */ |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
557 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
|
558 |
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
|
559 /* Allocate mixing buffer */ |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
560 this->hidden->mixlen = this->spec.size; |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
561 this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
562 if (this->hidden->mixbuf == NULL) { |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
563 ALSA_CloseDevice(this); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
564 SDL_OutOfMemory(); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
565 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
|
566 } |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
567 SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size); |
0 | 568 |
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
|
569 /* Get the parent process id (we're the parent of the audio thread) */ |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
570 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
|
571 |
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 /* Switch to blocking mode for playback */ |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
573 ALSA_snd_pcm_nonblock(pcm_handle, 0); |
0 | 574 |
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
|
575 /* We're ready to rock and roll. :-) */ |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
576 return 1; |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
577 } |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
578 |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
579 static void |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
580 ALSA_Deinitialize(void) |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
581 { |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
582 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
|
583 } |
0 | 584 |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
585 static int |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
586 ALSA_Init(SDL_AudioDriverImpl *impl) |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
587 { |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
588 if (LoadALSALibrary() < 0) { |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
589 return 0; |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
590 } |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
591 |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
592 /* Set the function pointers */ |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
593 impl->OpenDevice = ALSA_OpenDevice; |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
594 impl->WaitDevice = ALSA_WaitDevice; |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
595 impl->GetDeviceBuf = ALSA_GetDeviceBuf; |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
596 impl->PlayDevice = ALSA_PlayDevice; |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
597 impl->CloseDevice = ALSA_CloseDevice; |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
598 impl->Deinitialize = ALSA_Deinitialize; |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
599 impl->OnlyHasDefaultOutputDevice = 1; /* !!! FIXME: Add device enum! */ |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
600 |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
601 return 1; |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
602 } |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
603 |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
604 |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
605 AudioBootStrap ALSA_bootstrap = { |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
606 DRIVER_NAME, "ALSA 0.9 PCM audio", ALSA_Init, 0 |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
607 }; |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2043
diff
changeset
|
608 |
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
|
609 /* vi: set ts=4 sw=4 expandtab: */ |