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