2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2006 Sam Lantinga
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
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 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #include "SDL_config.h"
24 /* Get the name of the audio device we use for output */
26 #if SDL_AUDIO_DRIVER_BSD || SDL_AUDIO_DRIVER_OSS || SDL_AUDIO_DRIVER_SUNAUDIO
29 #include <sys/types.h>
32 #include "SDL_stdinc.h"
33 #include "SDL_audiodev_c.h"
36 #if defined(__NETBSD__) || defined(__OPENBSD__)
37 #define _PATH_DEV_DSP "/dev/audio"
39 #define _PATH_DEV_DSP "/dev/dsp"
42 #ifndef _PATH_DEV_DSP24
43 #define _PATH_DEV_DSP24 "/dev/sound/dsp"
45 #ifndef _PATH_DEV_AUDIO
46 #define _PATH_DEV_AUDIO "/dev/audio"
50 int SDL_OpenAudioPath(char *path
, int maxlen
, int flags
, int classic
)
56 /* Figure out what our audio device is */
57 if ( ((audiodev
=SDL_getenv("SDL_PATH_DSP")) == NULL
) &&
58 ((audiodev
=SDL_getenv("AUDIODEV")) == NULL
) ) {
60 audiodev
= _PATH_DEV_AUDIO
;
64 /* Added support for /dev/sound/\* in Linux 2.4 */
65 if ( ((stat("/dev/sound", &sb
) == 0) && S_ISDIR(sb
.st_mode
)) &&
66 ((stat(_PATH_DEV_DSP24
, &sb
) == 0) && S_ISCHR(sb
.st_mode
)) ) {
67 audiodev
= _PATH_DEV_DSP24
;
69 audiodev
= _PATH_DEV_DSP
;
73 audio_fd
= open(audiodev
, flags
, 0);
75 /* If the first open fails, look for other devices */
76 if ( (audio_fd
< 0) && (SDL_strlen(audiodev
) < (sizeof(audiopath
)-3)) ) {
81 do { /* Don't use errno ENOENT - it may not be thread-safe */
82 SDL_snprintf(audiopath
, SDL_arraysize(audiopath
),
83 "%s%d", audiodev
, instance
++);
85 if ( stat(audiopath
, &sb
) == 0 ) {
87 audio_fd
= open(audiopath
, flags
, 0);
89 } while ( exists
&& (audio_fd
< 0) );
93 SDL_strlcpy(path
, audiodev
, maxlen
);
94 path
[maxlen
-1] = '\0';
99 #elif SDL_AUDIO_DRIVER_PAUD
101 /* Get the name of the audio device we use for output */
103 #include <sys/types.h>
104 #include <sys/stat.h>
106 #include "SDL_stdinc.h"
107 #include "SDL_audiodev_c.h"
109 #ifndef _PATH_DEV_DSP
110 #define _PATH_DEV_DSP "/dev/%caud%c/%c"
113 char devsettings
[][3] =
115 { 'p', '0', '1' }, { 'p', '0', '2' }, { 'p', '0', '3' }, { 'p', '0', '4' },
116 { 'p', '1', '1' }, { 'p', '1', '2' }, { 'p', '1', '3' }, { 'p', '1', '4' },
117 { 'p', '2', '1' }, { 'p', '2', '2' }, { 'p', '2', '3' }, { 'p', '2', '4' },
118 { 'p', '3', '1' }, { 'p', '3', '2' }, { 'p', '3', '3' }, { 'p', '3', '4' },
119 { 'b', '0', '1' }, { 'b', '0', '2' }, { 'b', '0', '3' }, { 'b', '0', '4' },
120 { 'b', '1', '1' }, { 'b', '1', '2' }, { 'b', '1', '3' }, { 'b', '1', '4' },
121 { 'b', '2', '1' }, { 'b', '2', '2' }, { 'b', '2', '3' }, { 'b', '2', '4' },
122 { 'b', '3', '1' }, { 'b', '3', '2' }, { 'b', '3', '3' }, { 'b', '3', '4' },
126 static int OpenUserDefinedDevice(char *path
, int maxlen
, int flags
)
128 const char *audiodev
;
131 /* Figure out what our audio device is */
132 if ((audiodev
=SDL_getenv("SDL_PATH_DSP")) == NULL
) {
133 audiodev
=SDL_getenv("AUDIODEV");
135 if ( audiodev
== NULL
) {
138 audio_fd
= open(audiodev
, flags
, 0);
139 if ( path
!= NULL
) {
140 SDL_strlcpy(path
, audiodev
, maxlen
);
141 path
[maxlen
-1] = '\0';
146 int SDL_OpenAudioPath(char *path
, int maxlen
, int flags
, int classic
)
150 char audiopath
[1024];
153 audio_fd
= OpenUserDefinedDevice(path
,maxlen
,flags
);
154 if ( audio_fd
!= -1 ) {
159 while( devsettings
[cycle
][0] != '\0' ) {
160 SDL_snprintf( audiopath
, SDL_arraysize(audiopath
),
162 devsettings
[cycle
][0],
163 devsettings
[cycle
][1],
164 devsettings
[cycle
][2]);
166 if ( stat(audiopath
, &sb
) == 0 ) {
167 audio_fd
= open(audiopath
, flags
, 0);
168 if ( audio_fd
> 0 ) {
169 if ( path
!= NULL
) {
170 SDL_strlcpy( path
, audiopath
, maxlen
);
179 #endif /* Audio driver selection */