Mercurial > sdl-ios-xcode
comparison src/audio/dsp/SDL_dspaudio.c @ 93:fc774f445e10
Applied Hannu's fix and switched to blocking writes .. seems to work?
author | Sam Lantinga <slouken@lokigames.com> |
---|---|
date | Sat, 07 Jul 2001 23:27:29 +0000 |
parents | d3bc792e136d |
children | ae6e6b73333f |
comparison
equal
deleted
inserted
replaced
92:dab667b72ccc | 93:fc774f445e10 |
---|---|
49 | 49 |
50 /* The tag name used by DSP audio */ | 50 /* The tag name used by DSP audio */ |
51 #define DSP_DRIVER_NAME "dsp" | 51 #define DSP_DRIVER_NAME "dsp" |
52 | 52 |
53 /* Open the audio device for playback, and don't block if busy */ | 53 /* Open the audio device for playback, and don't block if busy */ |
54 /*#define USE_BLOCKING_WRITES*/ | 54 #define USE_BLOCKING_WRITES |
55 #ifdef USE_BLOCKING_WRITES | 55 #ifdef USE_BLOCKING_WRITES |
56 #define OPEN_FLAGS O_WRONLY | 56 #define OPEN_FLAGS O_WRONLY |
57 #else | 57 #else |
58 #define OPEN_FLAGS (O_WRONLY|O_NONBLOCK) | 58 #define OPEN_FLAGS (O_WRONLY|O_NONBLOCK) |
59 #endif | 59 #endif |
126 }; | 126 }; |
127 | 127 |
128 /* This function waits until it is possible to write a full sound buffer */ | 128 /* This function waits until it is possible to write a full sound buffer */ |
129 static void DSP_WaitAudio(_THIS) | 129 static void DSP_WaitAudio(_THIS) |
130 { | 130 { |
131 #ifndef USE_BLOCKING_WRITES /* Not necessary because of blocking writes */ | |
132 fd_set fdset; | |
133 | |
134 /* Check to see if the thread-parent process is still alive */ | 131 /* Check to see if the thread-parent process is still alive */ |
135 { static int cnt = 0; | 132 { static int cnt = 0; |
136 /* Note that this only works with thread implementations | 133 /* Note that this only works with thread implementations |
137 that use a different process id for each thread. | 134 that use a different process id for each thread. |
138 */ | 135 */ |
141 this->enabled = 0; | 138 this->enabled = 0; |
142 } | 139 } |
143 } | 140 } |
144 } | 141 } |
145 | 142 |
143 #ifndef USE_BLOCKING_WRITES /* Not necessary when using blocking writes */ | |
146 /* See if we need to use timed audio synchronization */ | 144 /* See if we need to use timed audio synchronization */ |
147 if ( frame_ticks ) { | 145 if ( frame_ticks ) { |
148 /* Use timer for general audio synchronization */ | 146 /* Use timer for general audio synchronization */ |
149 Sint32 ticks; | 147 Sint32 ticks; |
150 | 148 |
152 if ( ticks > 0 ) { | 150 if ( ticks > 0 ) { |
153 SDL_Delay(ticks); | 151 SDL_Delay(ticks); |
154 } | 152 } |
155 } else { | 153 } else { |
156 /* Use select() for audio synchronization */ | 154 /* Use select() for audio synchronization */ |
155 fd_set fdset; | |
157 struct timeval timeout; | 156 struct timeval timeout; |
157 | |
158 FD_ZERO(&fdset); | 158 FD_ZERO(&fdset); |
159 FD_SET(audio_fd, &fdset); | 159 FD_SET(audio_fd, &fdset); |
160 timeout.tv_sec = 10; | 160 timeout.tv_sec = 10; |
161 timeout.tv_usec = 0; | 161 timeout.tv_usec = 0; |
162 #ifdef DEBUG_AUDIO | 162 #ifdef DEBUG_AUDIO |
184 #endif /* !USE_BLOCKING_WRITES */ | 184 #endif /* !USE_BLOCKING_WRITES */ |
185 } | 185 } |
186 | 186 |
187 static void DSP_PlayAudio(_THIS) | 187 static void DSP_PlayAudio(_THIS) |
188 { | 188 { |
189 int written; | 189 int written, p=0; |
190 | 190 |
191 /* Write the audio data, checking for EAGAIN on broken audio drivers */ | 191 /* Write the audio data, checking for EAGAIN on broken audio drivers */ |
192 do { | 192 do { |
193 written = write(audio_fd, mixbuf, mixlen); | 193 written = write(audio_fd, &mixbuf[p], mixlen-p); |
194 if ( (written < 0) && ((errno == 0) || (errno == EAGAIN)) ) { | 194 if (written>0) |
195 p += written; | |
196 if (written == -1 && errno != 0 && errno != EAGAIN && errno != EINTR) | |
197 { | |
198 /* Non recoverable error has occurred. It should be reported!!! */ | |
199 perror("audio"); | |
200 break; | |
201 } | |
202 | |
203 if ( p < written || ((written < 0) && ((errno == 0) || (errno == EAGAIN))) ) { | |
195 SDL_Delay(1); /* Let a little CPU time go by */ | 204 SDL_Delay(1); /* Let a little CPU time go by */ |
196 } | 205 } |
197 } while ( (written < 0) && | 206 } while ( p < written ); |
198 ((errno == 0) || (errno == EAGAIN) || (errno == EINTR)) ); | |
199 | 207 |
200 /* If timer synchronization is enabled, set the next write frame */ | 208 /* If timer synchronization is enabled, set the next write frame */ |
201 if ( frame_ticks ) { | 209 if ( frame_ticks ) { |
202 next_frame += frame_ticks; | 210 next_frame += frame_ticks; |
203 } | 211 } |