annotate src/audio/alsa/SDL_alsa_audio.c @ 4810:7a602fd2121f

OK, it appears that dramatic hacks are not necessary to make Cocoa work...
author Eli Gottlieb <eligottlieb@gmail.com>
date Mon, 26 Jul 2010 20:41:45 -0400
parents 9bc9ff36eb8f
children b530ef003506
rev   line source
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1 /*
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2 SDL - Simple DirectMedia Layer
3697
f7b03b6838cb Fixed bug #926
Sam Lantinga <slouken@libsdl.org>
parents: 3627
diff changeset
3 Copyright (C) 1997-2010 Sam Lantinga
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
4
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
5 This library is free software; you can redistribute it and/or
3697
f7b03b6838cb Fixed bug #926
Sam Lantinga <slouken@libsdl.org>
parents: 3627
diff changeset
6 modify it under the terms of the GNU Lesser General Public
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
3697
f7b03b6838cb Fixed bug #926
Sam Lantinga <slouken@libsdl.org>
parents: 3627
diff changeset
8 version 2.1 of the License, or (at your option) any later version.
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
9
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3697
f7b03b6838cb Fixed bug #926
Sam Lantinga <slouken@libsdl.org>
parents: 3627
diff changeset
13 Lesser General Public License for more details.
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
14
3697
f7b03b6838cb Fixed bug #926
Sam Lantinga <slouken@libsdl.org>
parents: 3627
diff changeset
15 You should have received a copy of the GNU Lesser General Public
f7b03b6838cb Fixed bug #926
Sam Lantinga <slouken@libsdl.org>
parents: 3627
diff changeset
16 License along with this library; if not, write to the Free Software
f7b03b6838cb Fixed bug #926
Sam Lantinga <slouken@libsdl.org>
parents: 3627
diff changeset
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
18
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
19 Sam Lantinga
252
e8157fcb3114 Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents: 0
diff changeset
20 slouken@libsdl.org
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
21 */
1402
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1379
diff changeset
22 #include "SDL_config.h"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
23
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
24 /* Allow access to a raw mixing buffer */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
25
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
26 #include <sys/types.h>
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
27 #include <signal.h> /* For kill() */
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 <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
29 #include <string.h>
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
30
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
31 #include "SDL_timer.h"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
32 #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
33 #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
34 #include "../SDL_audio_c.h"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
35 #include "SDL_alsa_audio.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
36
3362
4e83cdb58134 Merged r4990:4991 from branches/SDL-1.2: ALSA 1.0 API and dlvsym() removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
37 #ifdef SDL_AUDIO_DRIVER_ALSA_DYNAMIC
4e83cdb58134 Merged r4990:4991 from branches/SDL-1.2: ALSA 1.0 API and dlvsym() removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
38 #include "SDL_loadso.h"
4e83cdb58134 Merged r4990:4991 from branches/SDL-1.2: ALSA 1.0 API and dlvsym() removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
39 #endif
865
92615154bb68 Date: Sun, 29 Feb 2004 15:14:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
40
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
41 /* The tag name used by ALSA audio */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
42 #define DRIVER_NAME "alsa"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
43
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
44 static int (*ALSA_snd_pcm_open)
2060
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2049
diff changeset
45 (snd_pcm_t **, const char *, snd_pcm_stream_t, int);
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2049
diff changeset
46 static int (*ALSA_snd_pcm_close) (snd_pcm_t * pcm);
2049
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 snd_pcm_sframes_t(*ALSA_snd_pcm_writei)
2060
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2049
diff changeset
48 (snd_pcm_t *, const void *, snd_pcm_uframes_t);
3627
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
49 static int (*ALSA_snd_pcm_recover) (snd_pcm_t *, int, int);
2060
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2049
diff changeset
50 static int (*ALSA_snd_pcm_prepare) (snd_pcm_t *);
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2049
diff changeset
51 static int (*ALSA_snd_pcm_drain) (snd_pcm_t *);
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2049
diff changeset
52 static const char *(*ALSA_snd_strerror) (int);
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2049
diff changeset
53 static size_t(*ALSA_snd_pcm_hw_params_sizeof) (void);
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2049
diff changeset
54 static size_t(*ALSA_snd_pcm_sw_params_sizeof) (void);
3627
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
55 static void (*ALSA_snd_pcm_hw_params_copy)
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
56 (snd_pcm_hw_params_t *, const snd_pcm_hw_params_t *);
2060
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2049
diff changeset
57 static int (*ALSA_snd_pcm_hw_params_any) (snd_pcm_t *, snd_pcm_hw_params_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
58 static int (*ALSA_snd_pcm_hw_params_set_access)
2060
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2049
diff changeset
59 (snd_pcm_t *, snd_pcm_hw_params_t *, snd_pcm_access_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
60 static int (*ALSA_snd_pcm_hw_params_set_format)
2060
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2049
diff changeset
61 (snd_pcm_t *, snd_pcm_hw_params_t *, snd_pcm_format_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
62 static int (*ALSA_snd_pcm_hw_params_set_channels)
2060
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2049
diff changeset
63 (snd_pcm_t *, snd_pcm_hw_params_t *, unsigned int);
3627
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
64 static int (*ALSA_snd_pcm_hw_params_get_channels)
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
65 (const snd_pcm_hw_params_t *, unsigned int *);
3362
4e83cdb58134 Merged r4990:4991 from branches/SDL-1.2: ALSA 1.0 API and dlvsym() removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
66 static int (*ALSA_snd_pcm_hw_params_set_rate_near)
4e83cdb58134 Merged r4990:4991 from branches/SDL-1.2: ALSA 1.0 API and dlvsym() removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
67 (snd_pcm_t *, snd_pcm_hw_params_t *, unsigned int *, int *);
4e83cdb58134 Merged r4990:4991 from branches/SDL-1.2: ALSA 1.0 API and dlvsym() removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
68 static int (*ALSA_snd_pcm_hw_params_set_period_size_near)
4e83cdb58134 Merged r4990:4991 from branches/SDL-1.2: ALSA 1.0 API and dlvsym() removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
69 (snd_pcm_t *, snd_pcm_hw_params_t *, snd_pcm_uframes_t *, int *);
3627
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
70 static int (*ALSA_snd_pcm_hw_params_get_period_size)
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
71 (const snd_pcm_hw_params_t *, snd_pcm_uframes_t *, int *);
3362
4e83cdb58134 Merged r4990:4991 from branches/SDL-1.2: ALSA 1.0 API and dlvsym() removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
72 static int (*ALSA_snd_pcm_hw_params_set_periods_near)
4e83cdb58134 Merged r4990:4991 from branches/SDL-1.2: ALSA 1.0 API and dlvsym() removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
73 (snd_pcm_t *, snd_pcm_hw_params_t *, unsigned int *, int *);
3627
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
74 static int (*ALSA_snd_pcm_hw_params_get_periods)
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
75 (const snd_pcm_hw_params_t *, unsigned int *, int *);
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
76 static int (*ALSA_snd_pcm_hw_params_set_buffer_size_near)
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
77 (snd_pcm_t *pcm, snd_pcm_hw_params_t *, snd_pcm_uframes_t *);
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
78 static int (*ALSA_snd_pcm_hw_params_get_buffer_size)
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
79 (const snd_pcm_hw_params_t *, snd_pcm_uframes_t *);
2060
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2049
diff changeset
80 static int (*ALSA_snd_pcm_hw_params) (snd_pcm_t *, snd_pcm_hw_params_t *);
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2049
diff changeset
81 static int (*ALSA_snd_pcm_sw_params_current) (snd_pcm_t *,
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2049
diff changeset
82 snd_pcm_sw_params_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
83 static int (*ALSA_snd_pcm_sw_params_set_start_threshold)
2060
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2049
diff changeset
84 (snd_pcm_t *, snd_pcm_sw_params_t *, snd_pcm_uframes_t);
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2049
diff changeset
85 static int (*ALSA_snd_pcm_sw_params) (snd_pcm_t *, snd_pcm_sw_params_t *);
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2049
diff changeset
86 static int (*ALSA_snd_pcm_nonblock) (snd_pcm_t *, int);
3627
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
87 static int (*ALSA_snd_pcm_wait)(snd_pcm_t *, 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
88 #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
89 #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
90
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
91
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
92 #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
93
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
94 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
95 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
96
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
97 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
98 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
99 {
3362
4e83cdb58134 Merged r4990:4991 from branches/SDL-1.2: ALSA 1.0 API and dlvsym() removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
100 *addr = SDL_LoadFunction(alsa_handle, fn);
4e83cdb58134 Merged r4990:4991 from branches/SDL-1.2: ALSA 1.0 API and dlvsym() removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
101 if (*addr == NULL) {
4e83cdb58134 Merged r4990:4991 from branches/SDL-1.2: ALSA 1.0 API and dlvsym() removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
102 /* Don't call SDL_SetError(): SDL_LoadFunction already did. */
4e83cdb58134 Merged r4990:4991 from branches/SDL-1.2: ALSA 1.0 API and dlvsym() removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
103 return 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
104 }
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
105
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
106 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
107 }
865
92615154bb68 Date: Sun, 29 Feb 2004 15:14:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
108
1161
05d4b93b911e Placate gcc's strict aliasing rules with an extra cast.
Ryan C. Gordon <icculus@icculus.org>
parents: 942
diff changeset
109 /* 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
110 #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
111 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
112 #else
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
113 #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
114 #endif
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
115
2060
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2049
diff changeset
116 static int
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2049
diff changeset
117 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
118 {
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
119 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
120 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
121 SDL_ALSA_SYM(snd_pcm_writei);
3627
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
122 SDL_ALSA_SYM(snd_pcm_recover);
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_prepare);
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_drain);
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_strerror);
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_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
127 SDL_ALSA_SYM(snd_pcm_sw_params_sizeof);
3627
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
128 SDL_ALSA_SYM(snd_pcm_hw_params_copy);
2049
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_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
130 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
131 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
132 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
133 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
134 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
135 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
136 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
137 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
138 SDL_ALSA_SYM(snd_pcm_hw_params_get_periods);
3627
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
139 SDL_ALSA_SYM(snd_pcm_hw_params_set_buffer_size_near);
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
140 SDL_ALSA_SYM(snd_pcm_hw_params_get_buffer_size);
2049
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);
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_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
143 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
144 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
145 SDL_ALSA_SYM(snd_pcm_nonblock);
3627
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
146 SDL_ALSA_SYM(snd_pcm_wait);
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
147 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
148 }
2060
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2049
diff changeset
149
2049
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) {
3362
4e83cdb58134 Merged r4990:4991 from branches/SDL-1.2: ALSA 1.0 API and dlvsym() removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
158 SDL_UnloadObject(alsa_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
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) {
3362
4e83cdb58134 Merged r4990:4991 from branches/SDL-1.2: ALSA 1.0 API and dlvsym() removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
168 alsa_handle = SDL_LoadObject(alsa_library);
2049
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;
3362
4e83cdb58134 Merged r4990:4991 from branches/SDL-1.2: ALSA 1.0 API and dlvsym() removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
171 /* Don't call SDL_SetError(): SDL_LoadObject already did. */
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
172 } else {
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
173 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
174 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
175 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
176 }
c121d94672cb SDL 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 return retval;
865
92615154bb68 Date: Sun, 29 Feb 2004 15:14:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
180 }
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 #else
92615154bb68 Date: Sun, 29 Feb 2004 15:14:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
183
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
184 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
185 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
186 {
865
92615154bb68 Date: Sun, 29 Feb 2004 15:14:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
187 }
92615154bb68 Date: Sun, 29 Feb 2004 15:14:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
188
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
189 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
190 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
191 {
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
192 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
193 return 0;
865
92615154bb68 Date: Sun, 29 Feb 2004 15:14:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
194 }
92615154bb68 Date: Sun, 29 Feb 2004 15:14:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
195
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
196 #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
197
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
198 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
199 get_audio_device(int channels)
354
30935e76acb5 Updated ALSA audio support for ALSA 0.9
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
200 {
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
201 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
202
c121d94672cb SDL 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 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
204 if (device == NULL) {
3627
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
205 switch (channels) {
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
206 case 6:
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
207 device = "plug:surround51";
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
208 break;
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
209 case 4:
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
210 device = "plug:surround40";
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
211 break;
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
212 default:
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
213 device = "default";
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
214 break;
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
215 }
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
216 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
217 return device;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
218 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
219
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
220
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
221 /* 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
222 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
223 ALSA_WaitDevice(_THIS)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
224 {
3627
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
225 /* We're in blocking mode, so there's nothing to do here */
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
226 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
227
1878
d7c9d7f42881 Swizzle ALSA channels for 5.1 output to match DirectSound and CoreAudio.
Ryan C. Gordon <icculus@icculus.org>
parents: 1553
diff changeset
228
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
229 /* !!! 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
230 /*
d7c9d7f42881 Swizzle ALSA channels for 5.1 output to match DirectSound and CoreAudio.
Ryan C. Gordon <icculus@icculus.org>
parents: 1553
diff changeset
231 * 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
232 * "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
233 * 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
234 */
d7c9d7f42881 Swizzle ALSA channels for 5.1 output to match DirectSound and CoreAudio.
Ryan C. Gordon <icculus@icculus.org>
parents: 1553
diff changeset
235 #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
236 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
237 Uint32 i; \
3704
9bc9ff36eb8f Merged r5549:5550 from branches/SDL-1.2: ALSA 6-channel swizzle fix.
Ryan C. Gordon <icculus@icculus.org>
parents: 3699
diff changeset
238 for (i = 0; i < this->spec.samples; i++, ptr += 6) { \
1878
d7c9d7f42881 Swizzle ALSA channels for 5.1 output to match DirectSound and CoreAudio.
Ryan C. Gordon <icculus@icculus.org>
parents: 1553
diff changeset
239 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
240 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
241 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
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
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
244 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
245 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
246 {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
247 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
248 }
2735
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2060
diff changeset
249
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
250 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
251 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
252 {
c121d94672cb SDL 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 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
254 }
2735
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2060
diff changeset
255
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
256 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
257 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
258 {
c121d94672cb SDL 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 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
260 }
2735
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2060
diff changeset
261
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
262 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
263 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
264 {
c121d94672cb SDL 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 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
266 }
1878
d7c9d7f42881 Swizzle ALSA channels for 5.1 output to match DirectSound and CoreAudio.
Ryan C. Gordon <icculus@icculus.org>
parents: 1553
diff changeset
267
d7c9d7f42881 Swizzle ALSA channels for 5.1 output to match DirectSound and CoreAudio.
Ryan C. Gordon <icculus@icculus.org>
parents: 1553
diff changeset
268 #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
269
d7c9d7f42881 Swizzle ALSA channels for 5.1 output to match DirectSound and CoreAudio.
Ryan C. Gordon <icculus@icculus.org>
parents: 1553
diff changeset
270
d7c9d7f42881 Swizzle ALSA channels for 5.1 output to match DirectSound and CoreAudio.
Ryan C. Gordon <icculus@icculus.org>
parents: 1553
diff changeset
271 /*
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
272 * 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
273 * 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
274 */
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
275 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
276 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
277 {
d7c9d7f42881 Swizzle ALSA channels for 5.1 output to match DirectSound and CoreAudio.
Ryan C. Gordon <icculus@icculus.org>
parents: 1553
diff changeset
278 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
279 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
280 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
281 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
282 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
283 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
284 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
285 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
286 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
287 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
288 }
d7c9d7f42881 Swizzle ALSA channels for 5.1 output to match DirectSound and CoreAudio.
Ryan C. Gordon <icculus@icculus.org>
parents: 1553
diff changeset
289
d7c9d7f42881 Swizzle ALSA channels for 5.1 output to match DirectSound and CoreAudio.
Ryan C. Gordon <icculus@icculus.org>
parents: 1553
diff changeset
290 /* !!! 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
291 }
d7c9d7f42881 Swizzle ALSA channels for 5.1 output to match DirectSound and CoreAudio.
Ryan C. Gordon <icculus@icculus.org>
parents: 1553
diff changeset
292
d7c9d7f42881 Swizzle ALSA channels for 5.1 output to match DirectSound and CoreAudio.
Ryan C. Gordon <icculus@icculus.org>
parents: 1553
diff changeset
293
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
294 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
295 ALSA_PlayDevice(_THIS)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
296 {
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
297 int status;
3627
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
298 const Uint8 *sample_buf = (const Uint8 *) this->hidden->mixbuf;
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
299 const int frame_size = (((int) (this->spec.format & 0xFF)) / 8) *
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
300 this->spec.channels;
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
301 snd_pcm_uframes_t frames_left = ((snd_pcm_uframes_t) this->spec.samples);
765
4c2ba6161939 Editors Note: The original patch was modified to use SDL_Delay() instead of
Sam Lantinga <slouken@libsdl.org>
parents: 547
diff changeset
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 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
304
3627
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
305 while ( frames_left > 0 && this->enabled ) {
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
306 /* !!! FIXME: This works, but needs more testing before going live */
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
307 /*ALSA_snd_pcm_wait(this->hidden->pcm_handle, -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
308 status = ALSA_snd_pcm_writei(this->hidden->pcm_handle,
3627
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
309 sample_buf, frames_left);
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
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
311 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
312 if (status == -EAGAIN) {
3627
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
313 /* Apparently snd_pcm_recover() doesn't handle this case -
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
314 does it assume snd_pcm_wait() above? */
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
315 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
316 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
317 }
3627
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
318 status = ALSA_snd_pcm_recover(this->hidden->pcm_handle, status, 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
319 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
320 /* Hmm, not much we can do - abort */
3627
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
321 fprintf(stderr, "ALSA write failed (unrecoverable): %s\n",
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
322 ALSA_snd_strerror(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
323 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
324 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
325 }
c121d94672cb SDL 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 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
327 }
3627
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
328 sample_buf += status * frame_size;
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
329 frames_left -= 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
330 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
331 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
332
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
333 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
334 ALSA_GetDeviceBuf(_THIS)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
335 {
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
336 return (this->hidden->mixbuf);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
337 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
338
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
339 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
340 ALSA_CloseDevice(_THIS)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
341 {
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
342 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
343 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
344 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
345 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
346 }
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
347 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
348 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
349 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
350 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
351 }
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
352 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
353 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
354 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
355 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
356
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
357 static int
3627
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
358 ALSA_finalize_hardware(_THIS, snd_pcm_hw_params_t *hwparams, int override)
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
359 {
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
360 int status;
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
361 snd_pcm_uframes_t bufsize;
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
362
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
363 /* "set" the hardware with the desired parameters */
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
364 status = ALSA_snd_pcm_hw_params(this->hidden->pcm_handle, hwparams);
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
365 if ( status < 0 ) {
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
366 return(-1);
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
367 }
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
368
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
369 /* Get samples for the actual buffer size */
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
370 status = ALSA_snd_pcm_hw_params_get_buffer_size(hwparams, &bufsize);
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
371 if ( status < 0 ) {
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
372 return(-1);
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
373 }
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
374 if ( !override && bufsize != this->spec.samples * 2 ) {
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
375 return(-1);
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
376 }
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
377
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
378 /* !!! FIXME: Is this safe to do? */
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
379 this->spec.samples = bufsize / 2;
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
380
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
381 /* This is useful for debugging */
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
382 if ( SDL_getenv("SDL_AUDIO_ALSA_DEBUG") ) {
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
383 snd_pcm_uframes_t persize = 0;
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
384 unsigned int periods = 0;
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
385
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
386 ALSA_snd_pcm_hw_params_get_period_size(hwparams, &persize, NULL);
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
387 ALSA_snd_pcm_hw_params_get_periods(hwparams, &periods, NULL);
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
388
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
389 fprintf(stderr,
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
390 "ALSA: period size = %ld, periods = %u, buffer size = %lu\n",
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
391 persize, periods, bufsize);
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
392 }
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
393
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
394 return(0);
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
395 }
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
396
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
397 static int
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
398 ALSA_set_period_size(_THIS, snd_pcm_hw_params_t *params, int override)
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
399 {
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
400 const char *env;
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
401 int status;
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
402 snd_pcm_hw_params_t *hwparams;
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
403 snd_pcm_uframes_t frames;
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
404 unsigned int periods;
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
405
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
406 /* Copy the hardware parameters for this setup */
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
407 snd_pcm_hw_params_alloca(&hwparams);
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
408 ALSA_snd_pcm_hw_params_copy(hwparams, params);
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
409
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
410 if ( !override ) {
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
411 env = SDL_getenv("SDL_AUDIO_ALSA_SET_PERIOD_SIZE");
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
412 if ( env ) {
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
413 override = SDL_atoi(env);
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
414 if ( override == 0 ) {
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
415 return(-1);
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
416 }
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
417 }
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
418 }
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
419
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
420 frames = this->spec.samples;
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
421 status = ALSA_snd_pcm_hw_params_set_period_size_near(
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
422 this->hidden->pcm_handle, hwparams, &frames, NULL);
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
423 if ( status < 0 ) {
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
424 return(-1);
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
425 }
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
426
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
427 periods = 2;
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
428 status = ALSA_snd_pcm_hw_params_set_periods_near(
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
429 this->hidden->pcm_handle, hwparams, &periods, NULL);
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
430 if ( status < 0 ) {
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
431 return(-1);
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
432 }
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
433
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
434 return ALSA_finalize_hardware(this, hwparams, override);
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
435 }
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
436
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
437 static int
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
438 ALSA_set_buffer_size(_THIS, snd_pcm_hw_params_t *params, int override)
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
439 {
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
440 const char *env;
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
441 int status;
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
442 snd_pcm_hw_params_t *hwparams;
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
443 snd_pcm_uframes_t frames;
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
444
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
445 /* Copy the hardware parameters for this setup */
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
446 snd_pcm_hw_params_alloca(&hwparams);
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
447 ALSA_snd_pcm_hw_params_copy(hwparams, params);
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
448
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
449 if ( !override ) {
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
450 env = SDL_getenv("SDL_AUDIO_ALSA_SET_BUFFER_SIZE");
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
451 if ( env ) {
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
452 override = SDL_atoi(env);
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
453 if ( override == 0 ) {
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
454 return(-1);
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
455 }
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
456 }
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
457 }
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
458
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
459 frames = this->spec.samples * 2;
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
460 status = ALSA_snd_pcm_hw_params_set_buffer_size_near(
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
461 this->hidden->pcm_handle, hwparams, &frames);
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
462 if ( status < 0 ) {
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
463 return(-1);
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
464 }
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
465
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
466 return ALSA_finalize_hardware(this, hwparams, override);
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
467 }
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
468
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
469 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
470 ALSA_OpenDevice(_THIS, const char *devname, int iscapture)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
471 {
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
472 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
473 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
474 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
475 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
476 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
477 SDL_AudioFormat test_format = 0;
3362
4e83cdb58134 Merged r4990:4991 from branches/SDL-1.2: ALSA 1.0 API and dlvsym() removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
478 unsigned int rate = 0;
4e83cdb58134 Merged r4990:4991 from branches/SDL-1.2: ALSA 1.0 API and dlvsym() removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
479 unsigned int channels = 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
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
481 /* 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
482 this->hidden = (struct SDL_PrivateAudioData *)
2060
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2049
diff changeset
483 SDL_malloc((sizeof *this->hidden));
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
484 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
485 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
486 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
487 }
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
488 SDL_memset(this->hidden, 0, (sizeof *this->hidden));
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
489
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
490 /* 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
491 /* 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
492 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
493 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
494 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
495
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
496 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
497 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
498 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
499 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
500 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
501 }
354
30935e76acb5 Updated ALSA audio support for ALSA 0.9
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
502
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
503 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
504
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
505 /* 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
506 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
507 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
508 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
509 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
510 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
511 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
512 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
513 }
354
30935e76acb5 Updated ALSA audio support for ALSA 0.9
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
514
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
515 /* 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
516 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
517 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
518 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
519 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
520 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
521 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
522 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
523 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
524
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
525 /* 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
526 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
527 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
528 test_format && (status < 0);) {
2060
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2049
diff changeset
529 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
530 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
531 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
532 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
533 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
534 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
535 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
536 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
537 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
538 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
539 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
540 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
541 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
542 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
543 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
544 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
545 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
546 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
547 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
548 break;
1995
0ca6ba107642 ALSA backend can handle int32 and float32 data directly.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
549 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
550 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
551 break;
0ca6ba107642 ALSA backend can handle int32 and float32 data directly.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
552 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
553 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
554 break;
0ca6ba107642 ALSA backend can handle int32 and float32 data directly.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
555 case AUDIO_F32LSB:
0ca6ba107642 ALSA backend can handle int32 and float32 data directly.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
556 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
557 break;
0ca6ba107642 ALSA backend can handle int32 and float32 data directly.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
558 case AUDIO_F32MSB:
0ca6ba107642 ALSA backend can handle int32 and float32 data directly.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
559 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
560 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
561 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
562 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
563 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
564 }
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
565 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
566 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
567 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
568 }
c121d94672cb SDL 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 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
570 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
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 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
573 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
574 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
575 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
576 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
577 }
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
578 this->spec.format = test_format;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
579
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
580 /* 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
581 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
582 this->spec.channels);
3362
4e83cdb58134 Merged r4990:4991 from branches/SDL-1.2: ALSA 1.0 API and dlvsym() removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
583 channels = 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
584 if (status < 0) {
3362
4e83cdb58134 Merged r4990:4991 from branches/SDL-1.2: ALSA 1.0 API and dlvsym() removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
585 status = ALSA_snd_pcm_hw_params_get_channels(hwparams, &channels);
4e83cdb58134 Merged r4990:4991 from branches/SDL-1.2: ALSA 1.0 API and dlvsym() removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
586 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
587 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
588 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
589 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
590 }
3362
4e83cdb58134 Merged r4990:4991 from branches/SDL-1.2: ALSA 1.0 API and dlvsym() removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
591 this->spec.channels = 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
592 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
593
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
594 /* Set the audio rate */
3362
4e83cdb58134 Merged r4990:4991 from branches/SDL-1.2: ALSA 1.0 API and dlvsym() removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
595 rate = this->spec.freq;
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
596 status = ALSA_snd_pcm_hw_params_set_rate_near(pcm_handle, hwparams,
3362
4e83cdb58134 Merged r4990:4991 from branches/SDL-1.2: ALSA 1.0 API and dlvsym() removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
597 &rate, 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
598 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
599 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
600 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
601 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
602 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
603 }
3362
4e83cdb58134 Merged r4990:4991 from branches/SDL-1.2: ALSA 1.0 API and dlvsym() removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
604 this->spec.freq = rate;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
605
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
606 /* Set the buffer size, in samples */
3627
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
607 if ( ALSA_set_period_size(this, hwparams, 0) < 0 &&
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
608 ALSA_set_buffer_size(this, hwparams, 0) < 0 ) {
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
609 /* Failed to set desired buffer size, do the best you can... */
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
610 if ( ALSA_set_period_size(this, hwparams, 1) < 0 ) {
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
611 ALSA_CloseDevice(this);
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
612 SDL_SetError("Couldn't set hardware audio parameters: %s", ALSA_snd_strerror(status));
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
613 return(-1);
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
614 }
3362
4e83cdb58134 Merged r4990:4991 from branches/SDL-1.2: ALSA 1.0 API and dlvsym() removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
615 }
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
616 /* 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
617 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
618 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
619 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
620 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
621 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
622 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
623 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
624 }
2060
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2049
diff changeset
625 status =
3627
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
626 ALSA_snd_pcm_sw_params_set_start_threshold(pcm_handle, swparams, 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
627 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
628 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
629 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
630 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
631 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
632 }
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
633 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
634 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
635 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
636 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
637 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
638 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
639 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
640
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
641 /* 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
642 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
643
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1878
diff changeset
644 /* 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
645 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
646 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
647 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
648 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
649 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
650 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
651 }
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
652 SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
653
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
654 /* 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
655 ALSA_snd_pcm_nonblock(pcm_handle, 0);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
656
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
657 /* 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
658 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
659 }
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
660
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
661 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
662 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
663 {
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
664 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
665 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
666
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
667 static int
2060
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2049
diff changeset
668 ALSA_Init(SDL_AudioDriverImpl * impl)
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
669 {
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
670 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
671 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
672 }
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
673
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
674 /* 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
675 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
676 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
677 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
678 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
679 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
680 impl->Deinitialize = ALSA_Deinitialize;
2060
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2049
diff changeset
681 impl->OnlyHasDefaultOutputDevice = 1; /* !!! FIXME: Add device enum! */
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
682
3699
4160ba33b597 Removed test for "driver is valid, but doesn't see any audio devices."
Ryan C. Gordon <icculus@icculus.org>
parents: 3697
diff changeset
683 return 1; /* this audio target is available. */
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
684 }
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
685
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
686
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
687 AudioBootStrap ALSA_bootstrap = {
3627
631173ffd68f Merged r4991:5154 from branches/SDL-1.2/src/audio/alsa: many 1.2.14 ALSA fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 3362
diff changeset
688 DRIVER_NAME, "ALSA PCM audio", ALSA_Init, 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
689 };
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
690
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
691 /* vi: set ts=4 sw=4 expandtab: */