comparison src/audio/paudio/SDL_paudio.c @ 3809:7852b5b78af5 SDL-ryan-multiple-audio-device

Cleaning out SDL_audiodev.c and related references ...
author Ryan C. Gordon <icculus@icculus.org>
date Thu, 05 Oct 2006 01:13:47 +0000
parents c8b3d3d13ed1
children ca74a71063ac
comparison
equal deleted inserted replaced
3808:e630f5fe29d8 3809:7852b5b78af5
28 #include <errno.h> 28 #include <errno.h>
29 #include <unistd.h> 29 #include <unistd.h>
30 #include <fcntl.h> 30 #include <fcntl.h>
31 #include <sys/time.h> 31 #include <sys/time.h>
32 #include <sys/ioctl.h> 32 #include <sys/ioctl.h>
33 #include <sys/types.h>
33 #include <sys/stat.h> 34 #include <sys/stat.h>
34 35
35 #include "SDL_timer.h" 36 #include "SDL_timer.h"
36 #include "SDL_audio.h" 37 #include "SDL_audio.h"
38 #include "SDL_stdinc.h"
37 #include "../SDL_audiomem.h" 39 #include "../SDL_audiomem.h"
38 #include "../SDL_audio_c.h" 40 #include "../SDL_audio_c.h"
39 #include "../SDL_audiodev_c.h"
40 #include "SDL_paudio.h" 41 #include "SDL_paudio.h"
41 42
42 #define DEBUG_AUDIO 1 43 #define DEBUG_AUDIO 1
43 44
44 /* A conflict within AIX 4.3.3 <sys/> headers and probably others as well. 45 /* A conflict within AIX 4.3.3 <sys/> headers and probably others as well.
59 static void Paud_WaitAudio(_THIS); 60 static void Paud_WaitAudio(_THIS);
60 static void Paud_PlayAudio(_THIS); 61 static void Paud_PlayAudio(_THIS);
61 static Uint8 *Paud_GetAudioBuf(_THIS); 62 static Uint8 *Paud_GetAudioBuf(_THIS);
62 static void Paud_CloseAudio(_THIS); 63 static void Paud_CloseAudio(_THIS);
63 64
65
66 /* Get the name of the audio device we use for output */
67
68 #ifndef _PATH_DEV_DSP
69 #define _PATH_DEV_DSP "/dev/%caud%c/%c"
70 #endif
71
72 static char devsettings[][3] = {
73 {'p', '0', '1'}, {'p', '0', '2'}, {'p', '0', '3'}, {'p', '0', '4'},
74 {'p', '1', '1'}, {'p', '1', '2'}, {'p', '1', '3'}, {'p', '1', '4'},
75 {'p', '2', '1'}, {'p', '2', '2'}, {'p', '2', '3'}, {'p', '2', '4'},
76 {'p', '3', '1'}, {'p', '3', '2'}, {'p', '3', '3'}, {'p', '3', '4'},
77 {'b', '0', '1'}, {'b', '0', '2'}, {'b', '0', '3'}, {'b', '0', '4'},
78 {'b', '1', '1'}, {'b', '1', '2'}, {'b', '1', '3'}, {'b', '1', '4'},
79 {'b', '2', '1'}, {'b', '2', '2'}, {'b', '2', '3'}, {'b', '2', '4'},
80 {'b', '3', '1'}, {'b', '3', '2'}, {'b', '3', '3'}, {'b', '3', '4'},
81 {'\0', '\0', '\0'}
82 };
83
84 static int
85 OpenUserDefinedDevice(char *path, int maxlen, int flags)
86 {
87 const char *audiodev;
88 int audio_fd;
89
90 /* Figure out what our audio device is */
91 if ((audiodev = SDL_getenv("SDL_PATH_DSP")) == NULL) {
92 audiodev = SDL_getenv("AUDIODEV");
93 }
94 if (audiodev == NULL) {
95 return -1;
96 }
97 audio_fd = open(audiodev, flags, 0);
98 if (path != NULL) {
99 SDL_strlcpy(path, audiodev, maxlen);
100 path[maxlen - 1] = '\0';
101 }
102 return audio_fd;
103 }
104
105 int
106 OpenAudioPath(char *path, int maxlen, int flags, int classic)
107 {
108 struct stat sb;
109 int audio_fd;
110 char audiopath[1024];
111 int cycle;
112
113 audio_fd = OpenUserDefinedDevice(path, maxlen, flags);
114 if (audio_fd != -1) {
115 return audio_fd;
116 }
117
118 cycle = 0;
119 /* !!! FIXME: do we really need a table here? */
120 while (devsettings[cycle][0] != '\0') {
121 SDL_snprintf(audiopath, SDL_arraysize(audiopath),
122 _PATH_DEV_DSP,
123 devsettings[cycle][0],
124 devsettings[cycle][1], devsettings[cycle][2]);
125
126 if (stat(audiopath, &sb) == 0) {
127 audio_fd = open(audiopath, flags, 0);
128 if (audio_fd > 0) {
129 if (path != NULL) {
130 SDL_strlcpy(path, audiopath, maxlen);
131 }
132 return audio_fd;
133 }
134 }
135 }
136 return -1;
137 }
138
139
64 /* Audio driver bootstrap functions */ 140 /* Audio driver bootstrap functions */
65 141
66 static int 142 static int
67 Audio_Available(void) 143 Audio_Available(void)
68 { 144 {
69 int fd; 145 int fd;
70 int available; 146 int available;
71 147
72 available = 0; 148 available = 0;
73 fd = SDL_OpenAudioPath(NULL, 0, OPEN_FLAGS, 0); 149 fd = OpenAudioPath(NULL, 0, OPEN_FLAGS, 0);
74 if (fd >= 0) { 150 if (fd >= 0) {
75 available = 1; 151 available = 1;
76 close(fd); 152 close(fd);
77 } 153 }
78 return (available); 154 return (available);
253 329
254 /* Reset the timer synchronization flag */ 330 /* Reset the timer synchronization flag */
255 frame_ticks = 0.0; 331 frame_ticks = 0.0;
256 332
257 /* Open the audio device */ 333 /* Open the audio device */
258 audio_fd = SDL_OpenAudioPath(audiodev, sizeof(audiodev), OPEN_FLAGS, 0); 334 audio_fd = OpenAudioPath(audiodev, sizeof(audiodev), OPEN_FLAGS, 0);
259 if (audio_fd < 0) { 335 if (audio_fd < 0) {
260 SDL_SetError("Couldn't open %s: %s", audiodev, strerror(errno)); 336 SDL_SetError("Couldn't open %s: %s", audiodev, strerror(errno));
261 return -1; 337 return -1;
262 } 338 }
263 339