comparison src/audio/windib/SDL_dibaudio.c @ 36:13ee9f4834ea

Windows CE patches contributed by Rainer Loritz
author Sam Lantinga <slouken@lokigames.com>
date Wed, 23 May 2001 23:35:10 +0000
parents 74212992fb08
children e8157fcb3114
comparison
equal deleted inserted replaced
35:d3bc792e136d 36:13ee9f4834ea
35 #include "SDL_audio.h" 35 #include "SDL_audio.h"
36 #include "SDL_mutex.h" 36 #include "SDL_mutex.h"
37 #include "SDL_timer.h" 37 #include "SDL_timer.h"
38 #include "SDL_audio_c.h" 38 #include "SDL_audio_c.h"
39 #include "SDL_dibaudio.h" 39 #include "SDL_dibaudio.h"
40 #if defined(_WIN32_WCE) && (_WIN32_WCE < 300)
41 #include "win_ce_semaphore.h"
42 #endif
40 43
41 44
42 /* Audio driver functions */ 45 /* Audio driver functions */
43 static int DIB_OpenAudio(_THIS, SDL_AudioSpec *spec); 46 static int DIB_OpenAudio(_THIS, SDL_AudioSpec *spec);
44 static void DIB_ThreadInit(_THIS); 47 static void DIB_ThreadInit(_THIS);
110 /* Only service "buffer done playing" messages */ 113 /* Only service "buffer done playing" messages */
111 if ( uMsg != WOM_DONE ) 114 if ( uMsg != WOM_DONE )
112 return; 115 return;
113 116
114 /* Signal that we are done playing a buffer */ 117 /* Signal that we are done playing a buffer */
118 #if defined(_WIN32_WCE) && (_WIN32_WCE < 300)
119 ReleaseSemaphoreCE(audio_sem, 1, NULL);
120 #else
115 ReleaseSemaphore(audio_sem, 1, NULL); 121 ReleaseSemaphore(audio_sem, 1, NULL);
122 #endif
116 } 123 }
117 124
118 static void SetMMerror(char *function, MMRESULT code) 125 static void SetMMerror(char *function, MMRESULT code)
119 { 126 {
120 int len; 127 int len;
121 char errbuf[MAXERRORLENGTH]; 128 char errbuf[MAXERRORLENGTH];
129 #ifdef _WIN32_WCE
130 wchar_t werrbuf[MAXERRORLENGTH];
131 #endif
122 132
123 sprintf(errbuf, "%s: ", function); 133 sprintf(errbuf, "%s: ", function);
124 len = strlen(errbuf); 134 len = strlen(errbuf);
135
136 #ifdef _WIN32_WCE
137 /* UNICODE version */
138 waveOutGetErrorText(code, werrbuf, MAXERRORLENGTH-len);
139 WideCharToMultiByte(CP_ACP,0,werrbuf,-1,errbuf+len,MAXERRORLENGTH-len,NULL,NULL);
140 #else
125 waveOutGetErrorText(code, errbuf+len, MAXERRORLENGTH-len); 141 waveOutGetErrorText(code, errbuf+len, MAXERRORLENGTH-len);
126 SDL_SetError("%s", errbuf); 142 #endif
143
144 SDL_SetError("%s",errbuf);
127 } 145 }
128 146
129 /* Set high priority for the audio thread */ 147 /* Set high priority for the audio thread */
130 static void DIB_ThreadInit(_THIS) 148 static void DIB_ThreadInit(_THIS)
131 { 149 {
133 } 151 }
134 152
135 void DIB_WaitAudio(_THIS) 153 void DIB_WaitAudio(_THIS)
136 { 154 {
137 /* Wait for an audio chunk to finish */ 155 /* Wait for an audio chunk to finish */
156 #if defined(_WIN32_WCE) && (_WIN32_WCE < 300)
157 WaitForSemaphoreCE(audio_sem, INFINITE);
158 #else
138 WaitForSingleObject(audio_sem, INFINITE); 159 WaitForSingleObject(audio_sem, INFINITE);
160 #endif
139 } 161 }
140 162
141 Uint8 *DIB_GetAudioBuf(_THIS) 163 Uint8 *DIB_GetAudioBuf(_THIS)
142 { 164 {
143 Uint8 *retval; 165 Uint8 *retval;
174 { 196 {
175 int i; 197 int i;
176 198
177 /* Close up audio */ 199 /* Close up audio */
178 if ( audio_sem ) { 200 if ( audio_sem ) {
201 #if defined(_WIN32_WCE) && (_WIN32_WCE < 300)
202 CloseSynchHandle(audio_sem);
203 #else
179 CloseHandle(audio_sem); 204 CloseHandle(audio_sem);
205 #endif
180 } 206 }
181 if ( sound ) { 207 if ( sound ) {
182 waveOutClose(sound); 208 waveOutClose(sound);
183 } 209 }
184 210
265 printf("Audio device: %s\n", caps.szPname); 291 printf("Audio device: %s\n", caps.szPname);
266 } 292 }
267 #endif 293 #endif
268 294
269 /* Create the audio buffer semaphore */ 295 /* Create the audio buffer semaphore */
296 #if defined(_WIN32_WCE) && (_WIN32_WCE < 300)
297 audio_sem = CreateSemaphoreCE(NULL, NUM_BUFFERS-1, NUM_BUFFERS, NULL);
298 #else
270 audio_sem = CreateSemaphore(NULL, NUM_BUFFERS-1, NUM_BUFFERS, NULL); 299 audio_sem = CreateSemaphore(NULL, NUM_BUFFERS-1, NUM_BUFFERS, NULL);
300 #endif
271 if ( audio_sem == NULL ) { 301 if ( audio_sem == NULL ) {
272 SDL_SetError("Couldn't create semaphore"); 302 SDL_SetError("Couldn't create semaphore");
273 return(-1); 303 return(-1);
274 } 304 }
275 305