Mercurial > sdl-ios-xcode
comparison src/audio/SDL_audiodev.c @ 1662:782fd950bd46 SDL-1.3
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
WARNING: None of the video drivers have been updated for the new API yet! The API is still under design and very fluid.
The code is now run through a consistent indent format:
indent -i4 -nut -nsc -br -ce
The headers are being converted to automatically generate doxygen documentation.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sun, 28 May 2006 13:04:16 +0000 |
parents | 12b6d331d82a |
children | 4da1ee79c9af |
comparison
equal
deleted
inserted
replaced
1661:281d3f4870e5 | 1662:782fd950bd46 |
---|---|
45 #ifndef _PATH_DEV_AUDIO | 45 #ifndef _PATH_DEV_AUDIO |
46 #define _PATH_DEV_AUDIO "/dev/audio" | 46 #define _PATH_DEV_AUDIO "/dev/audio" |
47 #endif | 47 #endif |
48 | 48 |
49 | 49 |
50 int SDL_OpenAudioPath(char *path, int maxlen, int flags, int classic) | 50 int |
51 SDL_OpenAudioPath (char *path, int maxlen, int flags, int classic) | |
51 { | 52 { |
52 const char *audiodev; | 53 const char *audiodev; |
53 int audio_fd; | 54 int audio_fd; |
54 char audiopath[1024]; | 55 char audiopath[1024]; |
55 | 56 |
56 /* Figure out what our audio device is */ | 57 /* Figure out what our audio device is */ |
57 if ( ((audiodev=SDL_getenv("SDL_PATH_DSP")) == NULL) && | 58 if (((audiodev = SDL_getenv ("SDL_PATH_DSP")) == NULL) && |
58 ((audiodev=SDL_getenv("AUDIODEV")) == NULL) ) { | 59 ((audiodev = SDL_getenv ("AUDIODEV")) == NULL)) { |
59 if ( classic ) { | 60 if (classic) { |
60 audiodev = _PATH_DEV_AUDIO; | 61 audiodev = _PATH_DEV_AUDIO; |
61 } else { | 62 } else { |
62 struct stat sb; | 63 struct stat sb; |
63 | 64 |
64 /* Added support for /dev/sound/\* in Linux 2.4 */ | 65 /* Added support for /dev/sound/\* in Linux 2.4 */ |
65 if ( ((stat("/dev/sound", &sb) == 0) && S_ISDIR(sb.st_mode)) && | 66 if (((stat ("/dev/sound", &sb) == 0) && S_ISDIR (sb.st_mode)) |
66 ((stat(_PATH_DEV_DSP24, &sb) == 0) && S_ISCHR(sb.st_mode)) ) { | 67 && ((stat (_PATH_DEV_DSP24, &sb) == 0) |
67 audiodev = _PATH_DEV_DSP24; | 68 && S_ISCHR (sb.st_mode))) { |
68 } else { | 69 audiodev = _PATH_DEV_DSP24; |
69 audiodev = _PATH_DEV_DSP; | 70 } else { |
70 } | 71 audiodev = _PATH_DEV_DSP; |
71 } | 72 } |
72 } | 73 } |
73 audio_fd = open(audiodev, flags, 0); | 74 } |
75 audio_fd = open (audiodev, flags, 0); | |
74 | 76 |
75 /* If the first open fails, look for other devices */ | 77 /* If the first open fails, look for other devices */ |
76 if ( (audio_fd < 0) && (SDL_strlen(audiodev) < (sizeof(audiopath)-3)) ) { | 78 if ((audio_fd < 0) && (SDL_strlen (audiodev) < (sizeof (audiopath) - 3))) { |
77 int exists, instance; | 79 int exists, instance; |
78 struct stat sb; | 80 struct stat sb; |
79 | 81 |
80 instance = 1; | 82 instance = 1; |
81 do { /* Don't use errno ENOENT - it may not be thread-safe */ | 83 do { /* Don't use errno ENOENT - it may not be thread-safe */ |
82 SDL_snprintf(audiopath, SDL_arraysize(audiopath), | 84 SDL_snprintf (audiopath, SDL_arraysize (audiopath), |
83 "%s%d", audiodev, instance++); | 85 "%s%d", audiodev, instance++); |
84 exists = 0; | 86 exists = 0; |
85 if ( stat(audiopath, &sb) == 0 ) { | 87 if (stat (audiopath, &sb) == 0) { |
86 exists = 1; | 88 exists = 1; |
87 audio_fd = open(audiopath, flags, 0); | 89 audio_fd = open (audiopath, flags, 0); |
88 } | 90 } |
89 } while ( exists && (audio_fd < 0) ); | 91 } |
90 audiodev = audiopath; | 92 while (exists && (audio_fd < 0)); |
91 } | 93 audiodev = audiopath; |
92 if ( path != NULL ) { | 94 } |
93 SDL_strlcpy(path, audiodev, maxlen); | 95 if (path != NULL) { |
94 path[maxlen-1] = '\0'; | 96 SDL_strlcpy (path, audiodev, maxlen); |
95 } | 97 path[maxlen - 1] = '\0'; |
96 return(audio_fd); | 98 } |
99 return (audio_fd); | |
97 } | 100 } |
98 | 101 |
99 #elif SDL_AUDIO_DRIVER_PAUD | 102 #elif SDL_AUDIO_DRIVER_PAUD |
100 | 103 |
101 /* Get the name of the audio device we use for output */ | 104 /* Get the name of the audio device we use for output */ |
108 | 111 |
109 #ifndef _PATH_DEV_DSP | 112 #ifndef _PATH_DEV_DSP |
110 #define _PATH_DEV_DSP "/dev/%caud%c/%c" | 113 #define _PATH_DEV_DSP "/dev/%caud%c/%c" |
111 #endif | 114 #endif |
112 | 115 |
113 char devsettings[][3] = | 116 char devsettings[][3] = { |
114 { | 117 {'p', '0', '1'}, {'p', '0', '2'}, {'p', '0', '3'}, {'p', '0', '4'}, |
115 { 'p', '0', '1' }, { 'p', '0', '2' }, { 'p', '0', '3' }, { 'p', '0', '4' }, | 118 {'p', '1', '1'}, {'p', '1', '2'}, {'p', '1', '3'}, {'p', '1', '4'}, |
116 { 'p', '1', '1' }, { 'p', '1', '2' }, { 'p', '1', '3' }, { 'p', '1', '4' }, | 119 {'p', '2', '1'}, {'p', '2', '2'}, {'p', '2', '3'}, {'p', '2', '4'}, |
117 { 'p', '2', '1' }, { 'p', '2', '2' }, { 'p', '2', '3' }, { 'p', '2', '4' }, | 120 {'p', '3', '1'}, {'p', '3', '2'}, {'p', '3', '3'}, {'p', '3', '4'}, |
118 { 'p', '3', '1' }, { 'p', '3', '2' }, { 'p', '3', '3' }, { 'p', '3', '4' }, | 121 {'b', '0', '1'}, {'b', '0', '2'}, {'b', '0', '3'}, {'b', '0', '4'}, |
119 { 'b', '0', '1' }, { 'b', '0', '2' }, { 'b', '0', '3' }, { 'b', '0', '4' }, | 122 {'b', '1', '1'}, {'b', '1', '2'}, {'b', '1', '3'}, {'b', '1', '4'}, |
120 { 'b', '1', '1' }, { 'b', '1', '2' }, { 'b', '1', '3' }, { 'b', '1', '4' }, | 123 {'b', '2', '1'}, {'b', '2', '2'}, {'b', '2', '3'}, {'b', '2', '4'}, |
121 { 'b', '2', '1' }, { 'b', '2', '2' }, { 'b', '2', '3' }, { 'b', '2', '4' }, | 124 {'b', '3', '1'}, {'b', '3', '2'}, {'b', '3', '3'}, {'b', '3', '4'}, |
122 { 'b', '3', '1' }, { 'b', '3', '2' }, { 'b', '3', '3' }, { 'b', '3', '4' }, | 125 {'\0', '\0', '\0'} |
123 { '\0', '\0', '\0' } | |
124 }; | 126 }; |
125 | 127 |
126 static int OpenUserDefinedDevice(char *path, int maxlen, int flags) | 128 static int |
129 OpenUserDefinedDevice (char *path, int maxlen, int flags) | |
127 { | 130 { |
128 const char *audiodev; | 131 const char *audiodev; |
129 int audio_fd; | 132 int audio_fd; |
130 | 133 |
131 /* Figure out what our audio device is */ | 134 /* Figure out what our audio device is */ |
132 if ((audiodev=SDL_getenv("SDL_PATH_DSP")) == NULL) { | 135 if ((audiodev = SDL_getenv ("SDL_PATH_DSP")) == NULL) { |
133 audiodev=SDL_getenv("AUDIODEV"); | 136 audiodev = SDL_getenv ("AUDIODEV"); |
134 } | 137 } |
135 if ( audiodev == NULL ) { | 138 if (audiodev == NULL) { |
136 return -1; | 139 return -1; |
137 } | 140 } |
138 audio_fd = open(audiodev, flags, 0); | 141 audio_fd = open (audiodev, flags, 0); |
139 if ( path != NULL ) { | 142 if (path != NULL) { |
140 SDL_strlcpy(path, audiodev, maxlen); | 143 SDL_strlcpy (path, audiodev, maxlen); |
141 path[maxlen-1] = '\0'; | 144 path[maxlen - 1] = '\0'; |
142 } | 145 } |
143 return audio_fd; | 146 return audio_fd; |
144 } | 147 } |
145 | 148 |
146 int SDL_OpenAudioPath(char *path, int maxlen, int flags, int classic) | 149 int |
150 SDL_OpenAudioPath (char *path, int maxlen, int flags, int classic) | |
147 { | 151 { |
148 struct stat sb; | 152 struct stat sb; |
149 int audio_fd; | 153 int audio_fd; |
150 char audiopath[1024]; | 154 char audiopath[1024]; |
151 int cycle; | 155 int cycle; |
152 | 156 |
153 audio_fd = OpenUserDefinedDevice(path,maxlen,flags); | 157 audio_fd = OpenUserDefinedDevice (path, maxlen, flags); |
154 if ( audio_fd != -1 ) { | 158 if (audio_fd != -1) { |
155 return audio_fd; | 159 return audio_fd; |
156 } | 160 } |
157 | 161 |
158 cycle = 0; | 162 cycle = 0; |
159 while( devsettings[cycle][0] != '\0' ) { | 163 while (devsettings[cycle][0] != '\0') { |
160 SDL_snprintf( audiopath, SDL_arraysize(audiopath), | 164 SDL_snprintf (audiopath, SDL_arraysize (audiopath), |
161 _PATH_DEV_DSP, | 165 _PATH_DEV_DSP, |
162 devsettings[cycle][0], | 166 devsettings[cycle][0], |
163 devsettings[cycle][1], | 167 devsettings[cycle][1], devsettings[cycle][2]); |
164 devsettings[cycle][2]); | |
165 | 168 |
166 if ( stat(audiopath, &sb) == 0 ) { | 169 if (stat (audiopath, &sb) == 0) { |
167 audio_fd = open(audiopath, flags, 0); | 170 audio_fd = open (audiopath, flags, 0); |
168 if ( audio_fd > 0 ) { | 171 if (audio_fd > 0) { |
169 if ( path != NULL ) { | 172 if (path != NULL) { |
170 SDL_strlcpy( path, audiopath, maxlen ); | 173 SDL_strlcpy (path, audiopath, maxlen); |
171 } | 174 } |
172 return audio_fd; | 175 return audio_fd; |
173 } | 176 } |
174 } | 177 } |
175 } | 178 } |
176 return -1; | 179 return -1; |
177 } | 180 } |
178 | 181 |
179 #endif /* Audio driver selection */ | 182 #endif /* Audio driver selection */ |
183 /* vi: set ts=4 sw=4 expandtab: */ |