Mercurial > sdl-ios-xcode
annotate src/audio/SDL_audiodev.c @ 1312:c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
I batch edited these files, so please let me know if I've accidentally removed anybody's
credit here.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Wed, 01 Feb 2006 06:32:25 +0000 |
parents | fcfb783a3ca2 |
children | 3692456e7b0f |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1138
diff
changeset
|
3 Copyright (C) 1997-2006 Sam Lantinga |
0 | 4 |
5 This library is free software; you can redistribute it and/or | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1138
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
0 | 7 License as published by the Free Software Foundation; either |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1138
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
0 | 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 | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1138
diff
changeset
|
13 Lesser General Public License for more details. |
0 | 14 |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1138
diff
changeset
|
15 You should have received a copy of the GNU Lesser General Public |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1138
diff
changeset
|
16 License along with this library; if not, write to the Free Software |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1138
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
0 | 18 |
19 Sam Lantinga | |
252
e8157fcb3114
Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents:
94
diff
changeset
|
20 slouken@libsdl.org |
0 | 21 */ |
22 | |
23 /* Get the name of the audio device we use for output */ | |
24 | |
1035
974ba6ae0fa3
Date: Wed, 26 Jan 2005 13:37:09 GMT
Sam Lantinga <slouken@libsdl.org>
parents:
1026
diff
changeset
|
25 #if defined(unix) || defined(__unix__) || defined(__riscos__) |
0 | 26 |
27 #include <stdlib.h> | |
28 #include <stdio.h> | |
29 #include <fcntl.h> | |
30 #include <sys/types.h> | |
31 #include <sys/stat.h> | |
32 #include <string.h> | |
33 | |
34 #include "SDL_audiodev_c.h" | |
35 | |
36 #ifndef _PATH_DEV_DSP | |
1026
0f3aa6ab3341
Select patches included from The NetBSD Package Collection (www.pkgsrc.org)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
37 #if defined(__NetBSD__) || defined(__OpenBSD__) |
94
ae6e6b73333f
Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
38 #define _PATH_DEV_DSP "/dev/audio" |
ae6e6b73333f
Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
39 #else |
ae6e6b73333f
Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
40 #define _PATH_DEV_DSP "/dev/dsp" |
ae6e6b73333f
Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
41 #endif |
0 | 42 #endif |
43 #ifndef _PATH_DEV_DSP24 | |
44 #define _PATH_DEV_DSP24 "/dev/sound/dsp" | |
45 #endif | |
46 #ifndef _PATH_DEV_AUDIO | |
47 #define _PATH_DEV_AUDIO "/dev/audio" | |
48 #endif | |
49 | |
50 | |
51 int SDL_OpenAudioPath(char *path, int maxlen, int flags, int classic) | |
52 { | |
53 const char *audiodev; | |
54 int audio_fd; | |
55 char audiopath[1024]; | |
56 | |
57 /* Figure out what our audio device is */ | |
58 if ( ((audiodev=getenv("SDL_PATH_DSP")) == NULL) && | |
59 ((audiodev=getenv("AUDIODEV")) == NULL) ) { | |
60 if ( classic ) { | |
61 audiodev = _PATH_DEV_AUDIO; | |
62 } else { | |
63 struct stat sb; | |
64 | |
65 /* Added support for /dev/sound/\* in Linux 2.4 */ | |
1138
fcfb783a3ca2
Commercial-OSS-on-Solaris patch...
Ryan C. Gordon <icculus@icculus.org>
parents:
1035
diff
changeset
|
66 if ( ((stat("/dev/sound", &sb) == 0) && S_ISDIR(sb.st_mode)) && |
fcfb783a3ca2
Commercial-OSS-on-Solaris patch...
Ryan C. Gordon <icculus@icculus.org>
parents:
1035
diff
changeset
|
67 ((stat(_PATH_DEV_DSP24, &sb) == 0) && S_ISCHR(sb.st_mode)) ) { |
0 | 68 audiodev = _PATH_DEV_DSP24; |
69 } else { | |
70 audiodev = _PATH_DEV_DSP; | |
71 } | |
72 } | |
73 } | |
74 audio_fd = open(audiodev, flags, 0); | |
75 | |
76 /* If the first open fails, look for other devices */ | |
77 if ( (audio_fd < 0) && (strlen(audiodev) < (sizeof(audiopath)-3)) ) { | |
78 int exists, instance; | |
79 struct stat sb; | |
80 | |
81 instance = 1; | |
82 do { /* Don't use errno ENOENT - it may not be thread-safe */ | |
83 sprintf(audiopath, "%s%d", audiodev, instance++); | |
84 exists = 0; | |
85 if ( stat(audiopath, &sb) == 0 ) { | |
86 exists = 1; | |
87 audio_fd = open(audiopath, flags, 0); | |
88 } | |
89 } while ( exists && (audio_fd < 0) ); | |
90 audiodev = audiopath; | |
91 } | |
92 if ( path != NULL ) { | |
93 strncpy(path, audiodev, maxlen); | |
94 path[maxlen-1] = '\0'; | |
95 } | |
96 return(audio_fd); | |
97 } | |
98 | |
99 #elif defined(_AIX) | |
100 | |
101 /* Get the name of the audio device we use for output */ | |
102 | |
103 #include <stdlib.h> | |
104 #include <sys/types.h> | |
105 #include <sys/stat.h> | |
106 #include <string.h> | |
107 | |
108 #include "SDL_audiodev_c.h" | |
109 | |
110 #ifndef _PATH_DEV_DSP | |
111 #define _PATH_DEV_DSP "/dev/%caud%c/%c" | |
112 #endif | |
113 | |
114 char devsettings[][3] = | |
115 { | |
116 { 'p', '0', '1' }, { 'p', '0', '2' }, { 'p', '0', '3' }, { 'p', '0', '4' }, | |
117 { 'p', '1', '1' }, { 'p', '1', '2' }, { 'p', '1', '3' }, { 'p', '1', '4' }, | |
118 { 'p', '2', '1' }, { 'p', '2', '2' }, { 'p', '2', '3' }, { 'p', '2', '4' }, | |
119 { 'p', '3', '1' }, { 'p', '3', '2' }, { 'p', '3', '3' }, { 'p', '3', '4' }, | |
120 { 'b', '0', '1' }, { 'b', '0', '2' }, { 'b', '0', '3' }, { 'b', '0', '4' }, | |
121 { 'b', '1', '1' }, { 'b', '1', '2' }, { 'b', '1', '3' }, { 'b', '1', '4' }, | |
122 { 'b', '2', '1' }, { 'b', '2', '2' }, { 'b', '2', '3' }, { 'b', '2', '4' }, | |
123 { 'b', '3', '1' }, { 'b', '3', '2' }, { 'b', '3', '3' }, { 'b', '3', '4' }, | |
124 { '\0', '\0', '\0' } | |
125 }; | |
126 | |
127 static int OpenUserDefinedDevice(char *path, int maxlen, int flags) | |
128 { | |
129 const char *audiodev; | |
130 int audio_fd; | |
131 | |
132 /* Figure out what our audio device is */ | |
133 if ((audiodev=getenv("SDL_PATH_DSP")) == NULL) { | |
134 audiodev=getenv("AUDIODEV"); | |
135 } | |
136 if ( audiodev == NULL ) { | |
137 return -1; | |
138 } | |
139 audio_fd = open(audiodev, flags, 0); | |
140 if ( path != NULL ) { | |
141 strncpy(path, audiodev, maxlen); | |
142 path[maxlen-1] = '\0'; | |
143 } | |
144 return audio_fd; | |
145 } | |
146 | |
147 int SDL_OpenAudioPath(char *path, int maxlen, int flags, int classic) | |
148 { | |
149 struct stat sb; | |
150 int audio_fd; | |
151 char audiopath[1024]; | |
152 int cycle; | |
153 | |
154 audio_fd = OpenUserDefinedDevice(path,maxlen,flags); | |
155 if ( audio_fd != -1 ) { | |
156 return audio_fd; | |
157 } | |
158 | |
159 cycle = 0; | |
160 while( devsettings[cycle][0] != '\0' ) { | |
161 sprintf( audiopath, | |
162 _PATH_DEV_DSP, | |
163 devsettings[cycle][0], | |
164 devsettings[cycle][1], | |
165 devsettings[cycle][2]); | |
166 | |
167 if ( stat(audiopath, &sb) == 0 ) { | |
168 audio_fd = open(audiopath, flags, 0); | |
169 if ( audio_fd > 0 ) { | |
170 if ( path != NULL ) { | |
171 strncpy( path, audiopath, maxlen ); | |
172 path[maxlen-1] = '\0'; | |
173 } | |
174 return audio_fd; | |
175 } | |
176 } | |
177 } | |
178 return -1; | |
179 } | |
180 | |
181 #endif /* UNIX system */ |