root / audio / dsoundaudio.c @ 42388c4b
History | View | Annotate | Download (26.5 kB)
1 | 1d14ffa9 | bellard | /*
|
---|---|---|---|
2 | 1d14ffa9 | bellard | * QEMU DirectSound audio driver
|
3 | 1d14ffa9 | bellard | *
|
4 | 1d14ffa9 | bellard | * Copyright (c) 2005 Vassili Karpov (malc)
|
5 | 1d14ffa9 | bellard | *
|
6 | 1d14ffa9 | bellard | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
7 | 1d14ffa9 | bellard | * of this software and associated documentation files (the "Software"), to deal
|
8 | 1d14ffa9 | bellard | * in the Software without restriction, including without limitation the rights
|
9 | 1d14ffa9 | bellard | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10 | 1d14ffa9 | bellard | * copies of the Software, and to permit persons to whom the Software is
|
11 | 1d14ffa9 | bellard | * furnished to do so, subject to the following conditions:
|
12 | 1d14ffa9 | bellard | *
|
13 | 1d14ffa9 | bellard | * The above copyright notice and this permission notice shall be included in
|
14 | 1d14ffa9 | bellard | * all copies or substantial portions of the Software.
|
15 | 1d14ffa9 | bellard | *
|
16 | 1d14ffa9 | bellard | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17 | 1d14ffa9 | bellard | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18 | 1d14ffa9 | bellard | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
19 | 1d14ffa9 | bellard | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20 | 1d14ffa9 | bellard | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21 | 1d14ffa9 | bellard | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22 | 1d14ffa9 | bellard | * THE SOFTWARE.
|
23 | 1d14ffa9 | bellard | */
|
24 | 1d14ffa9 | bellard | |
25 | 1d14ffa9 | bellard | /*
|
26 | 1d14ffa9 | bellard | * SEAL 1.07 by Carlos 'pel' Hasan was used as documentation
|
27 | 1d14ffa9 | bellard | */
|
28 | 1d14ffa9 | bellard | |
29 | 749bc4bf | pbrook | #include "qemu-common.h" |
30 | 749bc4bf | pbrook | #include "audio.h" |
31 | 1d14ffa9 | bellard | |
32 | 1d14ffa9 | bellard | #define AUDIO_CAP "dsound" |
33 | 1d14ffa9 | bellard | #include "audio_int.h" |
34 | 1d14ffa9 | bellard | |
35 | 4fddf62a | ths | #define WIN32_LEAN_AND_MEAN
|
36 | 1d14ffa9 | bellard | #include <windows.h> |
37 | 4fddf62a | ths | #include <mmsystem.h> |
38 | 1d14ffa9 | bellard | #include <objbase.h> |
39 | 1d14ffa9 | bellard | #include <dsound.h> |
40 | 1d14ffa9 | bellard | |
41 | 1d14ffa9 | bellard | /* #define DEBUG_DSOUND */
|
42 | 1d14ffa9 | bellard | |
43 | 1d14ffa9 | bellard | static struct { |
44 | 1d14ffa9 | bellard | int lock_retries;
|
45 | 1d14ffa9 | bellard | int restore_retries;
|
46 | 1d14ffa9 | bellard | int getstatus_retries;
|
47 | 1d14ffa9 | bellard | int set_primary;
|
48 | 1d14ffa9 | bellard | int bufsize_in;
|
49 | 1d14ffa9 | bellard | int bufsize_out;
|
50 | c0fe3827 | bellard | audsettings_t settings; |
51 | 1d14ffa9 | bellard | int latency_millis;
|
52 | 1d14ffa9 | bellard | } conf = { |
53 | 1d14ffa9 | bellard | 1,
|
54 | 1d14ffa9 | bellard | 1,
|
55 | 1d14ffa9 | bellard | 1,
|
56 | 1d14ffa9 | bellard | 0,
|
57 | 1d14ffa9 | bellard | 16384,
|
58 | 1d14ffa9 | bellard | 16384,
|
59 | 1d14ffa9 | bellard | { |
60 | 1d14ffa9 | bellard | 44100,
|
61 | 1d14ffa9 | bellard | 2,
|
62 | 1d14ffa9 | bellard | AUD_FMT_S16 |
63 | 1d14ffa9 | bellard | }, |
64 | 1d14ffa9 | bellard | 10
|
65 | 1d14ffa9 | bellard | }; |
66 | 1d14ffa9 | bellard | |
67 | 1d14ffa9 | bellard | typedef struct { |
68 | 1d14ffa9 | bellard | LPDIRECTSOUND dsound; |
69 | 1d14ffa9 | bellard | LPDIRECTSOUNDCAPTURE dsound_capture; |
70 | 1d14ffa9 | bellard | LPDIRECTSOUNDBUFFER dsound_primary_buffer; |
71 | c0fe3827 | bellard | audsettings_t settings; |
72 | 1d14ffa9 | bellard | } dsound; |
73 | 1d14ffa9 | bellard | |
74 | 1d14ffa9 | bellard | static dsound glob_dsound;
|
75 | 1d14ffa9 | bellard | |
76 | 1d14ffa9 | bellard | typedef struct { |
77 | 1d14ffa9 | bellard | HWVoiceOut hw; |
78 | 1d14ffa9 | bellard | LPDIRECTSOUNDBUFFER dsound_buffer; |
79 | 1d14ffa9 | bellard | DWORD old_pos; |
80 | 1d14ffa9 | bellard | int first_time;
|
81 | 1d14ffa9 | bellard | #ifdef DEBUG_DSOUND
|
82 | 1d14ffa9 | bellard | DWORD old_ppos; |
83 | 1d14ffa9 | bellard | DWORD played; |
84 | 1d14ffa9 | bellard | DWORD mixed; |
85 | 1d14ffa9 | bellard | #endif
|
86 | 1d14ffa9 | bellard | } DSoundVoiceOut; |
87 | 1d14ffa9 | bellard | |
88 | 1d14ffa9 | bellard | typedef struct { |
89 | 1d14ffa9 | bellard | HWVoiceIn hw; |
90 | 1d14ffa9 | bellard | int first_time;
|
91 | 1d14ffa9 | bellard | LPDIRECTSOUNDCAPTUREBUFFER dsound_capture_buffer; |
92 | 1d14ffa9 | bellard | } DSoundVoiceIn; |
93 | 1d14ffa9 | bellard | |
94 | 1d14ffa9 | bellard | static void dsound_log_hresult (HRESULT hr) |
95 | 1d14ffa9 | bellard | { |
96 | 1d14ffa9 | bellard | const char *str = "BUG"; |
97 | 1d14ffa9 | bellard | |
98 | 1d14ffa9 | bellard | switch (hr) {
|
99 | 1d14ffa9 | bellard | case DS_OK:
|
100 | 1d14ffa9 | bellard | str = "The method succeeded";
|
101 | 1d14ffa9 | bellard | break;
|
102 | 1d14ffa9 | bellard | #ifdef DS_NO_VIRTUALIZATION
|
103 | 1d14ffa9 | bellard | case DS_NO_VIRTUALIZATION:
|
104 | 1d14ffa9 | bellard | str = "The buffer was created, but another 3D algorithm was substituted";
|
105 | 1d14ffa9 | bellard | break;
|
106 | 1d14ffa9 | bellard | #endif
|
107 | 1d14ffa9 | bellard | #ifdef DS_INCOMPLETE
|
108 | 1d14ffa9 | bellard | case DS_INCOMPLETE:
|
109 | 1d14ffa9 | bellard | str = "The method succeeded, but not all the optional effects were obtained";
|
110 | 1d14ffa9 | bellard | break;
|
111 | 1d14ffa9 | bellard | #endif
|
112 | 1d14ffa9 | bellard | #ifdef DSERR_ACCESSDENIED
|
113 | 1d14ffa9 | bellard | case DSERR_ACCESSDENIED:
|
114 | 1d14ffa9 | bellard | str = "The request failed because access was denied";
|
115 | 1d14ffa9 | bellard | break;
|
116 | 1d14ffa9 | bellard | #endif
|
117 | 1d14ffa9 | bellard | #ifdef DSERR_ALLOCATED
|
118 | 1d14ffa9 | bellard | case DSERR_ALLOCATED:
|
119 | 1d14ffa9 | bellard | str = "The request failed because resources, such as a priority level, were already in use by another caller";
|
120 | 1d14ffa9 | bellard | break;
|
121 | 1d14ffa9 | bellard | #endif
|
122 | 1d14ffa9 | bellard | #ifdef DSERR_ALREADYINITIALIZED
|
123 | 1d14ffa9 | bellard | case DSERR_ALREADYINITIALIZED:
|
124 | 1d14ffa9 | bellard | str = "The object is already initialized";
|
125 | 1d14ffa9 | bellard | break;
|
126 | 1d14ffa9 | bellard | #endif
|
127 | 1d14ffa9 | bellard | #ifdef DSERR_BADFORMAT
|
128 | 1d14ffa9 | bellard | case DSERR_BADFORMAT:
|
129 | 1d14ffa9 | bellard | str = "The specified wave format is not supported";
|
130 | 1d14ffa9 | bellard | break;
|
131 | 1d14ffa9 | bellard | #endif
|
132 | 1d14ffa9 | bellard | #ifdef DSERR_BADSENDBUFFERGUID
|
133 | 1d14ffa9 | bellard | case DSERR_BADSENDBUFFERGUID:
|
134 | 1d14ffa9 | bellard | str = "The GUID specified in an audiopath file does not match a valid mix-in buffer";
|
135 | 1d14ffa9 | bellard | break;
|
136 | 1d14ffa9 | bellard | #endif
|
137 | 1d14ffa9 | bellard | #ifdef DSERR_BUFFERLOST
|
138 | 1d14ffa9 | bellard | case DSERR_BUFFERLOST:
|
139 | 1d14ffa9 | bellard | str = "The buffer memory has been lost and must be restored";
|
140 | 1d14ffa9 | bellard | break;
|
141 | 1d14ffa9 | bellard | #endif
|
142 | 1d14ffa9 | bellard | #ifdef DSERR_BUFFERTOOSMALL
|
143 | 1d14ffa9 | bellard | case DSERR_BUFFERTOOSMALL:
|
144 | 1d14ffa9 | bellard | str = "The buffer size is not great enough to enable effects processing";
|
145 | 1d14ffa9 | bellard | break;
|
146 | 1d14ffa9 | bellard | #endif
|
147 | 1d14ffa9 | bellard | #ifdef DSERR_CONTROLUNAVAIL
|
148 | 1d14ffa9 | bellard | case DSERR_CONTROLUNAVAIL:
|
149 | 1d14ffa9 | bellard | str = "The buffer control (volume, pan, and so on) requested by the caller is not available. Controls must be specified when the buffer is created, using the dwFlags member of DSBUFFERDESC";
|
150 | 1d14ffa9 | bellard | break;
|
151 | 1d14ffa9 | bellard | #endif
|
152 | 1d14ffa9 | bellard | #ifdef DSERR_DS8_REQUIRED
|
153 | 1d14ffa9 | bellard | case DSERR_DS8_REQUIRED:
|
154 | 1d14ffa9 | bellard | str = "A DirectSound object of class CLSID_DirectSound8 or later is required for the requested functionality. For more information, see IDirectSound8 Interface";
|
155 | 1d14ffa9 | bellard | break;
|
156 | 1d14ffa9 | bellard | #endif
|
157 | 1d14ffa9 | bellard | #ifdef DSERR_FXUNAVAILABLE
|
158 | 1d14ffa9 | bellard | case DSERR_FXUNAVAILABLE:
|
159 | 1d14ffa9 | bellard | str = "The effects requested could not be found on the system, or they are in the wrong order or in the wrong location; for example, an effect expected in hardware was found in software";
|
160 | 1d14ffa9 | bellard | break;
|
161 | 1d14ffa9 | bellard | #endif
|
162 | 1d14ffa9 | bellard | #ifdef DSERR_GENERIC
|
163 | 1d14ffa9 | bellard | case DSERR_GENERIC :
|
164 | 1d14ffa9 | bellard | str = "An undetermined error occurred inside the DirectSound subsystem";
|
165 | 1d14ffa9 | bellard | break;
|
166 | 1d14ffa9 | bellard | #endif
|
167 | 1d14ffa9 | bellard | #ifdef DSERR_INVALIDCALL
|
168 | 1d14ffa9 | bellard | case DSERR_INVALIDCALL:
|
169 | 1d14ffa9 | bellard | str = "This function is not valid for the current state of this object";
|
170 | 1d14ffa9 | bellard | break;
|
171 | 1d14ffa9 | bellard | #endif
|
172 | 1d14ffa9 | bellard | #ifdef DSERR_INVALIDPARAM
|
173 | 1d14ffa9 | bellard | case DSERR_INVALIDPARAM:
|
174 | 1d14ffa9 | bellard | str = "An invalid parameter was passed to the returning function";
|
175 | 1d14ffa9 | bellard | break;
|
176 | 1d14ffa9 | bellard | #endif
|
177 | 1d14ffa9 | bellard | #ifdef DSERR_NOAGGREGATION
|
178 | 1d14ffa9 | bellard | case DSERR_NOAGGREGATION:
|
179 | 1d14ffa9 | bellard | str = "The object does not support aggregation";
|
180 | 1d14ffa9 | bellard | break;
|
181 | 1d14ffa9 | bellard | #endif
|
182 | 1d14ffa9 | bellard | #ifdef DSERR_NODRIVER
|
183 | 1d14ffa9 | bellard | case DSERR_NODRIVER:
|
184 | 1d14ffa9 | bellard | str = "No sound driver is available for use, or the given GUID is not a valid DirectSound device ID";
|
185 | 1d14ffa9 | bellard | break;
|
186 | 1d14ffa9 | bellard | #endif
|
187 | 1d14ffa9 | bellard | #ifdef DSERR_NOINTERFACE
|
188 | 1d14ffa9 | bellard | case DSERR_NOINTERFACE:
|
189 | 1d14ffa9 | bellard | str = "The requested COM interface is not available";
|
190 | 1d14ffa9 | bellard | break;
|
191 | 1d14ffa9 | bellard | #endif
|
192 | 1d14ffa9 | bellard | #ifdef DSERR_OBJECTNOTFOUND
|
193 | 1d14ffa9 | bellard | case DSERR_OBJECTNOTFOUND:
|
194 | 1d14ffa9 | bellard | str = "The requested object was not found";
|
195 | 1d14ffa9 | bellard | break;
|
196 | 1d14ffa9 | bellard | #endif
|
197 | 1d14ffa9 | bellard | #ifdef DSERR_OTHERAPPHASPRIO
|
198 | 1d14ffa9 | bellard | case DSERR_OTHERAPPHASPRIO:
|
199 | 1d14ffa9 | bellard | str = "Another application has a higher priority level, preventing this call from succeeding";
|
200 | 1d14ffa9 | bellard | break;
|
201 | 1d14ffa9 | bellard | #endif
|
202 | 1d14ffa9 | bellard | #ifdef DSERR_OUTOFMEMORY
|
203 | 1d14ffa9 | bellard | case DSERR_OUTOFMEMORY:
|
204 | 1d14ffa9 | bellard | str = "The DirectSound subsystem could not allocate sufficient memory to complete the caller's request";
|
205 | 1d14ffa9 | bellard | break;
|
206 | 1d14ffa9 | bellard | #endif
|
207 | 1d14ffa9 | bellard | #ifdef DSERR_PRIOLEVELNEEDED
|
208 | 1d14ffa9 | bellard | case DSERR_PRIOLEVELNEEDED:
|
209 | 1d14ffa9 | bellard | str = "A cooperative level of DSSCL_PRIORITY or higher is required";
|
210 | 1d14ffa9 | bellard | break;
|
211 | 1d14ffa9 | bellard | #endif
|
212 | 1d14ffa9 | bellard | #ifdef DSERR_SENDLOOP
|
213 | 1d14ffa9 | bellard | case DSERR_SENDLOOP:
|
214 | 1d14ffa9 | bellard | str = "A circular loop of send effects was detected";
|
215 | 1d14ffa9 | bellard | break;
|
216 | 1d14ffa9 | bellard | #endif
|
217 | 1d14ffa9 | bellard | #ifdef DSERR_UNINITIALIZED
|
218 | 1d14ffa9 | bellard | case DSERR_UNINITIALIZED:
|
219 | 1d14ffa9 | bellard | str = "The Initialize method has not been called or has not been called successfully before other methods were called";
|
220 | 1d14ffa9 | bellard | break;
|
221 | 1d14ffa9 | bellard | #endif
|
222 | 1d14ffa9 | bellard | #ifdef DSERR_UNSUPPORTED
|
223 | 1d14ffa9 | bellard | case DSERR_UNSUPPORTED:
|
224 | 1d14ffa9 | bellard | str = "The function called is not supported at this time";
|
225 | 1d14ffa9 | bellard | break;
|
226 | 1d14ffa9 | bellard | #endif
|
227 | 1d14ffa9 | bellard | default:
|
228 | 1d14ffa9 | bellard | AUD_log (AUDIO_CAP, "Reason: Unknown (HRESULT %#lx)\n", hr);
|
229 | 1d14ffa9 | bellard | return;
|
230 | 1d14ffa9 | bellard | } |
231 | 1d14ffa9 | bellard | |
232 | 1d14ffa9 | bellard | AUD_log (AUDIO_CAP, "Reason: %s\n", str);
|
233 | 1d14ffa9 | bellard | } |
234 | 1d14ffa9 | bellard | |
235 | 1d14ffa9 | bellard | static void GCC_FMT_ATTR (2, 3) dsound_logerr ( |
236 | 1d14ffa9 | bellard | HRESULT hr, |
237 | 1d14ffa9 | bellard | const char *fmt, |
238 | 1d14ffa9 | bellard | ... |
239 | 1d14ffa9 | bellard | ) |
240 | 1d14ffa9 | bellard | { |
241 | 1d14ffa9 | bellard | va_list ap; |
242 | 1d14ffa9 | bellard | |
243 | 1d14ffa9 | bellard | va_start (ap, fmt); |
244 | 1d14ffa9 | bellard | AUD_vlog (AUDIO_CAP, fmt, ap); |
245 | 1d14ffa9 | bellard | va_end (ap); |
246 | 1d14ffa9 | bellard | |
247 | 1d14ffa9 | bellard | dsound_log_hresult (hr); |
248 | 1d14ffa9 | bellard | } |
249 | 1d14ffa9 | bellard | |
250 | 1d14ffa9 | bellard | static void GCC_FMT_ATTR (3, 4) dsound_logerr2 ( |
251 | 1d14ffa9 | bellard | HRESULT hr, |
252 | 1d14ffa9 | bellard | const char *typ, |
253 | 1d14ffa9 | bellard | const char *fmt, |
254 | 1d14ffa9 | bellard | ... |
255 | 1d14ffa9 | bellard | ) |
256 | 1d14ffa9 | bellard | { |
257 | 1d14ffa9 | bellard | va_list ap; |
258 | 1d14ffa9 | bellard | |
259 | c0fe3827 | bellard | AUD_log (AUDIO_CAP, "Could not initialize %s\n", typ);
|
260 | 1d14ffa9 | bellard | va_start (ap, fmt); |
261 | 1d14ffa9 | bellard | AUD_vlog (AUDIO_CAP, fmt, ap); |
262 | 1d14ffa9 | bellard | va_end (ap); |
263 | 1d14ffa9 | bellard | |
264 | 1d14ffa9 | bellard | dsound_log_hresult (hr); |
265 | 1d14ffa9 | bellard | } |
266 | 1d14ffa9 | bellard | |
267 | 1d14ffa9 | bellard | static DWORD millis_to_bytes (struct audio_pcm_info *info, DWORD millis) |
268 | 1d14ffa9 | bellard | { |
269 | 1d14ffa9 | bellard | return (millis * info->bytes_per_second) / 1000; |
270 | 1d14ffa9 | bellard | } |
271 | 1d14ffa9 | bellard | |
272 | 1d14ffa9 | bellard | #ifdef DEBUG_DSOUND
|
273 | 1d14ffa9 | bellard | static void print_wave_format (WAVEFORMATEX *wfx) |
274 | 1d14ffa9 | bellard | { |
275 | 1d14ffa9 | bellard | dolog ("tag = %d\n", wfx->wFormatTag);
|
276 | 1d14ffa9 | bellard | dolog ("nChannels = %d\n", wfx->nChannels);
|
277 | 1d14ffa9 | bellard | dolog ("nSamplesPerSec = %ld\n", wfx->nSamplesPerSec);
|
278 | 1d14ffa9 | bellard | dolog ("nAvgBytesPerSec = %ld\n", wfx->nAvgBytesPerSec);
|
279 | 1d14ffa9 | bellard | dolog ("nBlockAlign = %d\n", wfx->nBlockAlign);
|
280 | 1d14ffa9 | bellard | dolog ("wBitsPerSample = %d\n", wfx->wBitsPerSample);
|
281 | 1d14ffa9 | bellard | dolog ("cbSize = %d\n", wfx->cbSize);
|
282 | 1d14ffa9 | bellard | } |
283 | 1d14ffa9 | bellard | #endif
|
284 | 1d14ffa9 | bellard | |
285 | 1d14ffa9 | bellard | static int dsound_restore_out (LPDIRECTSOUNDBUFFER dsb) |
286 | 1d14ffa9 | bellard | { |
287 | 1d14ffa9 | bellard | HRESULT hr; |
288 | 1d14ffa9 | bellard | int i;
|
289 | 1d14ffa9 | bellard | |
290 | 1d14ffa9 | bellard | for (i = 0; i < conf.restore_retries; ++i) { |
291 | 1d14ffa9 | bellard | hr = IDirectSoundBuffer_Restore (dsb); |
292 | 1d14ffa9 | bellard | |
293 | 1d14ffa9 | bellard | switch (hr) {
|
294 | 1d14ffa9 | bellard | case DS_OK:
|
295 | 1d14ffa9 | bellard | return 0; |
296 | 1d14ffa9 | bellard | |
297 | 1d14ffa9 | bellard | case DSERR_BUFFERLOST:
|
298 | 1d14ffa9 | bellard | continue;
|
299 | 1d14ffa9 | bellard | |
300 | 1d14ffa9 | bellard | default:
|
301 | c0fe3827 | bellard | dsound_logerr (hr, "Could not restore playback buffer\n");
|
302 | 1d14ffa9 | bellard | return -1; |
303 | 1d14ffa9 | bellard | } |
304 | 1d14ffa9 | bellard | } |
305 | 1d14ffa9 | bellard | |
306 | 1d14ffa9 | bellard | dolog ("%d attempts to restore playback buffer failed\n", i);
|
307 | 1d14ffa9 | bellard | return -1; |
308 | 1d14ffa9 | bellard | } |
309 | 1d14ffa9 | bellard | |
310 | c0fe3827 | bellard | static int waveformat_from_audio_settings (WAVEFORMATEX *wfx, audsettings_t *as) |
311 | 1d14ffa9 | bellard | { |
312 | 1d14ffa9 | bellard | memset (wfx, 0, sizeof (*wfx)); |
313 | 1d14ffa9 | bellard | |
314 | 1d14ffa9 | bellard | wfx->wFormatTag = WAVE_FORMAT_PCM; |
315 | c0fe3827 | bellard | wfx->nChannels = as->nchannels; |
316 | c0fe3827 | bellard | wfx->nSamplesPerSec = as->freq; |
317 | c0fe3827 | bellard | wfx->nAvgBytesPerSec = as->freq << (as->nchannels == 2);
|
318 | c0fe3827 | bellard | wfx->nBlockAlign = 1 << (as->nchannels == 2); |
319 | 1d14ffa9 | bellard | wfx->cbSize = 0;
|
320 | 1d14ffa9 | bellard | |
321 | c0fe3827 | bellard | switch (as->fmt) {
|
322 | 1d14ffa9 | bellard | case AUD_FMT_S8:
|
323 | 1d14ffa9 | bellard | case AUD_FMT_U8:
|
324 | 1d14ffa9 | bellard | wfx->wBitsPerSample = 8;
|
325 | 1d14ffa9 | bellard | break;
|
326 | 1d14ffa9 | bellard | |
327 | 1d14ffa9 | bellard | case AUD_FMT_S16:
|
328 | ca9cc28c | balrog | case AUD_FMT_U16:
|
329 | 1d14ffa9 | bellard | wfx->wBitsPerSample = 16;
|
330 | 1d14ffa9 | bellard | wfx->nAvgBytesPerSec <<= 1;
|
331 | 1d14ffa9 | bellard | wfx->nBlockAlign <<= 1;
|
332 | 1d14ffa9 | bellard | break;
|
333 | 1d14ffa9 | bellard | |
334 | ca9cc28c | balrog | case AUD_FMT_S32:
|
335 | ca9cc28c | balrog | case AUD_FMT_U32:
|
336 | ca9cc28c | balrog | wfx->wBitsPerSample = 32;
|
337 | ca9cc28c | balrog | wfx->nAvgBytesPerSec <<= 2;
|
338 | ca9cc28c | balrog | wfx->nBlockAlign <<= 2;
|
339 | 1d14ffa9 | bellard | break;
|
340 | 1d14ffa9 | bellard | |
341 | 1d14ffa9 | bellard | default:
|
342 | c0fe3827 | bellard | dolog ("Internal logic error: Bad audio format %d\n", as->freq);
|
343 | 1d14ffa9 | bellard | return -1; |
344 | 1d14ffa9 | bellard | } |
345 | 1d14ffa9 | bellard | |
346 | 1d14ffa9 | bellard | return 0; |
347 | 1d14ffa9 | bellard | } |
348 | 1d14ffa9 | bellard | |
349 | c0fe3827 | bellard | static int waveformat_to_audio_settings (WAVEFORMATEX *wfx, audsettings_t *as) |
350 | 1d14ffa9 | bellard | { |
351 | 1d14ffa9 | bellard | if (wfx->wFormatTag != WAVE_FORMAT_PCM) {
|
352 | 1d14ffa9 | bellard | dolog ("Invalid wave format, tag is not PCM, but %d\n",
|
353 | 1d14ffa9 | bellard | wfx->wFormatTag); |
354 | 1d14ffa9 | bellard | return -1; |
355 | 1d14ffa9 | bellard | } |
356 | 1d14ffa9 | bellard | |
357 | 1d14ffa9 | bellard | if (!wfx->nSamplesPerSec) {
|
358 | 1d14ffa9 | bellard | dolog ("Invalid wave format, frequency is zero\n");
|
359 | 1d14ffa9 | bellard | return -1; |
360 | 1d14ffa9 | bellard | } |
361 | c0fe3827 | bellard | as->freq = wfx->nSamplesPerSec; |
362 | 1d14ffa9 | bellard | |
363 | 1d14ffa9 | bellard | switch (wfx->nChannels) {
|
364 | 1d14ffa9 | bellard | case 1: |
365 | c0fe3827 | bellard | as->nchannels = 1;
|
366 | 1d14ffa9 | bellard | break;
|
367 | 1d14ffa9 | bellard | |
368 | 1d14ffa9 | bellard | case 2: |
369 | c0fe3827 | bellard | as->nchannels = 2;
|
370 | 1d14ffa9 | bellard | break;
|
371 | 1d14ffa9 | bellard | |
372 | 1d14ffa9 | bellard | default:
|
373 | 1d14ffa9 | bellard | dolog ( |
374 | 1d14ffa9 | bellard | "Invalid wave format, number of channels is not 1 or 2, but %d\n",
|
375 | 1d14ffa9 | bellard | wfx->nChannels |
376 | 1d14ffa9 | bellard | ); |
377 | 1d14ffa9 | bellard | return -1; |
378 | 1d14ffa9 | bellard | } |
379 | 1d14ffa9 | bellard | |
380 | 1d14ffa9 | bellard | switch (wfx->wBitsPerSample) {
|
381 | 1d14ffa9 | bellard | case 8: |
382 | c0fe3827 | bellard | as->fmt = AUD_FMT_U8; |
383 | 1d14ffa9 | bellard | break;
|
384 | 1d14ffa9 | bellard | |
385 | 1d14ffa9 | bellard | case 16: |
386 | c0fe3827 | bellard | as->fmt = AUD_FMT_S16; |
387 | 1d14ffa9 | bellard | break;
|
388 | 1d14ffa9 | bellard | |
389 | ca9cc28c | balrog | case 32: |
390 | ca9cc28c | balrog | as->fmt = AUD_FMT_S32; |
391 | ca9cc28c | balrog | break;
|
392 | ca9cc28c | balrog | |
393 | 1d14ffa9 | bellard | default:
|
394 | ca9cc28c | balrog | dolog ("Invalid wave format, bits per sample is not "
|
395 | ca9cc28c | balrog | "8, 16 or 32, but %d\n",
|
396 | 1d14ffa9 | bellard | wfx->wBitsPerSample); |
397 | 1d14ffa9 | bellard | return -1; |
398 | 1d14ffa9 | bellard | } |
399 | 1d14ffa9 | bellard | |
400 | 1d14ffa9 | bellard | return 0; |
401 | 1d14ffa9 | bellard | } |
402 | 1d14ffa9 | bellard | |
403 | 1d14ffa9 | bellard | #include "dsound_template.h" |
404 | 1d14ffa9 | bellard | #define DSBTYPE_IN
|
405 | 1d14ffa9 | bellard | #include "dsound_template.h" |
406 | 1d14ffa9 | bellard | #undef DSBTYPE_IN
|
407 | 1d14ffa9 | bellard | |
408 | 1d14ffa9 | bellard | static int dsound_get_status_out (LPDIRECTSOUNDBUFFER dsb, DWORD *statusp) |
409 | 1d14ffa9 | bellard | { |
410 | 1d14ffa9 | bellard | HRESULT hr; |
411 | 1d14ffa9 | bellard | int i;
|
412 | 1d14ffa9 | bellard | |
413 | 1d14ffa9 | bellard | for (i = 0; i < conf.getstatus_retries; ++i) { |
414 | 1d14ffa9 | bellard | hr = IDirectSoundBuffer_GetStatus (dsb, statusp); |
415 | 1d14ffa9 | bellard | if (FAILED (hr)) {
|
416 | c0fe3827 | bellard | dsound_logerr (hr, "Could not get playback buffer status\n");
|
417 | 1d14ffa9 | bellard | return -1; |
418 | 1d14ffa9 | bellard | } |
419 | 1d14ffa9 | bellard | |
420 | 1d14ffa9 | bellard | if (*statusp & DSERR_BUFFERLOST) {
|
421 | 1d14ffa9 | bellard | if (dsound_restore_out (dsb)) {
|
422 | 1d14ffa9 | bellard | return -1; |
423 | 1d14ffa9 | bellard | } |
424 | 1d14ffa9 | bellard | continue;
|
425 | 1d14ffa9 | bellard | } |
426 | 1d14ffa9 | bellard | break;
|
427 | 1d14ffa9 | bellard | } |
428 | 1d14ffa9 | bellard | |
429 | 1d14ffa9 | bellard | return 0; |
430 | 1d14ffa9 | bellard | } |
431 | 1d14ffa9 | bellard | |
432 | 1d14ffa9 | bellard | static int dsound_get_status_in (LPDIRECTSOUNDCAPTUREBUFFER dscb, |
433 | 1d14ffa9 | bellard | DWORD *statusp) |
434 | 1d14ffa9 | bellard | { |
435 | 1d14ffa9 | bellard | HRESULT hr; |
436 | 1d14ffa9 | bellard | |
437 | 1d14ffa9 | bellard | hr = IDirectSoundCaptureBuffer_GetStatus (dscb, statusp); |
438 | 1d14ffa9 | bellard | if (FAILED (hr)) {
|
439 | c0fe3827 | bellard | dsound_logerr (hr, "Could not get capture buffer status\n");
|
440 | 1d14ffa9 | bellard | return -1; |
441 | 1d14ffa9 | bellard | } |
442 | 1d14ffa9 | bellard | |
443 | 1d14ffa9 | bellard | return 0; |
444 | 1d14ffa9 | bellard | } |
445 | 1d14ffa9 | bellard | |
446 | 1d14ffa9 | bellard | static void dsound_write_sample (HWVoiceOut *hw, uint8_t *dst, int dst_len) |
447 | 1d14ffa9 | bellard | { |
448 | 1d14ffa9 | bellard | int src_len1 = dst_len;
|
449 | 1d14ffa9 | bellard | int src_len2 = 0; |
450 | 1d14ffa9 | bellard | int pos = hw->rpos + dst_len;
|
451 | 1d14ffa9 | bellard | st_sample_t *src1 = hw->mix_buf + hw->rpos; |
452 | 1d14ffa9 | bellard | st_sample_t *src2 = NULL;
|
453 | 1d14ffa9 | bellard | |
454 | 1d14ffa9 | bellard | if (pos > hw->samples) {
|
455 | 1d14ffa9 | bellard | src_len1 = hw->samples - hw->rpos; |
456 | 1d14ffa9 | bellard | src2 = hw->mix_buf; |
457 | 1d14ffa9 | bellard | src_len2 = dst_len - src_len1; |
458 | 1d14ffa9 | bellard | pos = src_len2; |
459 | 1d14ffa9 | bellard | } |
460 | 1d14ffa9 | bellard | |
461 | 1d14ffa9 | bellard | if (src_len1) {
|
462 | 1d14ffa9 | bellard | hw->clip (dst, src1, src_len1); |
463 | 1d14ffa9 | bellard | } |
464 | 1d14ffa9 | bellard | |
465 | 1d14ffa9 | bellard | if (src_len2) {
|
466 | 1d14ffa9 | bellard | dst = advance (dst, src_len1 << hw->info.shift); |
467 | 1d14ffa9 | bellard | hw->clip (dst, src2, src_len2); |
468 | 1d14ffa9 | bellard | } |
469 | 1d14ffa9 | bellard | |
470 | 1d14ffa9 | bellard | hw->rpos = pos % hw->samples; |
471 | 1d14ffa9 | bellard | } |
472 | 1d14ffa9 | bellard | |
473 | 1d14ffa9 | bellard | static void dsound_clear_sample (HWVoiceOut *hw, LPDIRECTSOUNDBUFFER dsb) |
474 | 1d14ffa9 | bellard | { |
475 | 1d14ffa9 | bellard | int err;
|
476 | 1d14ffa9 | bellard | LPVOID p1, p2; |
477 | 1d14ffa9 | bellard | DWORD blen1, blen2, len1, len2; |
478 | 1d14ffa9 | bellard | |
479 | 1d14ffa9 | bellard | err = dsound_lock_out ( |
480 | 1d14ffa9 | bellard | dsb, |
481 | 1d14ffa9 | bellard | &hw->info, |
482 | 1d14ffa9 | bellard | 0,
|
483 | 1d14ffa9 | bellard | hw->samples << hw->info.shift, |
484 | 1d14ffa9 | bellard | &p1, &p2, |
485 | 1d14ffa9 | bellard | &blen1, &blen2, |
486 | 1d14ffa9 | bellard | 1
|
487 | 1d14ffa9 | bellard | ); |
488 | 1d14ffa9 | bellard | if (err) {
|
489 | 1d14ffa9 | bellard | return;
|
490 | 1d14ffa9 | bellard | } |
491 | 1d14ffa9 | bellard | |
492 | 1d14ffa9 | bellard | len1 = blen1 >> hw->info.shift; |
493 | 1d14ffa9 | bellard | len2 = blen2 >> hw->info.shift; |
494 | 1d14ffa9 | bellard | |
495 | 1d14ffa9 | bellard | #ifdef DEBUG_DSOUND
|
496 | 1d14ffa9 | bellard | dolog ("clear %p,%ld,%ld %p,%ld,%ld\n",
|
497 | 1d14ffa9 | bellard | p1, blen1, len1, |
498 | 1d14ffa9 | bellard | p2, blen2, len2); |
499 | 1d14ffa9 | bellard | #endif
|
500 | 1d14ffa9 | bellard | |
501 | 1d14ffa9 | bellard | if (p1 && len1) {
|
502 | 1d14ffa9 | bellard | audio_pcm_info_clear_buf (&hw->info, p1, len1); |
503 | 1d14ffa9 | bellard | } |
504 | 1d14ffa9 | bellard | |
505 | 1d14ffa9 | bellard | if (p2 && len2) {
|
506 | 1d14ffa9 | bellard | audio_pcm_info_clear_buf (&hw->info, p2, len2); |
507 | 1d14ffa9 | bellard | } |
508 | 1d14ffa9 | bellard | |
509 | 1d14ffa9 | bellard | dsound_unlock_out (dsb, p1, p2, blen1, blen2); |
510 | 1d14ffa9 | bellard | } |
511 | 1d14ffa9 | bellard | |
512 | 1d14ffa9 | bellard | static void dsound_close (dsound *s) |
513 | 1d14ffa9 | bellard | { |
514 | 1d14ffa9 | bellard | HRESULT hr; |
515 | 1d14ffa9 | bellard | |
516 | 1d14ffa9 | bellard | if (s->dsound_primary_buffer) {
|
517 | 1d14ffa9 | bellard | hr = IDirectSoundBuffer_Release (s->dsound_primary_buffer); |
518 | 1d14ffa9 | bellard | if (FAILED (hr)) {
|
519 | c0fe3827 | bellard | dsound_logerr (hr, "Could not release primary buffer\n");
|
520 | 1d14ffa9 | bellard | } |
521 | 1d14ffa9 | bellard | s->dsound_primary_buffer = NULL;
|
522 | 1d14ffa9 | bellard | } |
523 | 1d14ffa9 | bellard | } |
524 | 1d14ffa9 | bellard | |
525 | 1d14ffa9 | bellard | static int dsound_open (dsound *s) |
526 | 1d14ffa9 | bellard | { |
527 | 1d14ffa9 | bellard | int err;
|
528 | 1d14ffa9 | bellard | HRESULT hr; |
529 | 1d14ffa9 | bellard | WAVEFORMATEX wfx; |
530 | 1d14ffa9 | bellard | DSBUFFERDESC dsbd; |
531 | 1d14ffa9 | bellard | HWND hwnd; |
532 | 1d14ffa9 | bellard | |
533 | 1d14ffa9 | bellard | hwnd = GetForegroundWindow (); |
534 | 1d14ffa9 | bellard | hr = IDirectSound_SetCooperativeLevel ( |
535 | 1d14ffa9 | bellard | s->dsound, |
536 | 1d14ffa9 | bellard | hwnd, |
537 | 1d14ffa9 | bellard | DSSCL_PRIORITY |
538 | 1d14ffa9 | bellard | ); |
539 | 1d14ffa9 | bellard | |
540 | 1d14ffa9 | bellard | if (FAILED (hr)) {
|
541 | c0fe3827 | bellard | dsound_logerr (hr, "Could not set cooperative level for window %p\n",
|
542 | 1d14ffa9 | bellard | hwnd); |
543 | 1d14ffa9 | bellard | return -1; |
544 | 1d14ffa9 | bellard | } |
545 | 1d14ffa9 | bellard | |
546 | 1d14ffa9 | bellard | if (!conf.set_primary) {
|
547 | 1d14ffa9 | bellard | return 0; |
548 | 1d14ffa9 | bellard | } |
549 | 1d14ffa9 | bellard | |
550 | c0fe3827 | bellard | err = waveformat_from_audio_settings (&wfx, &conf.settings); |
551 | 1d14ffa9 | bellard | if (err) {
|
552 | 1d14ffa9 | bellard | return -1; |
553 | 1d14ffa9 | bellard | } |
554 | 1d14ffa9 | bellard | |
555 | 1d14ffa9 | bellard | memset (&dsbd, 0, sizeof (dsbd)); |
556 | 1d14ffa9 | bellard | dsbd.dwSize = sizeof (dsbd);
|
557 | 1d14ffa9 | bellard | dsbd.dwFlags = DSBCAPS_PRIMARYBUFFER; |
558 | 1d14ffa9 | bellard | dsbd.dwBufferBytes = 0;
|
559 | 1d14ffa9 | bellard | dsbd.lpwfxFormat = NULL;
|
560 | 1d14ffa9 | bellard | |
561 | 1d14ffa9 | bellard | hr = IDirectSound_CreateSoundBuffer ( |
562 | 1d14ffa9 | bellard | s->dsound, |
563 | 1d14ffa9 | bellard | &dsbd, |
564 | 1d14ffa9 | bellard | &s->dsound_primary_buffer, |
565 | 1d14ffa9 | bellard | NULL
|
566 | 1d14ffa9 | bellard | ); |
567 | 1d14ffa9 | bellard | if (FAILED (hr)) {
|
568 | c0fe3827 | bellard | dsound_logerr (hr, "Could not create primary playback buffer\n");
|
569 | 1d14ffa9 | bellard | return -1; |
570 | 1d14ffa9 | bellard | } |
571 | 1d14ffa9 | bellard | |
572 | 1d14ffa9 | bellard | hr = IDirectSoundBuffer_SetFormat (s->dsound_primary_buffer, &wfx); |
573 | 1d14ffa9 | bellard | if (FAILED (hr)) {
|
574 | c0fe3827 | bellard | dsound_logerr (hr, "Could not set primary playback buffer format\n");
|
575 | 1d14ffa9 | bellard | } |
576 | 1d14ffa9 | bellard | |
577 | 1d14ffa9 | bellard | hr = IDirectSoundBuffer_GetFormat ( |
578 | 1d14ffa9 | bellard | s->dsound_primary_buffer, |
579 | 1d14ffa9 | bellard | &wfx, |
580 | 1d14ffa9 | bellard | sizeof (wfx),
|
581 | 1d14ffa9 | bellard | NULL
|
582 | 1d14ffa9 | bellard | ); |
583 | 1d14ffa9 | bellard | if (FAILED (hr)) {
|
584 | c0fe3827 | bellard | dsound_logerr (hr, "Could not get primary playback buffer format\n");
|
585 | 1d14ffa9 | bellard | goto fail0;
|
586 | 1d14ffa9 | bellard | } |
587 | 1d14ffa9 | bellard | |
588 | 1d14ffa9 | bellard | #ifdef DEBUG_DSOUND
|
589 | 1d14ffa9 | bellard | dolog ("Primary\n");
|
590 | 1d14ffa9 | bellard | print_wave_format (&wfx); |
591 | 1d14ffa9 | bellard | #endif
|
592 | 1d14ffa9 | bellard | |
593 | c0fe3827 | bellard | err = waveformat_to_audio_settings (&wfx, &s->settings); |
594 | 1d14ffa9 | bellard | if (err) {
|
595 | 1d14ffa9 | bellard | goto fail0;
|
596 | 1d14ffa9 | bellard | } |
597 | 1d14ffa9 | bellard | |
598 | 1d14ffa9 | bellard | return 0; |
599 | 1d14ffa9 | bellard | |
600 | 1d14ffa9 | bellard | fail0:
|
601 | 1d14ffa9 | bellard | dsound_close (s); |
602 | 1d14ffa9 | bellard | return -1; |
603 | 1d14ffa9 | bellard | } |
604 | 1d14ffa9 | bellard | |
605 | 1d14ffa9 | bellard | static int dsound_ctl_out (HWVoiceOut *hw, int cmd, ...) |
606 | 1d14ffa9 | bellard | { |
607 | 1d14ffa9 | bellard | HRESULT hr; |
608 | 1d14ffa9 | bellard | DWORD status; |
609 | 1d14ffa9 | bellard | DSoundVoiceOut *ds = (DSoundVoiceOut *) hw; |
610 | 1d14ffa9 | bellard | LPDIRECTSOUNDBUFFER dsb = ds->dsound_buffer; |
611 | 1d14ffa9 | bellard | |
612 | 1d14ffa9 | bellard | if (!dsb) {
|
613 | 1d14ffa9 | bellard | dolog ("Attempt to control voice without a buffer\n");
|
614 | 1d14ffa9 | bellard | return 0; |
615 | 1d14ffa9 | bellard | } |
616 | 1d14ffa9 | bellard | |
617 | 1d14ffa9 | bellard | switch (cmd) {
|
618 | 1d14ffa9 | bellard | case VOICE_ENABLE:
|
619 | 1d14ffa9 | bellard | if (dsound_get_status_out (dsb, &status)) {
|
620 | 1d14ffa9 | bellard | return -1; |
621 | 1d14ffa9 | bellard | } |
622 | 1d14ffa9 | bellard | |
623 | 1d14ffa9 | bellard | if (status & DSBSTATUS_PLAYING) {
|
624 | c0fe3827 | bellard | dolog ("warning: Voice is already playing\n");
|
625 | 1d14ffa9 | bellard | return 0; |
626 | 1d14ffa9 | bellard | } |
627 | 1d14ffa9 | bellard | |
628 | 1d14ffa9 | bellard | dsound_clear_sample (hw, dsb); |
629 | 1d14ffa9 | bellard | |
630 | 1d14ffa9 | bellard | hr = IDirectSoundBuffer_Play (dsb, 0, 0, DSBPLAY_LOOPING); |
631 | 1d14ffa9 | bellard | if (FAILED (hr)) {
|
632 | c0fe3827 | bellard | dsound_logerr (hr, "Could not start playing buffer\n");
|
633 | 1d14ffa9 | bellard | return -1; |
634 | 1d14ffa9 | bellard | } |
635 | 1d14ffa9 | bellard | break;
|
636 | 1d14ffa9 | bellard | |
637 | 1d14ffa9 | bellard | case VOICE_DISABLE:
|
638 | 1d14ffa9 | bellard | if (dsound_get_status_out (dsb, &status)) {
|
639 | 1d14ffa9 | bellard | return -1; |
640 | 1d14ffa9 | bellard | } |
641 | 1d14ffa9 | bellard | |
642 | 1d14ffa9 | bellard | if (status & DSBSTATUS_PLAYING) {
|
643 | 1d14ffa9 | bellard | hr = IDirectSoundBuffer_Stop (dsb); |
644 | 1d14ffa9 | bellard | if (FAILED (hr)) {
|
645 | c0fe3827 | bellard | dsound_logerr (hr, "Could not stop playing buffer\n");
|
646 | 1d14ffa9 | bellard | return -1; |
647 | 1d14ffa9 | bellard | } |
648 | 1d14ffa9 | bellard | } |
649 | 1d14ffa9 | bellard | else {
|
650 | c0fe3827 | bellard | dolog ("warning: Voice is not playing\n");
|
651 | 1d14ffa9 | bellard | } |
652 | 1d14ffa9 | bellard | break;
|
653 | 1d14ffa9 | bellard | } |
654 | 1d14ffa9 | bellard | return 0; |
655 | 1d14ffa9 | bellard | } |
656 | 1d14ffa9 | bellard | |
657 | 1d14ffa9 | bellard | static int dsound_write (SWVoiceOut *sw, void *buf, int len) |
658 | 1d14ffa9 | bellard | { |
659 | 1d14ffa9 | bellard | return audio_pcm_sw_write (sw, buf, len);
|
660 | 1d14ffa9 | bellard | } |
661 | 1d14ffa9 | bellard | |
662 | 1d14ffa9 | bellard | static int dsound_run_out (HWVoiceOut *hw) |
663 | 1d14ffa9 | bellard | { |
664 | 1d14ffa9 | bellard | int err;
|
665 | 1d14ffa9 | bellard | HRESULT hr; |
666 | 1d14ffa9 | bellard | DSoundVoiceOut *ds = (DSoundVoiceOut *) hw; |
667 | 1d14ffa9 | bellard | LPDIRECTSOUNDBUFFER dsb = ds->dsound_buffer; |
668 | 1d14ffa9 | bellard | int live, len, hwshift;
|
669 | 1d14ffa9 | bellard | DWORD blen1, blen2; |
670 | 1d14ffa9 | bellard | DWORD len1, len2; |
671 | 1d14ffa9 | bellard | DWORD decr; |
672 | 1d14ffa9 | bellard | DWORD wpos, ppos, old_pos; |
673 | 1d14ffa9 | bellard | LPVOID p1, p2; |
674 | c0fe3827 | bellard | int bufsize;
|
675 | 1d14ffa9 | bellard | |
676 | 1d14ffa9 | bellard | if (!dsb) {
|
677 | 1d14ffa9 | bellard | dolog ("Attempt to run empty with playback buffer\n");
|
678 | 1d14ffa9 | bellard | return 0; |
679 | 1d14ffa9 | bellard | } |
680 | 1d14ffa9 | bellard | |
681 | 1d14ffa9 | bellard | hwshift = hw->info.shift; |
682 | c0fe3827 | bellard | bufsize = hw->samples << hwshift; |
683 | 1d14ffa9 | bellard | |
684 | 1d14ffa9 | bellard | live = audio_pcm_hw_get_live_out (hw); |
685 | 1d14ffa9 | bellard | |
686 | 1d14ffa9 | bellard | hr = IDirectSoundBuffer_GetCurrentPosition ( |
687 | 1d14ffa9 | bellard | dsb, |
688 | 1d14ffa9 | bellard | &ppos, |
689 | 1d14ffa9 | bellard | ds->first_time ? &wpos : NULL
|
690 | 1d14ffa9 | bellard | ); |
691 | 1d14ffa9 | bellard | if (FAILED (hr)) {
|
692 | c0fe3827 | bellard | dsound_logerr (hr, "Could not get playback buffer position\n");
|
693 | 1d14ffa9 | bellard | return 0; |
694 | 1d14ffa9 | bellard | } |
695 | 1d14ffa9 | bellard | |
696 | 1d14ffa9 | bellard | len = live << hwshift; |
697 | 1d14ffa9 | bellard | |
698 | 1d14ffa9 | bellard | if (ds->first_time) {
|
699 | 1d14ffa9 | bellard | if (conf.latency_millis) {
|
700 | c0fe3827 | bellard | DWORD cur_blat; |
701 | 1d14ffa9 | bellard | |
702 | c0fe3827 | bellard | cur_blat = audio_ring_dist (wpos, ppos, bufsize); |
703 | 1d14ffa9 | bellard | ds->first_time = 0;
|
704 | 1d14ffa9 | bellard | old_pos = wpos; |
705 | 1d14ffa9 | bellard | old_pos += |
706 | 1d14ffa9 | bellard | millis_to_bytes (&hw->info, conf.latency_millis) - cur_blat; |
707 | c0fe3827 | bellard | old_pos %= bufsize; |
708 | 1d14ffa9 | bellard | old_pos &= ~hw->info.align; |
709 | 1d14ffa9 | bellard | } |
710 | 1d14ffa9 | bellard | else {
|
711 | 1d14ffa9 | bellard | old_pos = wpos; |
712 | 1d14ffa9 | bellard | } |
713 | 1d14ffa9 | bellard | #ifdef DEBUG_DSOUND
|
714 | 1d14ffa9 | bellard | ds->played = 0;
|
715 | 1d14ffa9 | bellard | ds->mixed = 0;
|
716 | 1d14ffa9 | bellard | #endif
|
717 | 1d14ffa9 | bellard | } |
718 | 1d14ffa9 | bellard | else {
|
719 | 1d14ffa9 | bellard | if (ds->old_pos == ppos) {
|
720 | 1d14ffa9 | bellard | #ifdef DEBUG_DSOUND
|
721 | 1d14ffa9 | bellard | dolog ("old_pos == ppos\n");
|
722 | 1d14ffa9 | bellard | #endif
|
723 | 1d14ffa9 | bellard | return 0; |
724 | 1d14ffa9 | bellard | } |
725 | 1d14ffa9 | bellard | |
726 | 1d14ffa9 | bellard | #ifdef DEBUG_DSOUND
|
727 | 1d14ffa9 | bellard | ds->played += audio_ring_dist (ds->old_pos, ppos, hw->bufsize); |
728 | 1d14ffa9 | bellard | #endif
|
729 | 1d14ffa9 | bellard | old_pos = ds->old_pos; |
730 | 1d14ffa9 | bellard | } |
731 | 1d14ffa9 | bellard | |
732 | 1d14ffa9 | bellard | if ((old_pos < ppos) && ((old_pos + len) > ppos)) {
|
733 | 1d14ffa9 | bellard | len = ppos - old_pos; |
734 | 1d14ffa9 | bellard | } |
735 | 1d14ffa9 | bellard | else {
|
736 | c0fe3827 | bellard | if ((old_pos > ppos) && ((old_pos + len) > (ppos + bufsize))) {
|
737 | c0fe3827 | bellard | len = bufsize - old_pos + ppos; |
738 | 1d14ffa9 | bellard | } |
739 | 1d14ffa9 | bellard | } |
740 | 1d14ffa9 | bellard | |
741 | c0fe3827 | bellard | if (audio_bug (AUDIO_FUNC, len < 0 || len > bufsize)) { |
742 | c0fe3827 | bellard | dolog ("len=%d bufsize=%d old_pos=%ld ppos=%ld\n",
|
743 | c0fe3827 | bellard | len, bufsize, old_pos, ppos); |
744 | 1d14ffa9 | bellard | return 0; |
745 | 1d14ffa9 | bellard | } |
746 | 1d14ffa9 | bellard | |
747 | 1d14ffa9 | bellard | len &= ~hw->info.align; |
748 | 1d14ffa9 | bellard | if (!len) {
|
749 | 1d14ffa9 | bellard | return 0; |
750 | 1d14ffa9 | bellard | } |
751 | 1d14ffa9 | bellard | |
752 | 1d14ffa9 | bellard | #ifdef DEBUG_DSOUND
|
753 | 1d14ffa9 | bellard | ds->old_ppos = ppos; |
754 | 1d14ffa9 | bellard | #endif
|
755 | 1d14ffa9 | bellard | err = dsound_lock_out ( |
756 | 1d14ffa9 | bellard | dsb, |
757 | 1d14ffa9 | bellard | &hw->info, |
758 | 1d14ffa9 | bellard | old_pos, |
759 | 1d14ffa9 | bellard | len, |
760 | 1d14ffa9 | bellard | &p1, &p2, |
761 | 1d14ffa9 | bellard | &blen1, &blen2, |
762 | 1d14ffa9 | bellard | 0
|
763 | 1d14ffa9 | bellard | ); |
764 | 1d14ffa9 | bellard | if (err) {
|
765 | 1d14ffa9 | bellard | return 0; |
766 | 1d14ffa9 | bellard | } |
767 | 1d14ffa9 | bellard | |
768 | 1d14ffa9 | bellard | len1 = blen1 >> hwshift; |
769 | 1d14ffa9 | bellard | len2 = blen2 >> hwshift; |
770 | 1d14ffa9 | bellard | decr = len1 + len2; |
771 | 1d14ffa9 | bellard | |
772 | 1d14ffa9 | bellard | if (p1 && len1) {
|
773 | 1d14ffa9 | bellard | dsound_write_sample (hw, p1, len1); |
774 | 1d14ffa9 | bellard | } |
775 | 1d14ffa9 | bellard | |
776 | 1d14ffa9 | bellard | if (p2 && len2) {
|
777 | 1d14ffa9 | bellard | dsound_write_sample (hw, p2, len2); |
778 | 1d14ffa9 | bellard | } |
779 | 1d14ffa9 | bellard | |
780 | 1d14ffa9 | bellard | dsound_unlock_out (dsb, p1, p2, blen1, blen2); |
781 | c0fe3827 | bellard | ds->old_pos = (old_pos + (decr << hwshift)) % bufsize; |
782 | 1d14ffa9 | bellard | |
783 | 1d14ffa9 | bellard | #ifdef DEBUG_DSOUND
|
784 | 1d14ffa9 | bellard | ds->mixed += decr << hwshift; |
785 | 1d14ffa9 | bellard | |
786 | 1d14ffa9 | bellard | dolog ("played %lu mixed %lu diff %ld sec %f\n",
|
787 | 1d14ffa9 | bellard | ds->played, |
788 | 1d14ffa9 | bellard | ds->mixed, |
789 | 1d14ffa9 | bellard | ds->mixed - ds->played, |
790 | 1d14ffa9 | bellard | abs (ds->mixed - ds->played) / (double) hw->info.bytes_per_second);
|
791 | 1d14ffa9 | bellard | #endif
|
792 | 1d14ffa9 | bellard | return decr;
|
793 | 1d14ffa9 | bellard | } |
794 | 1d14ffa9 | bellard | |
795 | 1d14ffa9 | bellard | static int dsound_ctl_in (HWVoiceIn *hw, int cmd, ...) |
796 | 1d14ffa9 | bellard | { |
797 | 1d14ffa9 | bellard | HRESULT hr; |
798 | 1d14ffa9 | bellard | DWORD status; |
799 | 1d14ffa9 | bellard | DSoundVoiceIn *ds = (DSoundVoiceIn *) hw; |
800 | 1d14ffa9 | bellard | LPDIRECTSOUNDCAPTUREBUFFER dscb = ds->dsound_capture_buffer; |
801 | 1d14ffa9 | bellard | |
802 | 1d14ffa9 | bellard | if (!dscb) {
|
803 | 1d14ffa9 | bellard | dolog ("Attempt to control capture voice without a buffer\n");
|
804 | 1d14ffa9 | bellard | return -1; |
805 | 1d14ffa9 | bellard | } |
806 | 1d14ffa9 | bellard | |
807 | 1d14ffa9 | bellard | switch (cmd) {
|
808 | 1d14ffa9 | bellard | case VOICE_ENABLE:
|
809 | 1d14ffa9 | bellard | if (dsound_get_status_in (dscb, &status)) {
|
810 | 1d14ffa9 | bellard | return -1; |
811 | 1d14ffa9 | bellard | } |
812 | 1d14ffa9 | bellard | |
813 | 1d14ffa9 | bellard | if (status & DSCBSTATUS_CAPTURING) {
|
814 | c0fe3827 | bellard | dolog ("warning: Voice is already capturing\n");
|
815 | 1d14ffa9 | bellard | return 0; |
816 | 1d14ffa9 | bellard | } |
817 | 1d14ffa9 | bellard | |
818 | 1d14ffa9 | bellard | /* clear ?? */
|
819 | 1d14ffa9 | bellard | |
820 | 1d14ffa9 | bellard | hr = IDirectSoundCaptureBuffer_Start (dscb, DSCBSTART_LOOPING); |
821 | 1d14ffa9 | bellard | if (FAILED (hr)) {
|
822 | c0fe3827 | bellard | dsound_logerr (hr, "Could not start capturing\n");
|
823 | 1d14ffa9 | bellard | return -1; |
824 | 1d14ffa9 | bellard | } |
825 | 1d14ffa9 | bellard | break;
|
826 | 1d14ffa9 | bellard | |
827 | 1d14ffa9 | bellard | case VOICE_DISABLE:
|
828 | 1d14ffa9 | bellard | if (dsound_get_status_in (dscb, &status)) {
|
829 | 1d14ffa9 | bellard | return -1; |
830 | 1d14ffa9 | bellard | } |
831 | 1d14ffa9 | bellard | |
832 | 1d14ffa9 | bellard | if (status & DSCBSTATUS_CAPTURING) {
|
833 | 1d14ffa9 | bellard | hr = IDirectSoundCaptureBuffer_Stop (dscb); |
834 | 1d14ffa9 | bellard | if (FAILED (hr)) {
|
835 | c0fe3827 | bellard | dsound_logerr (hr, "Could not stop capturing\n");
|
836 | 1d14ffa9 | bellard | return -1; |
837 | 1d14ffa9 | bellard | } |
838 | 1d14ffa9 | bellard | } |
839 | 1d14ffa9 | bellard | else {
|
840 | c0fe3827 | bellard | dolog ("warning: Voice is not capturing\n");
|
841 | 1d14ffa9 | bellard | } |
842 | 1d14ffa9 | bellard | break;
|
843 | 1d14ffa9 | bellard | } |
844 | 1d14ffa9 | bellard | return 0; |
845 | 1d14ffa9 | bellard | } |
846 | 1d14ffa9 | bellard | |
847 | 1d14ffa9 | bellard | static int dsound_read (SWVoiceIn *sw, void *buf, int len) |
848 | 1d14ffa9 | bellard | { |
849 | 1d14ffa9 | bellard | return audio_pcm_sw_read (sw, buf, len);
|
850 | 1d14ffa9 | bellard | } |
851 | 1d14ffa9 | bellard | |
852 | 1d14ffa9 | bellard | static int dsound_run_in (HWVoiceIn *hw) |
853 | 1d14ffa9 | bellard | { |
854 | 1d14ffa9 | bellard | int err;
|
855 | 1d14ffa9 | bellard | HRESULT hr; |
856 | 1d14ffa9 | bellard | DSoundVoiceIn *ds = (DSoundVoiceIn *) hw; |
857 | 1d14ffa9 | bellard | LPDIRECTSOUNDCAPTUREBUFFER dscb = ds->dsound_capture_buffer; |
858 | 1d14ffa9 | bellard | int live, len, dead;
|
859 | 1d14ffa9 | bellard | DWORD blen1, blen2; |
860 | 1d14ffa9 | bellard | DWORD len1, len2; |
861 | 1d14ffa9 | bellard | DWORD decr; |
862 | 1d14ffa9 | bellard | DWORD cpos, rpos; |
863 | 1d14ffa9 | bellard | LPVOID p1, p2; |
864 | 1d14ffa9 | bellard | int hwshift;
|
865 | 1d14ffa9 | bellard | |
866 | 1d14ffa9 | bellard | if (!dscb) {
|
867 | 1d14ffa9 | bellard | dolog ("Attempt to run without capture buffer\n");
|
868 | 1d14ffa9 | bellard | return 0; |
869 | 1d14ffa9 | bellard | } |
870 | 1d14ffa9 | bellard | |
871 | 1d14ffa9 | bellard | hwshift = hw->info.shift; |
872 | 1d14ffa9 | bellard | |
873 | 1d14ffa9 | bellard | live = audio_pcm_hw_get_live_in (hw); |
874 | 1d14ffa9 | bellard | dead = hw->samples - live; |
875 | 1d14ffa9 | bellard | if (!dead) {
|
876 | 1d14ffa9 | bellard | return 0; |
877 | 1d14ffa9 | bellard | } |
878 | 1d14ffa9 | bellard | |
879 | 1d14ffa9 | bellard | hr = IDirectSoundCaptureBuffer_GetCurrentPosition ( |
880 | 1d14ffa9 | bellard | dscb, |
881 | 1d14ffa9 | bellard | &cpos, |
882 | 1d14ffa9 | bellard | ds->first_time ? &rpos : NULL
|
883 | 1d14ffa9 | bellard | ); |
884 | 1d14ffa9 | bellard | if (FAILED (hr)) {
|
885 | c0fe3827 | bellard | dsound_logerr (hr, "Could not get capture buffer position\n");
|
886 | 1d14ffa9 | bellard | return 0; |
887 | 1d14ffa9 | bellard | } |
888 | 1d14ffa9 | bellard | |
889 | 1d14ffa9 | bellard | if (ds->first_time) {
|
890 | 1d14ffa9 | bellard | ds->first_time = 0;
|
891 | 1d14ffa9 | bellard | if (rpos & hw->info.align) {
|
892 | c0fe3827 | bellard | ldebug ("warning: Misaligned capture read position %ld(%d)\n",
|
893 | 1d14ffa9 | bellard | rpos, hw->info.align); |
894 | 1d14ffa9 | bellard | } |
895 | 1d14ffa9 | bellard | hw->wpos = rpos >> hwshift; |
896 | 1d14ffa9 | bellard | } |
897 | 1d14ffa9 | bellard | |
898 | 1d14ffa9 | bellard | if (cpos & hw->info.align) {
|
899 | c0fe3827 | bellard | ldebug ("warning: Misaligned capture position %ld(%d)\n",
|
900 | 1d14ffa9 | bellard | cpos, hw->info.align); |
901 | 1d14ffa9 | bellard | } |
902 | 1d14ffa9 | bellard | cpos >>= hwshift; |
903 | 1d14ffa9 | bellard | |
904 | 1d14ffa9 | bellard | len = audio_ring_dist (cpos, hw->wpos, hw->samples); |
905 | 1d14ffa9 | bellard | if (!len) {
|
906 | 1d14ffa9 | bellard | return 0; |
907 | 1d14ffa9 | bellard | } |
908 | 1d14ffa9 | bellard | len = audio_MIN (len, dead); |
909 | 1d14ffa9 | bellard | |
910 | 1d14ffa9 | bellard | err = dsound_lock_in ( |
911 | 1d14ffa9 | bellard | dscb, |
912 | 1d14ffa9 | bellard | &hw->info, |
913 | 1d14ffa9 | bellard | hw->wpos << hwshift, |
914 | 1d14ffa9 | bellard | len << hwshift, |
915 | 1d14ffa9 | bellard | &p1, |
916 | 1d14ffa9 | bellard | &p2, |
917 | 1d14ffa9 | bellard | &blen1, |
918 | 1d14ffa9 | bellard | &blen2, |
919 | 1d14ffa9 | bellard | 0
|
920 | 1d14ffa9 | bellard | ); |
921 | 1d14ffa9 | bellard | if (err) {
|
922 | 1d14ffa9 | bellard | return 0; |
923 | 1d14ffa9 | bellard | } |
924 | 1d14ffa9 | bellard | |
925 | 1d14ffa9 | bellard | len1 = blen1 >> hwshift; |
926 | 1d14ffa9 | bellard | len2 = blen2 >> hwshift; |
927 | 1d14ffa9 | bellard | decr = len1 + len2; |
928 | 1d14ffa9 | bellard | |
929 | 1d14ffa9 | bellard | if (p1 && len1) {
|
930 | 1d14ffa9 | bellard | hw->conv (hw->conv_buf + hw->wpos, p1, len1, &nominal_volume); |
931 | 1d14ffa9 | bellard | } |
932 | 1d14ffa9 | bellard | |
933 | 1d14ffa9 | bellard | if (p2 && len2) {
|
934 | 1d14ffa9 | bellard | hw->conv (hw->conv_buf, p2, len2, &nominal_volume); |
935 | 1d14ffa9 | bellard | } |
936 | 1d14ffa9 | bellard | |
937 | 1d14ffa9 | bellard | dsound_unlock_in (dscb, p1, p2, blen1, blen2); |
938 | 1d14ffa9 | bellard | hw->wpos = (hw->wpos + decr) % hw->samples; |
939 | 1d14ffa9 | bellard | return decr;
|
940 | 1d14ffa9 | bellard | } |
941 | 1d14ffa9 | bellard | |
942 | 1d14ffa9 | bellard | static void dsound_audio_fini (void *opaque) |
943 | 1d14ffa9 | bellard | { |
944 | 1d14ffa9 | bellard | HRESULT hr; |
945 | 1d14ffa9 | bellard | dsound *s = opaque; |
946 | 1d14ffa9 | bellard | |
947 | 1d14ffa9 | bellard | if (!s->dsound) {
|
948 | 1d14ffa9 | bellard | return;
|
949 | 1d14ffa9 | bellard | } |
950 | 1d14ffa9 | bellard | |
951 | 1d14ffa9 | bellard | hr = IDirectSound_Release (s->dsound); |
952 | 1d14ffa9 | bellard | if (FAILED (hr)) {
|
953 | c0fe3827 | bellard | dsound_logerr (hr, "Could not release DirectSound\n");
|
954 | 1d14ffa9 | bellard | } |
955 | 1d14ffa9 | bellard | s->dsound = NULL;
|
956 | 1d14ffa9 | bellard | |
957 | 1d14ffa9 | bellard | if (!s->dsound_capture) {
|
958 | 1d14ffa9 | bellard | return;
|
959 | 1d14ffa9 | bellard | } |
960 | 1d14ffa9 | bellard | |
961 | 1d14ffa9 | bellard | hr = IDirectSoundCapture_Release (s->dsound_capture); |
962 | 1d14ffa9 | bellard | if (FAILED (hr)) {
|
963 | c0fe3827 | bellard | dsound_logerr (hr, "Could not release DirectSoundCapture\n");
|
964 | 1d14ffa9 | bellard | } |
965 | 1d14ffa9 | bellard | s->dsound_capture = NULL;
|
966 | 1d14ffa9 | bellard | } |
967 | 1d14ffa9 | bellard | |
968 | 1d14ffa9 | bellard | static void *dsound_audio_init (void) |
969 | 1d14ffa9 | bellard | { |
970 | 1d14ffa9 | bellard | int err;
|
971 | 1d14ffa9 | bellard | HRESULT hr; |
972 | 1d14ffa9 | bellard | dsound *s = &glob_dsound; |
973 | 1d14ffa9 | bellard | |
974 | 1d14ffa9 | bellard | hr = CoInitialize (NULL);
|
975 | 1d14ffa9 | bellard | if (FAILED (hr)) {
|
976 | c0fe3827 | bellard | dsound_logerr (hr, "Could not initialize COM\n");
|
977 | 1d14ffa9 | bellard | return NULL; |
978 | 1d14ffa9 | bellard | } |
979 | 1d14ffa9 | bellard | |
980 | 1d14ffa9 | bellard | hr = CoCreateInstance ( |
981 | 1d14ffa9 | bellard | &CLSID_DirectSound, |
982 | 1d14ffa9 | bellard | NULL,
|
983 | 1d14ffa9 | bellard | CLSCTX_ALL, |
984 | 1d14ffa9 | bellard | &IID_IDirectSound, |
985 | 1d14ffa9 | bellard | (void **) &s->dsound
|
986 | 1d14ffa9 | bellard | ); |
987 | 1d14ffa9 | bellard | if (FAILED (hr)) {
|
988 | c0fe3827 | bellard | dsound_logerr (hr, "Could not create DirectSound instance\n");
|
989 | 1d14ffa9 | bellard | return NULL; |
990 | 1d14ffa9 | bellard | } |
991 | 1d14ffa9 | bellard | |
992 | 1d14ffa9 | bellard | hr = IDirectSound_Initialize (s->dsound, NULL);
|
993 | 1d14ffa9 | bellard | if (FAILED (hr)) {
|
994 | c0fe3827 | bellard | dsound_logerr (hr, "Could not initialize DirectSound\n");
|
995 | 8ead62cf | bellard | |
996 | 8ead62cf | bellard | hr = IDirectSound_Release (s->dsound); |
997 | 8ead62cf | bellard | if (FAILED (hr)) {
|
998 | 8ead62cf | bellard | dsound_logerr (hr, "Could not release DirectSound\n");
|
999 | 8ead62cf | bellard | } |
1000 | 8ead62cf | bellard | s->dsound = NULL;
|
1001 | 1d14ffa9 | bellard | return NULL; |
1002 | 1d14ffa9 | bellard | } |
1003 | 1d14ffa9 | bellard | |
1004 | 1d14ffa9 | bellard | hr = CoCreateInstance ( |
1005 | 1d14ffa9 | bellard | &CLSID_DirectSoundCapture, |
1006 | 1d14ffa9 | bellard | NULL,
|
1007 | 1d14ffa9 | bellard | CLSCTX_ALL, |
1008 | 1d14ffa9 | bellard | &IID_IDirectSoundCapture, |
1009 | 1d14ffa9 | bellard | (void **) &s->dsound_capture
|
1010 | 1d14ffa9 | bellard | ); |
1011 | 1d14ffa9 | bellard | if (FAILED (hr)) {
|
1012 | c0fe3827 | bellard | dsound_logerr (hr, "Could not create DirectSoundCapture instance\n");
|
1013 | 1d14ffa9 | bellard | } |
1014 | 1d14ffa9 | bellard | else {
|
1015 | 1d14ffa9 | bellard | hr = IDirectSoundCapture_Initialize (s->dsound_capture, NULL);
|
1016 | 1d14ffa9 | bellard | if (FAILED (hr)) {
|
1017 | c0fe3827 | bellard | dsound_logerr (hr, "Could not initialize DirectSoundCapture\n");
|
1018 | 1d14ffa9 | bellard | |
1019 | 1d14ffa9 | bellard | hr = IDirectSoundCapture_Release (s->dsound_capture); |
1020 | 1d14ffa9 | bellard | if (FAILED (hr)) {
|
1021 | c0fe3827 | bellard | dsound_logerr (hr, "Could not release DirectSoundCapture\n");
|
1022 | 1d14ffa9 | bellard | } |
1023 | 1d14ffa9 | bellard | s->dsound_capture = NULL;
|
1024 | 1d14ffa9 | bellard | } |
1025 | 1d14ffa9 | bellard | } |
1026 | 1d14ffa9 | bellard | |
1027 | 1d14ffa9 | bellard | err = dsound_open (s); |
1028 | 1d14ffa9 | bellard | if (err) {
|
1029 | 1d14ffa9 | bellard | dsound_audio_fini (s); |
1030 | 1d14ffa9 | bellard | return NULL; |
1031 | 1d14ffa9 | bellard | } |
1032 | 1d14ffa9 | bellard | |
1033 | 1d14ffa9 | bellard | return s;
|
1034 | 1d14ffa9 | bellard | } |
1035 | 1d14ffa9 | bellard | |
1036 | 1d14ffa9 | bellard | static struct audio_option dsound_options[] = { |
1037 | 1d14ffa9 | bellard | {"LOCK_RETRIES", AUD_OPT_INT, &conf.lock_retries,
|
1038 | 1d14ffa9 | bellard | "Number of times to attempt locking the buffer", NULL, 0}, |
1039 | 1d14ffa9 | bellard | {"RESTOURE_RETRIES", AUD_OPT_INT, &conf.restore_retries,
|
1040 | 1d14ffa9 | bellard | "Number of times to attempt restoring the buffer", NULL, 0}, |
1041 | 1d14ffa9 | bellard | {"GETSTATUS_RETRIES", AUD_OPT_INT, &conf.getstatus_retries,
|
1042 | 1d14ffa9 | bellard | "Number of times to attempt getting status of the buffer", NULL, 0}, |
1043 | 1d14ffa9 | bellard | {"SET_PRIMARY", AUD_OPT_BOOL, &conf.set_primary,
|
1044 | 1d14ffa9 | bellard | "Set the parameters of primary buffer", NULL, 0}, |
1045 | 1d14ffa9 | bellard | {"LATENCY_MILLIS", AUD_OPT_INT, &conf.latency_millis,
|
1046 | 1d14ffa9 | bellard | "(undocumented)", NULL, 0}, |
1047 | c0fe3827 | bellard | {"PRIMARY_FREQ", AUD_OPT_INT, &conf.settings.freq,
|
1048 | 1d14ffa9 | bellard | "Primary buffer frequency", NULL, 0}, |
1049 | c0fe3827 | bellard | {"PRIMARY_CHANNELS", AUD_OPT_INT, &conf.settings.nchannels,
|
1050 | 1d14ffa9 | bellard | "Primary buffer number of channels (1 - mono, 2 - stereo)", NULL, 0}, |
1051 | c0fe3827 | bellard | {"PRIMARY_FMT", AUD_OPT_FMT, &conf.settings.fmt,
|
1052 | 1d14ffa9 | bellard | "Primary buffer format", NULL, 0}, |
1053 | 1d14ffa9 | bellard | {"BUFSIZE_OUT", AUD_OPT_INT, &conf.bufsize_out,
|
1054 | 1d14ffa9 | bellard | "(undocumented)", NULL, 0}, |
1055 | 1d14ffa9 | bellard | {"BUFSIZE_IN", AUD_OPT_INT, &conf.bufsize_in,
|
1056 | 1d14ffa9 | bellard | "(undocumented)", NULL, 0}, |
1057 | 1d14ffa9 | bellard | {NULL, 0, NULL, NULL, NULL, 0} |
1058 | 1d14ffa9 | bellard | }; |
1059 | 1d14ffa9 | bellard | |
1060 | 1d14ffa9 | bellard | static struct audio_pcm_ops dsound_pcm_ops = { |
1061 | 1d14ffa9 | bellard | dsound_init_out, |
1062 | 1d14ffa9 | bellard | dsound_fini_out, |
1063 | 1d14ffa9 | bellard | dsound_run_out, |
1064 | 1d14ffa9 | bellard | dsound_write, |
1065 | 1d14ffa9 | bellard | dsound_ctl_out, |
1066 | 1d14ffa9 | bellard | |
1067 | 1d14ffa9 | bellard | dsound_init_in, |
1068 | 1d14ffa9 | bellard | dsound_fini_in, |
1069 | 1d14ffa9 | bellard | dsound_run_in, |
1070 | 1d14ffa9 | bellard | dsound_read, |
1071 | 1d14ffa9 | bellard | dsound_ctl_in |
1072 | 1d14ffa9 | bellard | }; |
1073 | 1d14ffa9 | bellard | |
1074 | 1d14ffa9 | bellard | struct audio_driver dsound_audio_driver = {
|
1075 | 1d14ffa9 | bellard | INIT_FIELD (name = ) "dsound",
|
1076 | 1d14ffa9 | bellard | INIT_FIELD (descr = ) |
1077 | 1d14ffa9 | bellard | "DirectSound http://wikipedia.org/wiki/DirectSound",
|
1078 | 1d14ffa9 | bellard | INIT_FIELD (options = ) dsound_options, |
1079 | 1d14ffa9 | bellard | INIT_FIELD (init = ) dsound_audio_init, |
1080 | 1d14ffa9 | bellard | INIT_FIELD (fini = ) dsound_audio_fini, |
1081 | 1d14ffa9 | bellard | INIT_FIELD (pcm_ops = ) &dsound_pcm_ops, |
1082 | 1d14ffa9 | bellard | INIT_FIELD (can_be_default = ) 1,
|
1083 | 1d14ffa9 | bellard | INIT_FIELD (max_voices_out = ) INT_MAX, |
1084 | 1d14ffa9 | bellard | INIT_FIELD (max_voices_in = ) 1,
|
1085 | 1d14ffa9 | bellard | INIT_FIELD (voice_size_out = ) sizeof (DSoundVoiceOut),
|
1086 | 1d14ffa9 | bellard | INIT_FIELD (voice_size_in = ) sizeof (DSoundVoiceIn)
|
1087 | 1d14ffa9 | bellard | }; |