annotate src/audio/windib/SDL_dibaudio.c @ 3846:66fb40445587 SDL-ryan-multiple-audio-device

Removed distinction between "available" and "init" in audio backends, since both had to be checked for success as a pair at the higher level and several of the Available methods were just always-succeed placeholders anyhow. Now the availability check is done in the init code, and the higher level tries all possible drivers until one manages to initialize successfully.
author Ryan C. Gordon <icculus@icculus.org>
date Tue, 17 Oct 2006 09:09:21 +0000
parents 3479f939987c
children
rev   line source
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1 /*
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
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: 769
diff changeset
3 Copyright (C) 1997-2006 Sam Lantinga
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
4
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
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: 769
diff changeset
6 modify it under the terms of the GNU Lesser General Public
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
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: 769
diff changeset
8 version 2.1 of the License, or (at your option) any later version.
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
9
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
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: 769
diff changeset
13 Lesser General Public License for more details.
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
14
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 769
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: 769
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: 769
diff changeset
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
18
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
19 Sam Lantinga
252
e8157fcb3114 Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents: 36
diff changeset
20 slouken@libsdl.org
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
21 */
1402
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1361
diff changeset
22 #include "SDL_config.h"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
23
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
24 /* Allow access to a raw mixing buffer */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
25
1433
bb6839704ed6 SDL_windows.h is no longer necessary
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
26 #define WIN32_LEAN_AND_MEAN
bb6839704ed6 SDL_windows.h is no longer necessary
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
27 #include <windows.h>
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
28 #include <mmsystem.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
29
1358
c71e05b4dc2e More header massaging... works great on Windows. ;-)
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
30 #include "SDL_timer.h"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
31 #include "SDL_audio.h"
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
32 #include "../SDL_audio_c.h"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
33 #include "SDL_dibaudio.h"
36
13ee9f4834ea Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
34 #if defined(_WIN32_WCE) && (_WIN32_WCE < 300)
13ee9f4834ea Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
35 #include "win_ce_semaphore.h"
13ee9f4834ea Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
36 #endif
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
37
3841
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
38 #if defined(_WIN32_WCE)
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
39 #define WINDOWS_OS_NAME "Windows CE/PocketPC"
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
40 #elif defined(WIN64)
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
41 #define WINDOWS_OS_NAME "Win64"
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
42 #else
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
43 #define WINDOWS_OS_NAME "Win32"
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
44 #endif
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
45
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
46 /* The Win32 callback for filling the WAVE device */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
47 static void CALLBACK
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
48 FillSound(HWAVEOUT hwo, UINT uMsg, DWORD_PTR dwInstance,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
49 DWORD dwParam1, DWORD dwParam2)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
50 {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
51 SDL_AudioDevice *this = (SDL_AudioDevice *) dwInstance;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
52
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
53 /* Only service "buffer done playing" messages */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
54 if (uMsg != WOM_DONE)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
55 return;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
56
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
57 /* Signal that we are done playing a buffer */
36
13ee9f4834ea Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
58 #if defined(_WIN32_WCE) && (_WIN32_WCE < 300)
3841
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
59 ReleaseSemaphoreCE(this->hidden->audio_sem, 1, NULL);
36
13ee9f4834ea Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
60 #else
3841
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
61 ReleaseSemaphore(this->hidden->audio_sem, 1, NULL);
36
13ee9f4834ea Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
62 #endif
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
63 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
64
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
65 static void
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
66 SetMMerror(char *function, MMRESULT code)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
67 {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
68 size_t len;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
69 char errbuf[MAXERRORLENGTH];
36
13ee9f4834ea Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
70 #ifdef _WIN32_WCE
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
71 wchar_t werrbuf[MAXERRORLENGTH];
36
13ee9f4834ea Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
72 #endif
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
73
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
74 SDL_snprintf(errbuf, SDL_arraysize(errbuf), "%s: ", function);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
75 len = SDL_strlen(errbuf);
36
13ee9f4834ea Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
76
13ee9f4834ea Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
77 #ifdef _WIN32_WCE
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
78 /* UNICODE version */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
79 waveOutGetErrorText(code, werrbuf, MAXERRORLENGTH - len);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
80 WideCharToMultiByte(CP_ACP, 0, werrbuf, -1, errbuf + len,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
81 MAXERRORLENGTH - len, NULL, NULL);
36
13ee9f4834ea Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
82 #else
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
83 waveOutGetErrorText(code, errbuf + len, (UINT) (MAXERRORLENGTH - len));
36
13ee9f4834ea Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
84 #endif
13ee9f4834ea Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
85
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
86 SDL_SetError("%s", errbuf);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
87 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
88
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
89 /* Set high priority for the audio thread */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
90 static void
3841
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
91 WINWAVEOUT_ThreadInit(_THIS)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
92 {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
93 SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
94 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
95
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
96 void
3841
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
97 WINWAVEOUT_WaitDevice(_THIS)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
98 {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
99 /* Wait for an audio chunk to finish */
36
13ee9f4834ea Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
100 #if defined(_WIN32_WCE) && (_WIN32_WCE < 300)
3841
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
101 WaitForSemaphoreCE(this->hidden->audio_sem, INFINITE);
36
13ee9f4834ea Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
102 #else
3841
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
103 WaitForSingleObject(this->hidden->audio_sem, INFINITE);
36
13ee9f4834ea Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
104 #endif
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
105 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
106
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
107 Uint8 *
3841
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
108 WINWAVEOUT_GetDeviceBuf(_THIS)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
109 {
3841
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
110 return (Uint8 *) (this->hidden->wavebuf[this->hidden->next_buffer].lpData);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
111 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
112
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
113 void
3841
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
114 WINWAVEOUT_PlayDevice(_THIS)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
115 {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
116 /* Queue it up */
3841
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
117 waveOutWrite(this->hidden->sound,
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
118 &this->hidden->wavebuf[this->hidden->next_buffer],
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
119 sizeof (this->hidden->wavebuf[0]));
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
120 this->hidden->next_buffer = (this->hidden->next_buffer + 1) % NUM_BUFFERS;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
121 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
122
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
123 void
3841
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
124 WINWAVEOUT_WaitDone(_THIS)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
125 {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
126 int i, left;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
127
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
128 do {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
129 left = NUM_BUFFERS;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
130 for (i = 0; i < NUM_BUFFERS; ++i) {
3841
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
131 if (this->hidden->wavebuf[i].dwFlags & WHDR_DONE) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
132 --left;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
133 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
134 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
135 if (left > 0) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
136 SDL_Delay(100);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
137 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
138 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
139 while (left > 0);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
140 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
141
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
142 void
3841
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
143 WINWAVEOUT_CloseDevice(_THIS)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
144 {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
145 /* Close up audio */
3841
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
146 if (this->hidden != NULL) {
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
147 int i;
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
148
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
149 if (this->hidden->audio_sem) {
36
13ee9f4834ea Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
150 #if defined(_WIN32_WCE) && (_WIN32_WCE < 300)
3841
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
151 CloseSynchHandle(this->hidden->audio_sem);
36
13ee9f4834ea Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
152 #else
3841
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
153 CloseHandle(this->hidden->audio_sem);
36
13ee9f4834ea Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
154 #endif
3841
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
155 this->hidden->audio_sem = 0;
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
156 }
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
157
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
158 if (this->hidden->sound) {
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
159 waveOutClose(this->hidden->sound);
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
160 this->hidden->sound = 0;
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
161 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
162
3841
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
163 /* Clean up mixing buffers */
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
164 for (i = 0; i < NUM_BUFFERS; ++i) {
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
165 if (this->hidden->wavebuf[i].dwUser != 0xFFFF) {
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
166 waveOutUnprepareHeader(this->hidden->sound,
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
167 &this->hidden->wavebuf[i],
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
168 sizeof (this->hidden->wavebuf[i]));
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
169 this->hidden->wavebuf[i].dwUser = 0xFFFF;
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
170 }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
171 }
3841
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
172
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
173 if (this->hidden->mixbuf != NULL) {
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
174 /* Free raw mixing buffer */
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
175 SDL_free(this->hidden->mixbuf);
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
176 this->hidden->mixbuf = NULL;
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
177 }
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
178
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
179 SDL_free(this->hidden);
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
180 this->hidden = NULL;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
181 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
182 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
183
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
184 int
3841
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
185 WINWAVEOUT_OpenDevice(_THIS, const char *devname, int iscapture)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
186 {
3841
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
187 SDL_AudioFormat test_format = SDL_FirstAudioFormat(this->spec.format);
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
188 int valid_datatype = 0;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
189 MMRESULT result;
3841
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
190 WAVEFORMATEX waveformat;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
191 int i;
3841
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
192
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
193 /* Initialize all variables that we clean on shutdown */
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
194 this->hidden = (struct SDL_PrivateAudioData *)
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
195 SDL_malloc((sizeof *this->hidden));
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
196 if (this->hidden == NULL) {
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
197 SDL_OutOfMemory();
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
198 return 0;
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
199 }
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
200 SDL_memset(this->hidden, 0, (sizeof *this->hidden));
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
201
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
202 /* Initialize the wavebuf structures for closing */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
203 for (i = 0; i < NUM_BUFFERS; ++i)
3841
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
204 this->hidden->wavebuf[i].dwUser = 0xFFFF;
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
205
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
206 while ((!valid_datatype) && (test_format)) {
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
207 valid_datatype = 1;
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
208 _this->spec.format = test_format;
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
209 switch (test_format) {
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
210 case AUDIO_U8:
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
211 case AUDIO_S16:
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
212 case AUDIO_S32:
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
213 break; /* valid. */
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
214
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
215 default:
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
216 valid_datatype = 0;
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
217 test_format = SDL_NextAudioFormat();
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
218 break;
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
219 }
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
220 }
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
221
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
222 if (!valid_datatype) {
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
223 WINWAVEOUT_CloseDevice(this);
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
224 SDL_SetError("Unsupported audio format");
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
225 return 0;
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
226 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
227
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
228 /* Set basic WAVE format parameters */
3841
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
229 SDL_memset(&waveformat, '\0', sizeof (waveformat));
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
230 waveformat.wFormatTag = WAVE_FORMAT_PCM;
3841
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
231 waveformat.wBitsPerSample = SDL_AUDIO_BITSIZE(this->spec.format);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
232
3841
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
233 if (this->spec.channels > 2)
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
234 this->spec.channels = 2; /* !!! FIXME: is this right? */
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
235
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
236 waveformat.nChannels = this->spec.channels;
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
237 waveformat.nSamplesPerSec = this->spec.freq;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
238 waveformat.nBlockAlign =
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
239 waveformat.nChannels * (waveformat.wBitsPerSample / 8);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
240 waveformat.nAvgBytesPerSec =
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
241 waveformat.nSamplesPerSec * waveformat.nBlockAlign;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
242
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
243 /* Check the buffer size -- minimum of 1/4 second (word aligned) */
3841
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
244 if (this->spec.samples < (this->spec.freq / 4))
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
245 this->spec.samples = ((this->spec.freq / 4) + 3) & ~3;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
246
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
247 /* Update the fragment size as size in bytes */
3841
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
248 SDL_CalculateAudioSpec(&this->spec);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
249
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
250 /* Open the audio device */
3841
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
251 result = waveOutOpen(&this->hidden->sound, WAVE_MAPPER, &waveformat,
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
252 (DWORD_PTR) FillSound, (DWORD_PTR) this,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
253 CALLBACK_FUNCTION);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
254 if (result != MMSYSERR_NOERROR) {
3841
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
255 WINWAVEOUT_CloseDevice(this);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
256 SetMMerror("waveOutOpen()", result);
3841
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
257 return 0;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
258 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
259 #ifdef SOUND_DEBUG
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
260 /* Check the sound device we retrieved */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
261 {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
262 WAVEOUTCAPS caps;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
263
3841
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
264 result = waveOutGetDevCaps((UINT) this->hidden->sound,
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
265 &caps, sizeof(caps));
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
266 if (result != MMSYSERR_NOERROR) {
3841
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
267 WINWAVEOUT_CloseDevice(this);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
268 SetMMerror("waveOutGetDevCaps()", result);
3841
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
269 return 0;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
270 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
271 printf("Audio device: %s\n", caps.szPname);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
272 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
273 #endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
274
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
275 /* Create the audio buffer semaphore */
3841
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
276 this->hidden->audio_sem =
36
13ee9f4834ea Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
277 #if defined(_WIN32_WCE) && (_WIN32_WCE < 300)
3841
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
278 CreateSemaphoreCE(NULL, NUM_BUFFERS - 1, NUM_BUFFERS, NULL);
36
13ee9f4834ea Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
279 #else
3841
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
280 CreateSemaphore(NULL, NUM_BUFFERS - 1, NUM_BUFFERS, NULL);
36
13ee9f4834ea Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
281 #endif
3841
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
282 if (this->hidden->audio_sem == NULL) {
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
283 WINWAVEOUT_CloseDevice(this);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
284 SDL_SetError("Couldn't create semaphore");
3841
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
285 return 0;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
286 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
287
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
288 /* Create the sound buffers */
3841
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
289 this->hidden->mixbuf = (Uint8 *) SDL_malloc(NUM_BUFFERS * this->spec.size);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
290 if (mixbuf == NULL) {
3841
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
291 WINWAVEOUT_CloseDevice(this);
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
292 SDL_OutOfMemory();
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
293 return 0;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
294 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
295 for (i = 0; i < NUM_BUFFERS; ++i) {
3841
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
296 SDL_memset(&this->hidden->wavebuf[i], '\0',
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
297 sizeof (this->hidden->wavebuf[i]));
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
298 this->hidden->wavebuf[i].dwBufferLength = this->spec.size;
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
299 this->hidden->wavebuf[i].dwFlags = WHDR_DONE;
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
300 this->hidden->wavebuf[i].lpData =
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
301 (LPSTR) &this->hidden->mixbuf[i * this->spec.size];
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
302 result = waveOutPrepareHeader(this->hidden->sound,
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
303 &this->hidden->wavebuf[i],
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
304 sizeof (this->hidden->wavebuf[i]));
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
305 if (result != MMSYSERR_NOERROR) {
3841
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
306 WINWAVEOUT_CloseDevice(this);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
307 SetMMerror("waveOutPrepareHeader()", result);
3841
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
308 return 0;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
309 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
310 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
311
3841
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
312 return 1; /* Ready to go! */
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
313 }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
314
3841
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
315
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
316 static int
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
317 WINWAVEOUT_Init(SDL_AudioDriverImpl *impl)
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
318 {
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
319 /* Set the function pointers */
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
320 impl->OpenDevice = WINWAVEOUT_OpenDevice;
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
321 impl->ThreadInit = WINWAVEOUT_ThreadInit;
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
322 impl->PlayDevice = WINWAVEOUT_PlayDevice;
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
323 impl->WaitDevice = WINWAVEOUT_WaitDevice;
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
324 impl->WaitDone = WINWAVEOUT_WaitDone;
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
325 impl->GetDeviceBuf = WINWAVEOUT_GetDeviceBuf;
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
326 impl->CloseDevice = WINWAVEOUT_CloseDevice;
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
327 impl->OnlyHasDefaultOutputDevice = 1; /* !!! FIXME: Is this true? */
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
328
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
329 return 1;
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
330 }
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
331
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
332 AudioBootStrap WINWAVEOUT_bootstrap = {
3846
66fb40445587 Removed distinction between "available" and "init" in audio backends, since
Ryan C. Gordon <icculus@icculus.org>
parents: 3841
diff changeset
333 "waveout", WINDOWS_OS_NAME " WaveOut", WINWAVEOUT_Init, 0
3841
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
334 };
3479f939987c Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
335
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
336 /* vi: set ts=4 sw=4 expandtab: */