Mercurial > sdl-ios-xcode
annotate src/audio/windib/SDL_dibaudio.c @ 3841:3479f939987c SDL-ryan-multiple-audio-device
Moved windib (waveout) audio to 1.3 API and made other cleanups.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Sun, 08 Oct 2006 23:04:24 +0000 |
parents | c8b3d3d13ed1 |
children | 66fb40445587 |
rev | line source |
---|---|
0 | 1 /* |
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 | 4 |
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 | 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 | 9 |
10 This library is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
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 | 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 | 18 |
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 | 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 | 23 |
24 /* Allow access to a raw mixing buffer */ | |
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 | 28 #include <mmsystem.h> |
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 | 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 | 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 | 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 | 45 |
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
|
46 static 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
|
47 WINWAVEOUT_Available(void) |
0 | 48 { |
3841
3479f939987c
Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
3798
diff
changeset
|
49 return 1; /* Always available on win32/pocketpc systems... */ |
0 | 50 } |
51 | |
52 /* 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
|
53 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
|
54 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
|
55 DWORD dwParam1, DWORD dwParam2) |
0 | 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 SDL_AudioDevice *this = (SDL_AudioDevice *) dwInstance; |
0 | 58 |
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
|
59 /* 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
|
60 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
|
61 return; |
0 | 62 |
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
|
63 /* 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
|
64 #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
|
65 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
|
66 #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
|
67 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
|
68 #endif |
0 | 69 } |
70 | |
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 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
|
72 SetMMerror(char *function, MMRESULT code) |
0 | 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 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
|
75 char errbuf[MAXERRORLENGTH]; |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
76 #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
|
77 wchar_t werrbuf[MAXERRORLENGTH]; |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
78 #endif |
0 | 79 |
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
|
80 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
|
81 len = SDL_strlen(errbuf); |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
82 |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
83 #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
|
84 /* 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
|
85 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
|
86 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
|
87 MAXERRORLENGTH - len, NULL, NULL); |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
88 #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
|
89 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
|
90 #endif |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
91 |
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
|
92 SDL_SetError("%s", errbuf); |
0 | 93 } |
94 | |
95 /* 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
|
96 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
|
97 WINWAVEOUT_ThreadInit(_THIS) |
0 | 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 SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST); |
0 | 100 } |
101 | |
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
|
102 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
|
103 WINWAVEOUT_WaitDevice(_THIS) |
0 | 104 { |
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
|
105 /* 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
|
106 #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
|
107 WaitForSemaphoreCE(this->hidden->audio_sem, INFINITE); |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
108 #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
|
109 WaitForSingleObject(this->hidden->audio_sem, INFINITE); |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
110 #endif |
0 | 111 } |
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 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
|
114 WINWAVEOUT_GetDeviceBuf(_THIS) |
0 | 115 { |
3841
3479f939987c
Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
3798
diff
changeset
|
116 return (Uint8 *) (this->hidden->wavebuf[this->hidden->next_buffer].lpData); |
0 | 117 } |
118 | |
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
|
119 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
|
120 WINWAVEOUT_PlayDevice(_THIS) |
0 | 121 { |
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
|
122 /* 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
|
123 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
|
124 &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
|
125 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
|
126 this->hidden->next_buffer = (this->hidden->next_buffer + 1) % NUM_BUFFERS; |
0 | 127 } |
128 | |
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
|
129 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
|
130 WINWAVEOUT_WaitDone(_THIS) |
0 | 131 { |
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 int i, left; |
0 | 133 |
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
|
134 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
|
135 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
|
136 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
|
137 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
|
138 --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
|
139 } |
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
|
140 } |
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
|
141 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
|
142 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
|
143 } |
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
|
144 } |
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 while (left > 0); |
0 | 146 } |
147 | |
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
|
148 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
|
149 WINWAVEOUT_CloseDevice(_THIS) |
0 | 150 { |
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
|
151 /* 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
|
152 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
|
153 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
|
154 |
3479f939987c
Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
3798
diff
changeset
|
155 if (this->hidden->audio_sem) { |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
156 #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
|
157 CloseSynchHandle(this->hidden->audio_sem); |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
158 #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
|
159 CloseHandle(this->hidden->audio_sem); |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
160 #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
|
161 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
|
162 } |
3479f939987c
Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
3798
diff
changeset
|
163 |
3479f939987c
Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
3798
diff
changeset
|
164 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
|
165 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
|
166 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
|
167 } |
0 | 168 |
3841
3479f939987c
Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
3798
diff
changeset
|
169 /* 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
|
170 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
|
171 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
|
172 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
|
173 &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
|
174 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
|
175 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
|
176 } |
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
|
177 } |
3841
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 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
|
180 /* 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
|
181 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
|
182 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
|
183 } |
3479f939987c
Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
3798
diff
changeset
|
184 |
3479f939987c
Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
3798
diff
changeset
|
185 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
|
186 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
|
187 } |
0 | 188 } |
189 | |
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
|
190 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
|
191 WINWAVEOUT_OpenDevice(_THIS, const char *devname, int iscapture) |
0 | 192 { |
3841
3479f939987c
Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
3798
diff
changeset
|
193 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
|
194 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
|
195 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
|
196 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
|
197 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
|
198 |
3479f939987c
Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
3798
diff
changeset
|
199 /* 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
|
200 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
|
201 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
|
202 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
|
203 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
|
204 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
|
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 SDL_memset(this->hidden, 0, (sizeof *this->hidden)); |
0 | 207 |
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
|
208 /* 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
|
209 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
|
210 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
|
211 |
3479f939987c
Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
3798
diff
changeset
|
212 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
|
213 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
|
214 _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
|
215 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
|
216 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
|
217 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
|
218 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
|
219 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
|
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 default: |
3479f939987c
Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
3798
diff
changeset
|
222 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
|
223 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
|
224 break; |
3479f939987c
Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
3798
diff
changeset
|
225 } |
3479f939987c
Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
3798
diff
changeset
|
226 } |
3479f939987c
Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
3798
diff
changeset
|
227 |
3479f939987c
Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
3798
diff
changeset
|
228 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
|
229 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
|
230 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
|
231 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
|
232 } |
0 | 233 |
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
|
234 /* 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
|
235 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
|
236 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
|
237 waveformat.wBitsPerSample = SDL_AUDIO_BITSIZE(this->spec.format); |
0 | 238 |
3841
3479f939987c
Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
3798
diff
changeset
|
239 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
|
240 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
|
241 |
3479f939987c
Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
3798
diff
changeset
|
242 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
|
243 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
|
244 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
|
245 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
|
246 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
|
247 waveformat.nSamplesPerSec * waveformat.nBlockAlign; |
0 | 248 |
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
|
249 /* 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
|
250 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
|
251 this->spec.samples = ((this->spec.freq / 4) + 3) & ~3; |
0 | 252 |
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
|
253 /* 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
|
254 SDL_CalculateAudioSpec(&this->spec); |
0 | 255 |
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 /* 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
|
257 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
|
258 (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
|
259 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
|
260 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
|
261 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
|
262 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
|
263 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
|
264 } |
0 | 265 #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
|
266 /* 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
|
267 { |
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 WAVEOUTCAPS caps; |
0 | 269 |
3841
3479f939987c
Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
3798
diff
changeset
|
270 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
|
271 &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
|
272 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
|
273 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
|
274 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
|
275 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
|
276 } |
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
|
277 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
|
278 } |
0 | 279 #endif |
280 | |
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
|
281 /* 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
|
282 this->hidden->audio_sem = |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
283 #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
|
284 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
|
285 #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
|
286 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
|
287 #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
|
288 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
|
289 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
|
290 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
|
291 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
|
292 } |
0 | 293 |
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 /* 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
|
295 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
|
296 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
|
297 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
|
298 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
|
299 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
|
300 } |
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
|
301 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
|
302 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
|
303 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
|
304 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
|
305 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
|
306 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
|
307 (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
|
308 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
|
309 &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
|
310 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
|
311 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
|
312 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
|
313 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
|
314 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
|
315 } |
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
|
316 } |
0 | 317 |
3841
3479f939987c
Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
3798
diff
changeset
|
318 return 1; /* Ready to go! */ |
0 | 319 } |
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
|
320 |
3841
3479f939987c
Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
3798
diff
changeset
|
321 |
3479f939987c
Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
3798
diff
changeset
|
322 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
|
323 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
|
324 { |
3479f939987c
Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
3798
diff
changeset
|
325 /* 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
|
326 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
|
327 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
|
328 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
|
329 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
|
330 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
|
331 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
|
332 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
|
333 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
|
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 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
|
336 } |
3479f939987c
Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
3798
diff
changeset
|
337 |
3479f939987c
Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
3798
diff
changeset
|
338 AudioBootStrap WINWAVEOUT_bootstrap = { |
3479f939987c
Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
3798
diff
changeset
|
339 "waveout", WINDOWS_OS_NAME " WaveOut", |
3479f939987c
Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
3798
diff
changeset
|
340 WINWAVEOUT_Available, WINWAVEOUT_Init, 0 |
3479f939987c
Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
3798
diff
changeset
|
341 }; |
3479f939987c
Moved windib (waveout) audio to 1.3 API and made other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
3798
diff
changeset
|
342 |
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
|
343 /* vi: set ts=4 sw=4 expandtab: */ |