annotate src/audio/alsa/SDL_alsa_audio.c @ 1702:a7ad7081b977 SDL-1.3

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