dsound_template.h (cfc3fef6b4e493bf1a7ee16790ad584e20dfbbd1) dsound_template.h (7fa9754ac888d571000110504a3a7950f1404212)
1/*
2 * QEMU DirectSound audio driver header
3 *
4 * Copyright (c) 2005 Vassili Karpov (malc)
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights

--- 15 unchanged lines hidden (view full) ---

24#ifdef DSBTYPE_IN
25#define NAME "capture buffer"
26#define NAME2 "DirectSoundCapture"
27#define TYPE in
28#define IFACE IDirectSoundCaptureBuffer
29#define BUFPTR LPDIRECTSOUNDCAPTUREBUFFER
30#define FIELD dsound_capture_buffer
31#define FIELD2 dsound_capture
1/*
2 * QEMU DirectSound audio driver header
3 *
4 * Copyright (c) 2005 Vassili Karpov (malc)
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights

--- 15 unchanged lines hidden (view full) ---

24#ifdef DSBTYPE_IN
25#define NAME "capture buffer"
26#define NAME2 "DirectSoundCapture"
27#define TYPE in
28#define IFACE IDirectSoundCaptureBuffer
29#define BUFPTR LPDIRECTSOUNDCAPTUREBUFFER
30#define FIELD dsound_capture_buffer
31#define FIELD2 dsound_capture
32#define HWVOICE HWVoiceIn
33#define DSOUNDVOICE DSoundVoiceIn
32#else
33#define NAME "playback buffer"
34#define NAME2 "DirectSound"
35#define TYPE out
36#define IFACE IDirectSoundBuffer
37#define BUFPTR LPDIRECTSOUNDBUFFER
38#define FIELD dsound_buffer
39#define FIELD2 dsound
34#else
35#define NAME "playback buffer"
36#define NAME2 "DirectSound"
37#define TYPE out
38#define IFACE IDirectSoundBuffer
39#define BUFPTR LPDIRECTSOUNDBUFFER
40#define FIELD dsound_buffer
41#define FIELD2 dsound
42#define HWVOICE HWVoiceOut
43#define DSOUNDVOICE DSoundVoiceOut
40#endif
41
42static int glue (dsound_unlock_, TYPE) (
43 BUFPTR buf,
44 LPVOID p1,
45 LPVOID p2,
46 DWORD blen1,
47 DWORD blen2

--- 19 unchanged lines hidden (view full) ---

67 LPVOID *p2p,
68 DWORD *blen1p,
69 DWORD *blen2p,
70 int entire,
71 dsound *s
72 )
73{
74 HRESULT hr;
44#endif
45
46static int glue (dsound_unlock_, TYPE) (
47 BUFPTR buf,
48 LPVOID p1,
49 LPVOID p2,
50 DWORD blen1,
51 DWORD blen2

--- 19 unchanged lines hidden (view full) ---

71 LPVOID *p2p,
72 DWORD *blen1p,
73 DWORD *blen2p,
74 int entire,
75 dsound *s
76 )
77{
78 HRESULT hr;
75 LPVOID p1 = NULL, p2 = NULL;
76 DWORD blen1 = 0, blen2 = 0;
77 DWORD flag;
78
79#ifdef DSBTYPE_IN
80 flag = entire ? DSCBLOCK_ENTIREBUFFER : 0;
81#else
82 flag = entire ? DSBLOCK_ENTIREBUFFER : 0;
83#endif
79 DWORD flag;
80
81#ifdef DSBTYPE_IN
82 flag = entire ? DSCBLOCK_ENTIREBUFFER : 0;
83#else
84 flag = entire ? DSBLOCK_ENTIREBUFFER : 0;
85#endif
84 hr = glue(IFACE, _Lock)(buf, pos, len, &p1, &blen1, &p2, &blen2, flag);
86 hr = glue(IFACE, _Lock)(buf, pos, len, p1p, blen1p, p2p, blen2p, flag);
85
86 if (FAILED (hr)) {
87#ifndef DSBTYPE_IN
88 if (hr == DSERR_BUFFERLOST) {
89 if (glue (dsound_restore_, TYPE) (buf, s)) {
90 dsound_logerr (hr, "Could not lock " NAME "\n");
91 }
92 goto fail;
93 }
94#endif
95 dsound_logerr (hr, "Could not lock " NAME "\n");
96 goto fail;
97 }
98
87
88 if (FAILED (hr)) {
89#ifndef DSBTYPE_IN
90 if (hr == DSERR_BUFFERLOST) {
91 if (glue (dsound_restore_, TYPE) (buf, s)) {
92 dsound_logerr (hr, "Could not lock " NAME "\n");
93 }
94 goto fail;
95 }
96#endif
97 dsound_logerr (hr, "Could not lock " NAME "\n");
98 goto fail;
99 }
100
99 if ((p1 && (blen1 & info->align)) || (p2 && (blen2 & info->align))) {
100 dolog ("DirectSound returned misaligned buffer %ld %ld\n",
101 blen1, blen2);
102 glue (dsound_unlock_, TYPE) (buf, p1, p2, blen1, blen2);
101 if ((p1p && *p1p && (*blen1p & info->align)) ||
102 (p2p && *p2p && (*blen2p & info->align))) {
103 dolog("DirectSound returned misaligned buffer %ld %ld\n",
104 *blen1p, *blen2p);
105 glue(dsound_unlock_, TYPE)(buf, *p1p, p2p ? *p2p : NULL, *blen1p,
106 blen2p ? *blen2p : 0);
103 goto fail;
104 }
105
107 goto fail;
108 }
109
106 if (!p1 && blen1) {
107 dolog ("warning: !p1 && blen1=%ld\n", blen1);
108 blen1 = 0;
110 if (p1p && !*p1p && *blen1p) {
111 dolog("warning: !p1 && blen1=%ld\n", *blen1p);
112 *blen1p = 0;
109 }
110
113 }
114
111 if (!p2 && blen2) {
112 dolog ("warning: !p2 && blen2=%ld\n", blen2);
113 blen2 = 0;
115 if (p2p && !*p2p && *blen2p) {
116 dolog("warning: !p2 && blen2=%ld\n", *blen2p);
117 *blen2p = 0;
114 }
115
118 }
119
116 *p1p = p1;
117 *p2p = p2;
118 *blen1p = blen1;
119 *blen2p = blen2;
120 return 0;
121
122 fail:
123 *p1p = NULL - 1;
120 return 0;
121
122 fail:
123 *p1p = NULL - 1;
124 *p2p = NULL - 1;
125 *blen1p = -1;
124 *blen1p = -1;
126 *blen2p = -1;
125 if (p2p) {
126 *p2p = NULL - 1;
127 *blen2p = -1;
128 }
127 return -1;
128}
129
130#ifdef DSBTYPE_IN
131static void dsound_fini_in (HWVoiceIn *hw)
132#else
133static void dsound_fini_out (HWVoiceOut *hw)
134#endif

--- 102 unchanged lines hidden (view full) ---

237 goto fail0;
238 }
239
240 err = waveformat_to_audio_settings (&wfx, &obt_as);
241 if (err) {
242 goto fail0;
243 }
244
129 return -1;
130}
131
132#ifdef DSBTYPE_IN
133static void dsound_fini_in (HWVoiceIn *hw)
134#else
135static void dsound_fini_out (HWVoiceOut *hw)
136#endif

--- 102 unchanged lines hidden (view full) ---

239 goto fail0;
240 }
241
242 err = waveformat_to_audio_settings (&wfx, &obt_as);
243 if (err) {
244 goto fail0;
245 }
246
245 ds->first_time = 1;
246 obt_as.endianness = 0;
247 audio_pcm_init_info (&hw->info, &obt_as);
248
249 if (bc.dwBufferBytes & hw->info.align) {
250 dolog (
251 "GetCaps returned misaligned buffer size %ld, alignment %d\n",
252 bc.dwBufferBytes, hw->info.align + 1
253 );
254 }
247 obt_as.endianness = 0;
248 audio_pcm_init_info (&hw->info, &obt_as);
249
250 if (bc.dwBufferBytes & hw->info.align) {
251 dolog (
252 "GetCaps returned misaligned buffer size %ld, alignment %d\n",
253 bc.dwBufferBytes, hw->info.align + 1
254 );
255 }
256 hw->size_emul = bc.dwBufferBytes;
255 hw->samples = bc.dwBufferBytes >> hw->info.shift;
256 ds->s = s;
257
258#ifdef DEBUG_DSOUND
259 dolog ("caps %ld, desc %ld\n",
260 bc.dwBufferBytes, bd.dwBufferBytes);
257 hw->samples = bc.dwBufferBytes >> hw->info.shift;
258 ds->s = s;
259
260#ifdef DEBUG_DSOUND
261 dolog ("caps %ld, desc %ld\n",
262 bc.dwBufferBytes, bd.dwBufferBytes);
261
262 dolog ("bufsize %d, freq %d, chan %d, fmt %d\n",
263 hw->bufsize, settings.freq, settings.nchannels, settings.fmt);
264#endif
265 return 0;
266
267 fail0:
268 glue (dsound_fini_, TYPE) (hw);
269 return -1;
270}
271
272#undef NAME
273#undef NAME2
274#undef TYPE
275#undef IFACE
276#undef BUFPTR
277#undef FIELD
278#undef FIELD2
263#endif
264 return 0;
265
266 fail0:
267 glue (dsound_fini_, TYPE) (hw);
268 return -1;
269}
270
271#undef NAME
272#undef NAME2
273#undef TYPE
274#undef IFACE
275#undef BUFPTR
276#undef FIELD
277#undef FIELD2
278#undef HWVOICE
279#undef DSOUNDVOICE