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