author | Ryan C. Gordon <icculus@icculus.org> |
Fri, 12 Feb 2010 16:59:34 +0000 | |
branch | SDL-1.2 |
changeset 4402 | ed7b8e3520b5 |
parent 4365 | d91a8026e0aa |
child 5621 | 8b2b7f4009e5 |
permissions | -rw-r--r-- |
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 |
||
46 |
/* Audio driver functions */ |
|
354
30935e76acb5
Updated ALSA audio support for ALSA 0.9
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
47 |
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
|
48 |
static void ALSA_WaitAudio(_THIS); |
30935e76acb5
Updated ALSA audio support for ALSA 0.9
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
49 |
static void ALSA_PlayAudio(_THIS); |
30935e76acb5
Updated ALSA audio support for ALSA 0.9
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
50 |
static Uint8 *ALSA_GetAudioBuf(_THIS); |
30935e76acb5
Updated ALSA audio support for ALSA 0.9
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
51 |
static void ALSA_CloseAudio(_THIS); |
0 | 52 |
|
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
53 |
#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
|
54 |
|
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
55 |
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
|
56 |
static void *alsa_handle = NULL; |
92615154bb68
Date: Sun, 29 Feb 2004 15:14:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
57 |
static int alsa_loaded = 0; |
92615154bb68
Date: Sun, 29 Feb 2004 15:14:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
58 |
|
92615154bb68
Date: Sun, 29 Feb 2004 15:14:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
59 |
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
|
60 |
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
|
61 |
static snd_pcm_sframes_t (*SDL_NAME(snd_pcm_writei))(snd_pcm_t *pcm, const void *buffer, snd_pcm_uframes_t size); |
4358
df306a61a61d
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4357
diff
changeset
|
62 |
static int (*SDL_NAME(snd_pcm_recover))(snd_pcm_t *pcm, int err, int silent); |
865
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_prepare))(snd_pcm_t *pcm); |
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_drain))(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 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
|
66 |
static size_t (*SDL_NAME(snd_pcm_hw_params_sizeof))(void); |
1552 | 67 |
static size_t (*SDL_NAME(snd_pcm_sw_params_sizeof))(void); |
4357
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
68 |
static void (*SDL_NAME(snd_pcm_hw_params_copy))(snd_pcm_hw_params_t *dst, const snd_pcm_hw_params_t *src); |
865
92615154bb68
Date: Sun, 29 Feb 2004 15:14:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
69 |
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
|
70 |
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
|
71 |
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
|
72 |
static int (*SDL_NAME(snd_pcm_hw_params_set_channels))(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val); |
4331
a24454ed4ac4
Fixed debug code to print correct values
Sam Lantinga <slouken@libsdl.org>
parents:
4329
diff
changeset
|
73 |
static int (*SDL_NAME(snd_pcm_hw_params_get_channels))(const 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
|
74 |
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
|
75 |
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); |
4331
a24454ed4ac4
Fixed debug code to print correct values
Sam Lantinga <slouken@libsdl.org>
parents:
4329
diff
changeset
|
76 |
static int (*SDL_NAME(snd_pcm_hw_params_get_period_size))(const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *frames, int *dir); |
4292
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_periods_near))(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir); |
4331
a24454ed4ac4
Fixed debug code to print correct values
Sam Lantinga <slouken@libsdl.org>
parents:
4329
diff
changeset
|
78 |
static int (*SDL_NAME(snd_pcm_hw_params_get_periods))(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir); |
4333
55717a755897
Switched from setting the period size and count to setting the buffer size directly, based on feedback from the ALSA development list:
Sam Lantinga <slouken@libsdl.org>
parents:
4332
diff
changeset
|
79 |
static int (*SDL_NAME(snd_pcm_hw_params_set_buffer_size_near))(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val); |
4331
a24454ed4ac4
Fixed debug code to print correct values
Sam Lantinga <slouken@libsdl.org>
parents:
4329
diff
changeset
|
80 |
static int (*SDL_NAME(snd_pcm_hw_params_get_buffer_size))(const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val); |
865
92615154bb68
Date: Sun, 29 Feb 2004 15:14:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
81 |
static int (*SDL_NAME(snd_pcm_hw_params))(snd_pcm_t *pcm, snd_pcm_hw_params_t *params); |
1552 | 82 |
/* |
83 |
*/ |
|
84 |
static int (*SDL_NAME(snd_pcm_sw_params_current))(snd_pcm_t *pcm, snd_pcm_sw_params_t *swparams); |
|
85 |
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); |
|
86 |
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
|
87 |
static int (*SDL_NAME(snd_pcm_nonblock))(snd_pcm_t *pcm, int nonblock); |
4363
028d26915548
Added an untested code path for snd_pcm_wait()
Sam Lantinga <slouken@libsdl.org>
parents:
4362
diff
changeset
|
88 |
static int (*SDL_NAME(snd_pcm_wait))(snd_pcm_t *pcm, int timeout); |
865
92615154bb68
Date: Sun, 29 Feb 2004 15:14:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
89 |
#define snd_pcm_hw_params_sizeof SDL_NAME(snd_pcm_hw_params_sizeof) |
1552 | 90 |
#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
|
91 |
|
1161
05d4b93b911e
Placate gcc's strict aliasing rules with an extra cast.
Ryan C. Gordon <icculus@icculus.org>
parents:
942
diff
changeset
|
92 |
/* 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
|
93 |
static struct { |
92615154bb68
Date: Sun, 29 Feb 2004 15:14:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
94 |
const char *name; |
92615154bb68
Date: Sun, 29 Feb 2004 15:14:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
95 |
void **func; |
92615154bb68
Date: Sun, 29 Feb 2004 15:14:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
96 |
} alsa_functions[] = { |
1161
05d4b93b911e
Placate gcc's strict aliasing rules with an extra cast.
Ryan C. Gordon <icculus@icculus.org>
parents:
942
diff
changeset
|
97 |
{ "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
|
98 |
{ "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
|
99 |
{ "snd_pcm_writei", (void**)(char*)&SDL_NAME(snd_pcm_writei) }, |
4358
df306a61a61d
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4357
diff
changeset
|
100 |
{ "snd_pcm_recover", (void**)(char*)&SDL_NAME(snd_pcm_recover) }, |
1161
05d4b93b911e
Placate gcc's strict aliasing rules with an extra cast.
Ryan C. Gordon <icculus@icculus.org>
parents:
942
diff
changeset
|
101 |
{ "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
|
102 |
{ "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
|
103 |
{ "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
|
104 |
{ "snd_pcm_hw_params_sizeof", (void**)(char*)&SDL_NAME(snd_pcm_hw_params_sizeof) }, |
1552 | 105 |
{ "snd_pcm_sw_params_sizeof", (void**)(char*)&SDL_NAME(snd_pcm_sw_params_sizeof) }, |
4357
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
106 |
{ "snd_pcm_hw_params_copy", (void**)(char*)&SDL_NAME(snd_pcm_hw_params_copy) }, |
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) }, |
4333
55717a755897
Switched from setting the period size and count to setting the buffer size directly, based on feedback from the ALSA development list:
Sam Lantinga <slouken@libsdl.org>
parents:
4332
diff
changeset
|
117 |
{ "snd_pcm_hw_params_set_buffer_size_near", (void**)(char*)&SDL_NAME(snd_pcm_hw_params_set_buffer_size_near) }, |
4331
a24454ed4ac4
Fixed debug code to print correct values
Sam Lantinga <slouken@libsdl.org>
parents:
4329
diff
changeset
|
118 |
{ "snd_pcm_hw_params_get_buffer_size", (void**)(char*)&SDL_NAME(snd_pcm_hw_params_get_buffer_size) }, |
1161
05d4b93b911e
Placate gcc's strict aliasing rules with an extra cast.
Ryan C. Gordon <icculus@icculus.org>
parents:
942
diff
changeset
|
119 |
{ "snd_pcm_hw_params", (void**)(char*)&SDL_NAME(snd_pcm_hw_params) }, |
1552 | 120 |
{ "snd_pcm_sw_params_current", (void**)(char*)&SDL_NAME(snd_pcm_sw_params_current) }, |
121 |
{ "snd_pcm_sw_params_set_start_threshold", (void**)(char*)&SDL_NAME(snd_pcm_sw_params_set_start_threshold) }, |
|
122 |
{ "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
|
123 |
{ "snd_pcm_nonblock", (void**)(char*)&SDL_NAME(snd_pcm_nonblock) }, |
4363
028d26915548
Added an untested code path for snd_pcm_wait()
Sam Lantinga <slouken@libsdl.org>
parents:
4362
diff
changeset
|
124 |
{ "snd_pcm_wait", (void**)(char*)&SDL_NAME(snd_pcm_wait) }, |
865
92615154bb68
Date: Sun, 29 Feb 2004 15:14:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
125 |
}; |
92615154bb68
Date: Sun, 29 Feb 2004 15:14:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
126 |
|
92615154bb68
Date: Sun, 29 Feb 2004 15:14:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
127 |
static void UnloadALSALibrary(void) { |
92615154bb68
Date: Sun, 29 Feb 2004 15:14:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
128 |
if (alsa_loaded) { |
4292
464126f4c7db
Moved to stable ALSA API.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
129 |
SDL_UnloadObject(alsa_handle); |
865
92615154bb68
Date: Sun, 29 Feb 2004 15:14:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
130 |
alsa_handle = NULL; |
92615154bb68
Date: Sun, 29 Feb 2004 15:14:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
131 |
alsa_loaded = 0; |
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 |
} |
92615154bb68
Date: Sun, 29 Feb 2004 15:14:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
134 |
|
92615154bb68
Date: Sun, 29 Feb 2004 15:14:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
135 |
static int LoadALSALibrary(void) { |
92615154bb68
Date: Sun, 29 Feb 2004 15:14:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
136 |
int i, retval = -1; |
92615154bb68
Date: Sun, 29 Feb 2004 15:14:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
137 |
|
4292
464126f4c7db
Moved to stable ALSA API.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
138 |
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
|
139 |
if (alsa_handle) { |
92615154bb68
Date: Sun, 29 Feb 2004 15:14:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
140 |
alsa_loaded = 1; |
92615154bb68
Date: Sun, 29 Feb 2004 15:14:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
141 |
retval = 0; |
1379
c0a74f199ecf
Use only safe string functions
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
142 |
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
|
143 |
*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
|
144 |
if (!*alsa_functions[i].func) { |
92615154bb68
Date: Sun, 29 Feb 2004 15:14:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
145 |
retval = -1; |
92615154bb68
Date: Sun, 29 Feb 2004 15:14:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
146 |
UnloadALSALibrary(); |
92615154bb68
Date: Sun, 29 Feb 2004 15:14:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
147 |
break; |
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 |
} |
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 |
return retval; |
92615154bb68
Date: Sun, 29 Feb 2004 15:14:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
152 |
} |
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 |
#else |
92615154bb68
Date: Sun, 29 Feb 2004 15:14:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
155 |
|
92615154bb68
Date: Sun, 29 Feb 2004 15:14:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
156 |
static void UnloadALSALibrary(void) { |
92615154bb68
Date: Sun, 29 Feb 2004 15:14:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
157 |
return; |
92615154bb68
Date: Sun, 29 Feb 2004 15:14:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
158 |
} |
92615154bb68
Date: Sun, 29 Feb 2004 15:14:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
159 |
|
92615154bb68
Date: Sun, 29 Feb 2004 15:14:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
160 |
static int LoadALSALibrary(void) { |
92615154bb68
Date: Sun, 29 Feb 2004 15:14:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
161 |
return 0; |
92615154bb68
Date: Sun, 29 Feb 2004 15:14:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
162 |
} |
92615154bb68
Date: Sun, 29 Feb 2004 15:14:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
163 |
|
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
164 |
#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
|
165 |
|
942
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
939
diff
changeset
|
166 |
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
|
167 |
{ |
30935e76acb5
Updated ALSA audio support for ALSA 0.9
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
168 |
const char *device; |
30935e76acb5
Updated ALSA audio support for ALSA 0.9
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
169 |
|
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1331
diff
changeset
|
170 |
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
|
171 |
if ( device == NULL ) { |
4334
afadcd7d2319
Use the plug: ALSA devices for surround sound formats, which have automatic sample format/rate conversion.
Sam Lantinga <slouken@libsdl.org>
parents:
4333
diff
changeset
|
172 |
switch (channels) { |
afadcd7d2319
Use the plug: ALSA devices for surround sound formats, which have automatic sample format/rate conversion.
Sam Lantinga <slouken@libsdl.org>
parents:
4333
diff
changeset
|
173 |
case 6: |
afadcd7d2319
Use the plug: ALSA devices for surround sound formats, which have automatic sample format/rate conversion.
Sam Lantinga <slouken@libsdl.org>
parents:
4333
diff
changeset
|
174 |
device = "plug:surround51"; |
afadcd7d2319
Use the plug: ALSA devices for surround sound formats, which have automatic sample format/rate conversion.
Sam Lantinga <slouken@libsdl.org>
parents:
4333
diff
changeset
|
175 |
break; |
afadcd7d2319
Use the plug: ALSA devices for surround sound formats, which have automatic sample format/rate conversion.
Sam Lantinga <slouken@libsdl.org>
parents:
4333
diff
changeset
|
176 |
case 4: |
afadcd7d2319
Use the plug: ALSA devices for surround sound formats, which have automatic sample format/rate conversion.
Sam Lantinga <slouken@libsdl.org>
parents:
4333
diff
changeset
|
177 |
device = "plug:surround40"; |
afadcd7d2319
Use the plug: ALSA devices for surround sound formats, which have automatic sample format/rate conversion.
Sam Lantinga <slouken@libsdl.org>
parents:
4333
diff
changeset
|
178 |
break; |
afadcd7d2319
Use the plug: ALSA devices for surround sound formats, which have automatic sample format/rate conversion.
Sam Lantinga <slouken@libsdl.org>
parents:
4333
diff
changeset
|
179 |
default: |
afadcd7d2319
Use the plug: ALSA devices for surround sound formats, which have automatic sample format/rate conversion.
Sam Lantinga <slouken@libsdl.org>
parents:
4333
diff
changeset
|
180 |
device = "default"; |
afadcd7d2319
Use the plug: ALSA devices for surround sound formats, which have automatic sample format/rate conversion.
Sam Lantinga <slouken@libsdl.org>
parents:
4333
diff
changeset
|
181 |
break; |
afadcd7d2319
Use the plug: ALSA devices for surround sound formats, which have automatic sample format/rate conversion.
Sam Lantinga <slouken@libsdl.org>
parents:
4333
diff
changeset
|
182 |
} |
354
30935e76acb5
Updated ALSA audio support for ALSA 0.9
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
183 |
} |
30935e76acb5
Updated ALSA audio support for ALSA 0.9
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
184 |
return device; |
0 | 185 |
} |
186 |
||
187 |
/* Audio driver bootstrap functions */ |
|
188 |
||
189 |
static int Audio_Available(void) |
|
190 |
{ |
|
191 |
int available; |
|
354
30935e76acb5
Updated ALSA audio support for ALSA 0.9
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
192 |
int status; |
0 | 193 |
snd_pcm_t *handle; |
194 |
||
195 |
available = 0; |
|
865
92615154bb68
Date: Sun, 29 Feb 2004 15:14:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
196 |
if (LoadALSALibrary() < 0) { |
92615154bb68
Date: Sun, 29 Feb 2004 15:14:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
197 |
return available; |
92615154bb68
Date: Sun, 29 Feb 2004 15:14:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
198 |
} |
942
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
939
diff
changeset
|
199 |
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
|
200 |
if ( status >= 0 ) { |
30935e76acb5
Updated ALSA audio support for ALSA 0.9
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
201 |
available = 1; |
865
92615154bb68
Date: Sun, 29 Feb 2004 15:14:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
202 |
SDL_NAME(snd_pcm_close)(handle); |
0 | 203 |
} |
865
92615154bb68
Date: Sun, 29 Feb 2004 15:14:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
204 |
UnloadALSALibrary(); |
0 | 205 |
return(available); |
206 |
} |
|
207 |
||
208 |
static void Audio_DeleteDevice(SDL_AudioDevice *device) |
|
209 |
{ |
|
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1331
diff
changeset
|
210 |
SDL_free(device->hidden); |
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1331
diff
changeset
|
211 |
SDL_free(device); |
865
92615154bb68
Date: Sun, 29 Feb 2004 15:14:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
212 |
UnloadALSALibrary(); |
0 | 213 |
} |
214 |
||
215 |
static SDL_AudioDevice *Audio_CreateDevice(int devindex) |
|
216 |
{ |
|
217 |
SDL_AudioDevice *this; |
|
218 |
||
219 |
/* 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
|
220 |
LoadALSALibrary(); |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1331
diff
changeset
|
221 |
this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice)); |
0 | 222 |
if ( this ) { |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1331
diff
changeset
|
223 |
SDL_memset(this, 0, (sizeof *this)); |
0 | 224 |
this->hidden = (struct SDL_PrivateAudioData *) |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1331
diff
changeset
|
225 |
SDL_malloc((sizeof *this->hidden)); |
0 | 226 |
} |
227 |
if ( (this == NULL) || (this->hidden == NULL) ) { |
|
228 |
SDL_OutOfMemory(); |
|
229 |
if ( this ) { |
|
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1331
diff
changeset
|
230 |
SDL_free(this); |
0 | 231 |
} |
232 |
return(0); |
|
233 |
} |
|
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1331
diff
changeset
|
234 |
SDL_memset(this->hidden, 0, (sizeof *this->hidden)); |
0 | 235 |
|
236 |
/* Set the function pointers */ |
|
354
30935e76acb5
Updated ALSA audio support for ALSA 0.9
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
237 |
this->OpenAudio = ALSA_OpenAudio; |
30935e76acb5
Updated ALSA audio support for ALSA 0.9
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
238 |
this->WaitAudio = ALSA_WaitAudio; |
30935e76acb5
Updated ALSA audio support for ALSA 0.9
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
239 |
this->PlayAudio = ALSA_PlayAudio; |
30935e76acb5
Updated ALSA audio support for ALSA 0.9
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
240 |
this->GetAudioBuf = ALSA_GetAudioBuf; |
30935e76acb5
Updated ALSA audio support for ALSA 0.9
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
241 |
this->CloseAudio = ALSA_CloseAudio; |
0 | 242 |
|
243 |
this->free = Audio_DeleteDevice; |
|
244 |
||
245 |
return this; |
|
246 |
} |
|
247 |
||
248 |
AudioBootStrap ALSA_bootstrap = { |
|
4339
819270e2f893
Don't call it "ALSA 0.9 PCM audio" anymore, since we moved to the stable API.
Ryan C. Gordon <icculus@icculus.org>
parents:
4337
diff
changeset
|
249 |
DRIVER_NAME, "ALSA PCM audio", |
0 | 250 |
Audio_Available, Audio_CreateDevice |
251 |
}; |
|
252 |
||
253 |
/* 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
|
254 |
static void ALSA_WaitAudio(_THIS) |
0 | 255 |
{ |
4359
4b582c04ec1d
Recoomendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4358
diff
changeset
|
256 |
/* We're in blocking mode, so there's nothing to do here */ |
0 | 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 |
Uint32 i; \ |
4402
ed7b8e3520b5
Fixed channel swizzling for ALSA target with 6-channel output.
Ryan C. Gordon <icculus@icculus.org>
parents:
4365
diff
changeset
|
268 |
for (i = 0; i < this->spec.samples; i++, ptr += 6) { \ |
1878
d7c9d7f42881
Swizzle ALSA channels for 5.1 output to match DirectSound and CoreAudio.
Ryan C. Gordon <icculus@icculus.org>
parents:
1553
diff
changeset
|
269 |
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
|
270 |
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
|
271 |
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
|
272 |
} |
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 |
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
|
275 |
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
|
276 |
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
|
277 |
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
|
278 |
|
d7c9d7f42881
Swizzle ALSA channels for 5.1 output to match DirectSound and CoreAudio.
Ryan C. Gordon <icculus@icculus.org>
parents:
1553
diff
changeset
|
279 |
#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
|
280 |
|
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 |
* 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
|
284 |
* 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
|
285 |
*/ |
d7c9d7f42881
Swizzle ALSA channels for 5.1 output to match DirectSound and CoreAudio.
Ryan C. Gordon <icculus@icculus.org>
parents:
1553
diff
changeset
|
286 |
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
|
287 |
{ |
d7c9d7f42881
Swizzle ALSA channels for 5.1 output to match DirectSound and CoreAudio.
Ryan C. Gordon <icculus@icculus.org>
parents:
1553
diff
changeset
|
288 |
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
|
289 |
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
|
290 |
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
|
291 |
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
|
292 |
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
|
293 |
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
|
294 |
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
|
295 |
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
|
296 |
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
|
297 |
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
|
298 |
} |
d7c9d7f42881
Swizzle ALSA channels for 5.1 output to match DirectSound and CoreAudio.
Ryan C. Gordon <icculus@icculus.org>
parents:
1553
diff
changeset
|
299 |
|
d7c9d7f42881
Swizzle ALSA channels for 5.1 output to match DirectSound and CoreAudio.
Ryan C. Gordon <icculus@icculus.org>
parents:
1553
diff
changeset
|
300 |
/* !!! 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
|
301 |
} |
d7c9d7f42881
Swizzle ALSA channels for 5.1 output to match DirectSound and CoreAudio.
Ryan C. Gordon <icculus@icculus.org>
parents:
1553
diff
changeset
|
302 |
|
d7c9d7f42881
Swizzle ALSA channels for 5.1 output to match DirectSound and CoreAudio.
Ryan C. Gordon <icculus@icculus.org>
parents:
1553
diff
changeset
|
303 |
|
354
30935e76acb5
Updated ALSA audio support for ALSA 0.9
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
304 |
static void ALSA_PlayAudio(_THIS) |
0 | 305 |
{ |
4320
33d306630296
Corrected misuse of snd_pcm_writei() in ALSA driver.
Ryan C. Gordon <icculus@icculus.org>
parents:
4292
diff
changeset
|
306 |
int status; |
4332
67e799ffcadf
ALSA's idea of a "frame" is the same as SDL's idea of a "sample". The frame is a single sample on a single channel, and we've defined the frames for each channel as being interleaved.
Sam Lantinga <slouken@libsdl.org>
parents:
4331
diff
changeset
|
307 |
snd_pcm_uframes_t frames_left; |
4320
33d306630296
Corrected misuse of snd_pcm_writei() in ALSA driver.
Ryan C. Gordon <icculus@icculus.org>
parents:
4292
diff
changeset
|
308 |
const Uint8 *sample_buf = (const Uint8 *) mixbuf; |
4336
77b20871fd44
Thilo helped me track down the audio issue with 22050 hz stereo sound. Yay!
Sam Lantinga <slouken@libsdl.org>
parents:
4334
diff
changeset
|
309 |
const int frame_size = (((int) (this->spec.format & 0xFF)) / 8) * this->spec.channels; |
765
4c2ba6161939
Editors Note: The original patch was modified to use SDL_Delay() instead of
Sam Lantinga <slouken@libsdl.org>
parents:
547
diff
changeset
|
310 |
|
1878
d7c9d7f42881
Swizzle ALSA channels for 5.1 output to match DirectSound and CoreAudio.
Ryan C. Gordon <icculus@icculus.org>
parents:
1553
diff
changeset
|
311 |
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
|
312 |
|
4332
67e799ffcadf
ALSA's idea of a "frame" is the same as SDL's idea of a "sample". The frame is a single sample on a single channel, and we've defined the frames for each channel as being interleaved.
Sam Lantinga <slouken@libsdl.org>
parents:
4331
diff
changeset
|
313 |
frames_left = ((snd_pcm_uframes_t) this->spec.samples); |
1878
d7c9d7f42881
Swizzle ALSA channels for 5.1 output to match DirectSound and CoreAudio.
Ryan C. Gordon <icculus@icculus.org>
parents:
1553
diff
changeset
|
314 |
|
4337 | 315 |
while ( frames_left > 0 && this->enabled ) { |
4363
028d26915548
Added an untested code path for snd_pcm_wait()
Sam Lantinga <slouken@libsdl.org>
parents:
4362
diff
changeset
|
316 |
/* This works, but needs more testing before going live */ |
028d26915548
Added an untested code path for snd_pcm_wait()
Sam Lantinga <slouken@libsdl.org>
parents:
4362
diff
changeset
|
317 |
/*SDL_NAME(snd_pcm_wait)(pcm_handle, -1);*/ |
028d26915548
Added an untested code path for snd_pcm_wait()
Sam Lantinga <slouken@libsdl.org>
parents:
4362
diff
changeset
|
318 |
|
4332
67e799ffcadf
ALSA's idea of a "frame" is the same as SDL's idea of a "sample". The frame is a single sample on a single channel, and we've defined the frames for each channel as being interleaved.
Sam Lantinga <slouken@libsdl.org>
parents:
4331
diff
changeset
|
319 |
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
|
320 |
if ( status < 0 ) { |
4362
e48a66bed093
ALSA write failed (unrecoverable): Resource temporarily unavailable
Sam Lantinga <slouken@libsdl.org>
parents:
4361
diff
changeset
|
321 |
if ( status == -EAGAIN ) { |
4363
028d26915548
Added an untested code path for snd_pcm_wait()
Sam Lantinga <slouken@libsdl.org>
parents:
4362
diff
changeset
|
322 |
/* Apparently snd_pcm_recover() doesn't handle this case - does it assume snd_pcm_wait() above? */ |
4362
e48a66bed093
ALSA write failed (unrecoverable): Resource temporarily unavailable
Sam Lantinga <slouken@libsdl.org>
parents:
4361
diff
changeset
|
323 |
SDL_Delay(1); |
e48a66bed093
ALSA write failed (unrecoverable): Resource temporarily unavailable
Sam Lantinga <slouken@libsdl.org>
parents:
4361
diff
changeset
|
324 |
continue; |
e48a66bed093
ALSA write failed (unrecoverable): Resource temporarily unavailable
Sam Lantinga <slouken@libsdl.org>
parents:
4361
diff
changeset
|
325 |
} |
4361
991e4bcfc7a8
Added an error message for when ALSA audio fails
Sam Lantinga <slouken@libsdl.org>
parents:
4360
diff
changeset
|
326 |
status = SDL_NAME(snd_pcm_recover)(pcm_handle, status, 0); |
991e4bcfc7a8
Added an error message for when ALSA audio fails
Sam Lantinga <slouken@libsdl.org>
parents:
4360
diff
changeset
|
327 |
if ( status < 0 ) { |
354
30935e76acb5
Updated ALSA audio support for ALSA 0.9
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
328 |
/* Hmm, not much we can do - abort */ |
4364
ae3d564e2716
Whoops, missing newline!
Sam Lantinga <slouken@libsdl.org>
parents:
4363
diff
changeset
|
329 |
fprintf(stderr, "ALSA write failed (unrecoverable): %s\n", SDL_NAME(snd_strerror)(status)); |
354
30935e76acb5
Updated ALSA audio support for ALSA 0.9
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
330 |
this->enabled = 0; |
30935e76acb5
Updated ALSA audio support for ALSA 0.9
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
331 |
return; |
0 | 332 |
} |
356
a1e54d1ba16f
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
354
diff
changeset
|
333 |
continue; |
0 | 334 |
} |
4336
77b20871fd44
Thilo helped me track down the audio issue with 22050 hz stereo sound. Yay!
Sam Lantinga <slouken@libsdl.org>
parents:
4334
diff
changeset
|
335 |
sample_buf += status * frame_size; |
4332
67e799ffcadf
ALSA's idea of a "frame" is the same as SDL's idea of a "sample". The frame is a single sample on a single channel, and we've defined the frames for each channel as being interleaved.
Sam Lantinga <slouken@libsdl.org>
parents:
4331
diff
changeset
|
336 |
frames_left -= status; |
0 | 337 |
} |
338 |
} |
|
339 |
||
354
30935e76acb5
Updated ALSA audio support for ALSA 0.9
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
340 |
static Uint8 *ALSA_GetAudioBuf(_THIS) |
0 | 341 |
{ |
354
30935e76acb5
Updated ALSA audio support for ALSA 0.9
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
342 |
return(mixbuf); |
0 | 343 |
} |
344 |
||
354
30935e76acb5
Updated ALSA audio support for ALSA 0.9
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
345 |
static void ALSA_CloseAudio(_THIS) |
0 | 346 |
{ |
354
30935e76acb5
Updated ALSA audio support for ALSA 0.9
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
347 |
if ( mixbuf != NULL ) { |
30935e76acb5
Updated ALSA audio support for ALSA 0.9
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
348 |
SDL_FreeAudioMem(mixbuf); |
30935e76acb5
Updated ALSA audio support for ALSA 0.9
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
349 |
mixbuf = NULL; |
0 | 350 |
} |
354
30935e76acb5
Updated ALSA audio support for ALSA 0.9
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
351 |
if ( pcm_handle ) { |
865
92615154bb68
Date: Sun, 29 Feb 2004 15:14:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
352 |
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
|
353 |
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
|
354 |
pcm_handle = NULL; |
0 | 355 |
} |
356 |
} |
|
357 |
||
4357
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
358 |
static int ALSA_finalize_hardware(_THIS, SDL_AudioSpec *spec, snd_pcm_hw_params_t *hwparams, int override) |
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
359 |
{ |
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
360 |
int status; |
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
361 |
snd_pcm_uframes_t bufsize; |
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
362 |
|
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
363 |
/* "set" the hardware with the desired parameters */ |
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
364 |
status = SDL_NAME(snd_pcm_hw_params)(pcm_handle, hwparams); |
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
365 |
if ( status < 0 ) { |
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
366 |
return(-1); |
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
367 |
} |
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
368 |
|
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
369 |
/* Get samples for the actual buffer size */ |
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
370 |
status = SDL_NAME(snd_pcm_hw_params_get_buffer_size)(hwparams, &bufsize); |
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
371 |
if ( status < 0 ) { |
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
372 |
return(-1); |
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
373 |
} |
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
374 |
if ( !override && bufsize != spec->samples * 2 ) { |
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
375 |
return(-1); |
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
376 |
} |
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
377 |
|
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
378 |
/* FIXME: Is this safe to do? */ |
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
379 |
spec->samples = bufsize / 2; |
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
380 |
|
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
381 |
/* This is useful for debugging */ |
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
382 |
if ( getenv("SDL_AUDIO_ALSA_DEBUG") ) { |
4365 | 383 |
snd_pcm_uframes_t persize = 0; |
4357
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
384 |
unsigned int periods = 0; |
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
385 |
|
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
386 |
SDL_NAME(snd_pcm_hw_params_get_period_size)(hwparams, &persize, NULL); |
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
387 |
SDL_NAME(snd_pcm_hw_params_get_periods)(hwparams, &periods, NULL); |
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
388 |
|
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
389 |
fprintf(stderr, "ALSA: period size = %ld, periods = %u, buffer size = %lu\n", persize, periods, bufsize); |
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
390 |
} |
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
391 |
return(0); |
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
392 |
} |
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
393 |
|
4360
be2dff2f79c0
Getting as close as you can with periods is better than the default parameters.
Sam Lantinga <slouken@libsdl.org>
parents:
4359
diff
changeset
|
394 |
static int ALSA_set_period_size(_THIS, SDL_AudioSpec *spec, snd_pcm_hw_params_t *params, int override) |
4357
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
395 |
{ |
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
396 |
const char *env; |
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
397 |
int status; |
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
398 |
snd_pcm_hw_params_t *hwparams; |
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
399 |
snd_pcm_uframes_t frames; |
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
400 |
unsigned int periods; |
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
401 |
|
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
402 |
/* Copy the hardware parameters for this setup */ |
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
403 |
snd_pcm_hw_params_alloca(&hwparams); |
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
404 |
SDL_NAME(snd_pcm_hw_params_copy)(hwparams, params); |
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
405 |
|
4360
be2dff2f79c0
Getting as close as you can with periods is better than the default parameters.
Sam Lantinga <slouken@libsdl.org>
parents:
4359
diff
changeset
|
406 |
if ( !override ) { |
be2dff2f79c0
Getting as close as you can with periods is better than the default parameters.
Sam Lantinga <slouken@libsdl.org>
parents:
4359
diff
changeset
|
407 |
env = getenv("SDL_AUDIO_ALSA_SET_PERIOD_SIZE"); |
be2dff2f79c0
Getting as close as you can with periods is better than the default parameters.
Sam Lantinga <slouken@libsdl.org>
parents:
4359
diff
changeset
|
408 |
if ( env ) { |
be2dff2f79c0
Getting as close as you can with periods is better than the default parameters.
Sam Lantinga <slouken@libsdl.org>
parents:
4359
diff
changeset
|
409 |
override = SDL_atoi(env); |
be2dff2f79c0
Getting as close as you can with periods is better than the default parameters.
Sam Lantinga <slouken@libsdl.org>
parents:
4359
diff
changeset
|
410 |
if ( override == 0 ) { |
be2dff2f79c0
Getting as close as you can with periods is better than the default parameters.
Sam Lantinga <slouken@libsdl.org>
parents:
4359
diff
changeset
|
411 |
return(-1); |
be2dff2f79c0
Getting as close as you can with periods is better than the default parameters.
Sam Lantinga <slouken@libsdl.org>
parents:
4359
diff
changeset
|
412 |
} |
4357
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
413 |
} |
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
414 |
} |
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
415 |
|
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
416 |
frames = spec->samples; |
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
417 |
status = SDL_NAME(snd_pcm_hw_params_set_period_size_near)(pcm_handle, hwparams, &frames, NULL); |
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
418 |
if ( status < 0 ) { |
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
419 |
return(-1); |
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
420 |
} |
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
421 |
|
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
422 |
periods = 2; |
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
423 |
status = SDL_NAME(snd_pcm_hw_params_set_periods_near)(pcm_handle, hwparams, &periods, NULL); |
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
424 |
if ( status < 0 ) { |
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
425 |
return(-1); |
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
426 |
} |
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
427 |
|
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
428 |
return ALSA_finalize_hardware(this, spec, hwparams, override); |
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
429 |
} |
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
430 |
|
4360
be2dff2f79c0
Getting as close as you can with periods is better than the default parameters.
Sam Lantinga <slouken@libsdl.org>
parents:
4359
diff
changeset
|
431 |
static int ALSA_set_buffer_size(_THIS, SDL_AudioSpec *spec, snd_pcm_hw_params_t *params, int override) |
4357
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
432 |
{ |
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
433 |
const char *env; |
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
434 |
int status; |
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
435 |
snd_pcm_hw_params_t *hwparams; |
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
436 |
snd_pcm_uframes_t frames; |
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
437 |
|
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
438 |
/* Copy the hardware parameters for this setup */ |
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
439 |
snd_pcm_hw_params_alloca(&hwparams); |
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
440 |
SDL_NAME(snd_pcm_hw_params_copy)(hwparams, params); |
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
441 |
|
4360
be2dff2f79c0
Getting as close as you can with periods is better than the default parameters.
Sam Lantinga <slouken@libsdl.org>
parents:
4359
diff
changeset
|
442 |
if ( !override ) { |
be2dff2f79c0
Getting as close as you can with periods is better than the default parameters.
Sam Lantinga <slouken@libsdl.org>
parents:
4359
diff
changeset
|
443 |
env = getenv("SDL_AUDIO_ALSA_SET_BUFFER_SIZE"); |
be2dff2f79c0
Getting as close as you can with periods is better than the default parameters.
Sam Lantinga <slouken@libsdl.org>
parents:
4359
diff
changeset
|
444 |
if ( env ) { |
be2dff2f79c0
Getting as close as you can with periods is better than the default parameters.
Sam Lantinga <slouken@libsdl.org>
parents:
4359
diff
changeset
|
445 |
override = SDL_atoi(env); |
be2dff2f79c0
Getting as close as you can with periods is better than the default parameters.
Sam Lantinga <slouken@libsdl.org>
parents:
4359
diff
changeset
|
446 |
if ( override == 0 ) { |
be2dff2f79c0
Getting as close as you can with periods is better than the default parameters.
Sam Lantinga <slouken@libsdl.org>
parents:
4359
diff
changeset
|
447 |
return(-1); |
be2dff2f79c0
Getting as close as you can with periods is better than the default parameters.
Sam Lantinga <slouken@libsdl.org>
parents:
4359
diff
changeset
|
448 |
} |
4357
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
449 |
} |
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
450 |
} |
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
451 |
|
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
452 |
frames = spec->samples * 2; |
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
453 |
status = SDL_NAME(snd_pcm_hw_params_set_buffer_size_near)(pcm_handle, hwparams, &frames); |
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
454 |
if ( status < 0 ) { |
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
455 |
return(-1); |
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
456 |
} |
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
457 |
|
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
458 |
return ALSA_finalize_hardware(this, spec, hwparams, override); |
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
459 |
} |
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
460 |
|
354
30935e76acb5
Updated ALSA audio support for ALSA 0.9
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
461 |
static int ALSA_OpenAudio(_THIS, SDL_AudioSpec *spec) |
0 | 462 |
{ |
354
30935e76acb5
Updated ALSA audio support for ALSA 0.9
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
463 |
int status; |
1552 | 464 |
snd_pcm_hw_params_t *hwparams; |
465 |
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
|
466 |
snd_pcm_format_t format; |
4292
464126f4c7db
Moved to stable ALSA API.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
467 |
unsigned int rate; |
4333
55717a755897
Switched from setting the period size and count to setting the buffer size directly, based on feedback from the ALSA development list:
Sam Lantinga <slouken@libsdl.org>
parents:
4332
diff
changeset
|
468 |
unsigned int channels; |
354
30935e76acb5
Updated ALSA audio support for ALSA 0.9
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
469 |
Uint16 test_format; |
0 | 470 |
|
471 |
/* 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
|
472 |
/* 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
|
473 |
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
|
474 |
|
354
30935e76acb5
Updated ALSA audio support for ALSA 0.9
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
475 |
if ( status < 0 ) { |
865
92615154bb68
Date: Sun, 29 Feb 2004 15:14:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
476 |
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
|
477 |
return(-1); |
30935e76acb5
Updated ALSA audio support for ALSA 0.9
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
478 |
} |
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 |
/* Figure out what the hardware is capable of */ |
1552 | 481 |
snd_pcm_hw_params_alloca(&hwparams); |
482 |
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
|
483 |
if ( status < 0 ) { |
865
92615154bb68
Date: Sun, 29 Feb 2004 15:14:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
484 |
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
|
485 |
ALSA_CloseAudio(this); |
30935e76acb5
Updated ALSA audio support for ALSA 0.9
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
486 |
return(-1); |
30935e76acb5
Updated ALSA audio support for ALSA 0.9
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
487 |
} |
30935e76acb5
Updated ALSA audio support for ALSA 0.9
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
488 |
|
30935e76acb5
Updated ALSA audio support for ALSA 0.9
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
489 |
/* SDL only uses interleaved sample output */ |
1552 | 490 |
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
|
491 |
if ( status < 0 ) { |
865
92615154bb68
Date: Sun, 29 Feb 2004 15:14:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
492 |
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
|
493 |
ALSA_CloseAudio(this); |
0 | 494 |
return(-1); |
495 |
} |
|
496 |
||
497 |
/* 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
|
498 |
status = -1; |
0 | 499 |
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
|
500 |
test_format && (status < 0); ) { |
30935e76acb5
Updated ALSA audio support for ALSA 0.9
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
501 |
switch ( test_format ) { |
0 | 502 |
case AUDIO_U8: |
354
30935e76acb5
Updated ALSA audio support for ALSA 0.9
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
503 |
format = SND_PCM_FORMAT_U8; |
0 | 504 |
break; |
505 |
case AUDIO_S8: |
|
354
30935e76acb5
Updated ALSA audio support for ALSA 0.9
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
506 |
format = SND_PCM_FORMAT_S8; |
0 | 507 |
break; |
508 |
case AUDIO_S16LSB: |
|
354
30935e76acb5
Updated ALSA audio support for ALSA 0.9
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
509 |
format = SND_PCM_FORMAT_S16_LE; |
0 | 510 |
break; |
511 |
case AUDIO_S16MSB: |
|
354
30935e76acb5
Updated ALSA audio support for ALSA 0.9
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
512 |
format = SND_PCM_FORMAT_S16_BE; |
0 | 513 |
break; |
514 |
case AUDIO_U16LSB: |
|
354
30935e76acb5
Updated ALSA audio support for ALSA 0.9
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
515 |
format = SND_PCM_FORMAT_U16_LE; |
0 | 516 |
break; |
517 |
case AUDIO_U16MSB: |
|
354
30935e76acb5
Updated ALSA audio support for ALSA 0.9
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
518 |
format = SND_PCM_FORMAT_U16_BE; |
0 | 519 |
break; |
520 |
default: |
|
354
30935e76acb5
Updated ALSA audio support for ALSA 0.9
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
521 |
format = 0; |
0 | 522 |
break; |
523 |
} |
|
354
30935e76acb5
Updated ALSA audio support for ALSA 0.9
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
524 |
if ( format != 0 ) { |
1552 | 525 |
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
|
526 |
} |
30935e76acb5
Updated ALSA audio support for ALSA 0.9
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
527 |
if ( status < 0 ) { |
0 | 528 |
test_format = SDL_NextAudioFormat(); |
529 |
} |
|
530 |
} |
|
354
30935e76acb5
Updated ALSA audio support for ALSA 0.9
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
531 |
if ( status < 0 ) { |
0 | 532 |
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
|
533 |
ALSA_CloseAudio(this); |
0 | 534 |
return(-1); |
535 |
} |
|
536 |
spec->format = test_format; |
|
537 |
||
354
30935e76acb5
Updated ALSA audio support for ALSA 0.9
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
538 |
/* Set the number of channels */ |
1552 | 539 |
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
|
540 |
channels = spec->channels; |
354
30935e76acb5
Updated ALSA audio support for ALSA 0.9
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
541 |
if ( status < 0 ) { |
4292
464126f4c7db
Moved to stable ALSA API.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
542 |
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
|
543 |
if ( status < 0 ) { |
354
30935e76acb5
Updated ALSA audio support for ALSA 0.9
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
544 |
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
|
545 |
ALSA_CloseAudio(this); |
30935e76acb5
Updated ALSA audio support for ALSA 0.9
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
546 |
return(-1); |
30935e76acb5
Updated ALSA audio support for ALSA 0.9
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
547 |
} |
4292
464126f4c7db
Moved to stable ALSA API.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
548 |
spec->channels = channels; |
354
30935e76acb5
Updated ALSA audio support for ALSA 0.9
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
549 |
} |
0 | 550 |
|
354
30935e76acb5
Updated ALSA audio support for ALSA 0.9
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
551 |
/* Set the audio rate */ |
4292
464126f4c7db
Moved to stable ALSA API.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
552 |
rate = spec->freq; |
464126f4c7db
Moved to stable ALSA API.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
553 |
|
464126f4c7db
Moved to stable ALSA API.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
554 |
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
|
555 |
if ( status < 0 ) { |
865
92615154bb68
Date: Sun, 29 Feb 2004 15:14:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
556 |
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
|
557 |
ALSA_CloseAudio(this); |
30935e76acb5
Updated ALSA audio support for ALSA 0.9
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
558 |
return(-1); |
30935e76acb5
Updated ALSA audio support for ALSA 0.9
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
559 |
} |
4292
464126f4c7db
Moved to stable ALSA API.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
560 |
spec->freq = rate; |
0 | 561 |
|
354
30935e76acb5
Updated ALSA audio support for ALSA 0.9
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
562 |
/* Set the buffer size, in samples */ |
4360
be2dff2f79c0
Getting as close as you can with periods is better than the default parameters.
Sam Lantinga <slouken@libsdl.org>
parents:
4359
diff
changeset
|
563 |
if ( ALSA_set_period_size(this, spec, hwparams, 0) < 0 && |
be2dff2f79c0
Getting as close as you can with periods is better than the default parameters.
Sam Lantinga <slouken@libsdl.org>
parents:
4359
diff
changeset
|
564 |
ALSA_set_buffer_size(this, spec, hwparams, 0) < 0 ) { |
be2dff2f79c0
Getting as close as you can with periods is better than the default parameters.
Sam Lantinga <slouken@libsdl.org>
parents:
4359
diff
changeset
|
565 |
/* Failed to set desired buffer size, do the best you can... */ |
be2dff2f79c0
Getting as close as you can with periods is better than the default parameters.
Sam Lantinga <slouken@libsdl.org>
parents:
4359
diff
changeset
|
566 |
if ( ALSA_set_period_size(this, spec, hwparams, 1) < 0 ) { |
4357
a10dac5858fe
Recommendation from Lennart Poettering:
Sam Lantinga <slouken@libsdl.org>
parents:
4349
diff
changeset
|
567 |
SDL_SetError("Couldn't set hardware audio parameters: %s", SDL_NAME(snd_strerror)(status)); |
4347 | 568 |
ALSA_CloseAudio(this); |
569 |
return(-1); |
|
570 |
} |
|
4348
b312352d8c8d
Enable the ALSA debug code via environment variable
Sam Lantinga <slouken@libsdl.org>
parents:
4347
diff
changeset
|
571 |
} |
1552 | 572 |
|
573 |
/* Set the software parameters */ |
|
574 |
snd_pcm_sw_params_alloca(&swparams); |
|
575 |
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
|
576 |
if ( status < 0 ) { |
1552 | 577 |
SDL_SetError("Couldn't get software config: %s", SDL_NAME(snd_strerror)(status)); |
578 |
ALSA_CloseAudio(this); |
|
579 |
return(-1); |
|
580 |
} |
|
4331
a24454ed4ac4
Fixed debug code to print correct values
Sam Lantinga <slouken@libsdl.org>
parents:
4329
diff
changeset
|
581 |
status = SDL_NAME(snd_pcm_sw_params_set_start_threshold)(pcm_handle, swparams, 1); |
1552 | 582 |
if ( status < 0 ) { |
583 |
SDL_SetError("Couldn't set start threshold: %s", SDL_NAME(snd_strerror)(status)); |
|
584 |
ALSA_CloseAudio(this); |
|
585 |
return(-1); |
|
586 |
} |
|
587 |
status = SDL_NAME(snd_pcm_sw_params)(pcm_handle, swparams); |
|
588 |
if ( status < 0 ) { |
|
589 |
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
|
590 |
ALSA_CloseAudio(this); |
0 | 591 |
return(-1); |
592 |
} |
|
593 |
||
354
30935e76acb5
Updated ALSA audio support for ALSA 0.9
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
594 |
/* 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
|
595 |
SDL_CalculateAudioSpec(spec); |
0 | 596 |
|
354
30935e76acb5
Updated ALSA audio support for ALSA 0.9
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
597 |
/* Allocate mixing buffer */ |
30935e76acb5
Updated ALSA audio support for ALSA 0.9
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
598 |
mixlen = spec->size; |
30935e76acb5
Updated ALSA audio support for ALSA 0.9
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
599 |
mixbuf = (Uint8 *)SDL_AllocAudioMem(mixlen); |
30935e76acb5
Updated ALSA audio support for ALSA 0.9
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
600 |
if ( mixbuf == NULL ) { |
30935e76acb5
Updated ALSA audio support for ALSA 0.9
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
601 |
ALSA_CloseAudio(this); |
30935e76acb5
Updated ALSA audio support for ALSA 0.9
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
602 |
return(-1); |
0 | 603 |
} |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1331
diff
changeset
|
604 |
SDL_memset(mixbuf, spec->silence, spec->size); |
0 | 605 |
|
765
4c2ba6161939
Editors Note: The original patch was modified to use SDL_Delay() instead of
Sam Lantinga <slouken@libsdl.org>
parents:
547
diff
changeset
|
606 |
/* 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
|
607 |
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
|
608 |
|
0 | 609 |
/* We're ready to rock and roll. :-) */ |
610 |
return(0); |
|
611 |
} |