[DSOUND] block align buffer sizes
Robert Reif
reif at earthlink.net
Tue Feb 15 15:05:47 CST 2005
Make sure buffer sizes are a multiple of the block align size.
Wine currently doesn't deal with illegal sized buffers well.
I am investigating how windows deals with this programming
error and will provide a patch and tests if necessary.
-------------- next part --------------
Index: dlls/dsound/tests/ds3d.c
===================================================================
RCS file: /home/wine/wine/dlls/dsound/tests/ds3d.c,v
retrieving revision 1.19
diff -u -p -r1.19 ds3d.c
--- dlls/dsound/tests/ds3d.c 10 Feb 2005 20:26:20 -0000 1.19
+++ dlls/dsound/tests/ds3d.c 15 Feb 2005 20:47:52 -0000
@@ -713,7 +713,8 @@ static HRESULT test_secondary(LPGUID lpG
else
bufdesc.dwFlags|=
(DSBCAPS_CTRLFREQUENCY|DSBCAPS_CTRLVOLUME|DSBCAPS_CTRLPAN);
- bufdesc.dwBufferBytes=wfx.nAvgBytesPerSec*BUFFER_LEN/1000;
+ bufdesc.dwBufferBytes=align(wfx.nAvgBytesPerSec*BUFFER_LEN/1000,
+ wfx.nBlockAlign);
bufdesc.lpwfxFormat=&wfx;
if (winetest_interactive) {
trace(" Testing a %s%ssecondary buffer %s%s%s%sat %ldx%dx%d "
Index: dlls/dsound/tests/ds3d8.c
===================================================================
RCS file: /home/wine/wine/dlls/dsound/tests/ds3d8.c,v
retrieving revision 1.14
diff -u -p -r1.14 ds3d8.c
--- dlls/dsound/tests/ds3d8.c 10 Feb 2005 21:21:13 -0000 1.14
+++ dlls/dsound/tests/ds3d8.c 15 Feb 2005 20:47:53 -0000
@@ -615,7 +615,8 @@ static HRESULT test_secondary8(LPGUID lp
else
bufdesc.dwFlags|=
(DSBCAPS_CTRLFREQUENCY|DSBCAPS_CTRLVOLUME|DSBCAPS_CTRLPAN);
- bufdesc.dwBufferBytes=wfx.nAvgBytesPerSec*BUFFER_LEN/1000;
+ bufdesc.dwBufferBytes=align(wfx.nAvgBytesPerSec*BUFFER_LEN/1000,
+ wfx.nBlockAlign);
bufdesc.lpwfxFormat=&wfx;
if (has_3d) {
/* a stereo 3D buffer should fail */
Index: dlls/dsound/tests/dsound.c
===================================================================
RCS file: /home/wine/wine/dlls/dsound/tests/dsound.c,v
retrieving revision 1.45
diff -u -p -r1.45 dsound.c
--- dlls/dsound/tests/dsound.c 10 Feb 2005 20:26:20 -0000 1.45
+++ dlls/dsound/tests/dsound.c 15 Feb 2005 20:47:53 -0000
@@ -305,7 +305,8 @@ static HRESULT test_dsound(LPGUID lpGuid
ZeroMemory(&bufdesc, sizeof(bufdesc));
bufdesc.dwSize=sizeof(bufdesc);
bufdesc.dwFlags=DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_CTRL3D;
- bufdesc.dwBufferBytes=wfx.nAvgBytesPerSec*BUFFER_LEN/1000;
+ bufdesc.dwBufferBytes=align(wfx.nAvgBytesPerSec*BUFFER_LEN/1000,
+ wfx.nBlockAlign);
bufdesc.lpwfxFormat=&wfx;
rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
ok(rc==DS_OK && secondary!=NULL,
@@ -573,7 +574,8 @@ static HRESULT test_primary_secondary(LP
ZeroMemory(&bufdesc, sizeof(bufdesc));
bufdesc.dwSize=sizeof(bufdesc);
bufdesc.dwFlags=DSBCAPS_GETCURRENTPOSITION2;
- bufdesc.dwBufferBytes=wfx.nAvgBytesPerSec*BUFFER_LEN/1000;
+ bufdesc.dwBufferBytes=align(wfx.nAvgBytesPerSec*BUFFER_LEN/1000,
+ wfx.nBlockAlign);
bufdesc.lpwfxFormat=&wfx2;
if (winetest_interactive) {
trace(" Testing a primary buffer at %ldx%dx%d with a "
@@ -672,7 +674,8 @@ static HRESULT test_secondary(LPGUID lpG
ZeroMemory(&bufdesc, sizeof(bufdesc));
bufdesc.dwSize=sizeof(bufdesc);
bufdesc.dwFlags=DSBCAPS_GETCURRENTPOSITION2;
- bufdesc.dwBufferBytes=wfx.nAvgBytesPerSec*BUFFER_LEN/1000;
+ bufdesc.dwBufferBytes=align(wfx.nAvgBytesPerSec*BUFFER_LEN/1000,
+ wfx.nBlockAlign);
rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
ok(rc==DSERR_INVALIDPARAM,"IDirectSound_CreateSoundBuffer() "
"should have returned DSERR_INVALIDPARAM, returned: %s\n",
@@ -684,7 +687,8 @@ static HRESULT test_secondary(LPGUID lpG
ZeroMemory(&bufdesc, sizeof(bufdesc));
bufdesc.dwSize=sizeof(bufdesc);
bufdesc.dwFlags=DSBCAPS_GETCURRENTPOSITION2;
- bufdesc.dwBufferBytes=wfx.nAvgBytesPerSec*BUFFER_LEN/1000;
+ bufdesc.dwBufferBytes=align(wfx.nAvgBytesPerSec*BUFFER_LEN/1000,
+ wfx.nBlockAlign);
bufdesc.lpwfxFormat=&wfx;
if (winetest_interactive) {
trace(" Testing a secondary buffer at %ldx%dx%d "
Index: dlls/dsound/tests/dsound8.c
===================================================================
RCS file: /home/wine/wine/dlls/dsound/tests/dsound8.c,v
retrieving revision 1.15
diff -u -p -r1.15 dsound8.c
--- dlls/dsound/tests/dsound8.c 10 Feb 2005 20:26:20 -0000 1.15
+++ dlls/dsound/tests/dsound8.c 15 Feb 2005 20:47:54 -0000
@@ -38,6 +38,11 @@
static HRESULT (WINAPI *pDirectSoundCreate8)(LPCGUID,LPDIRECTSOUND8*,LPUNKNOWN)=NULL;
+int align(int length, int align)
+{
+ return (length / align) * align;
+}
+
static void IDirectSound8_test(LPDIRECTSOUND8 dso, BOOL initialized,
LPCGUID lpGuid)
{
@@ -315,7 +320,8 @@ static HRESULT test_dsound8(LPGUID lpGui
ZeroMemory(&bufdesc, sizeof(bufdesc));
bufdesc.dwSize=sizeof(bufdesc);
bufdesc.dwFlags=DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_CTRL3D;
- bufdesc.dwBufferBytes=wfx.nAvgBytesPerSec*BUFFER_LEN/1000;
+ bufdesc.dwBufferBytes=align(wfx.nAvgBytesPerSec*BUFFER_LEN/1000,
+ wfx.nBlockAlign);
bufdesc.lpwfxFormat=&wfx;
rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
ok(rc==DS_OK && secondary!=NULL,
@@ -594,7 +600,8 @@ static HRESULT test_primary_secondary8(L
ZeroMemory(&bufdesc, sizeof(bufdesc));
bufdesc.dwSize=sizeof(bufdesc);
bufdesc.dwFlags=DSBCAPS_GETCURRENTPOSITION2;
- bufdesc.dwBufferBytes=wfx.nAvgBytesPerSec*BUFFER_LEN/1000;
+ bufdesc.dwBufferBytes=align(wfx.nAvgBytesPerSec*BUFFER_LEN/1000,
+ wfx.nBlockAlign);
bufdesc.lpwfxFormat=&wfx2;
if (winetest_interactive) {
trace(" Testing a primary buffer at %ldx%dx%d with a "
@@ -693,7 +700,8 @@ static HRESULT test_secondary8(LPGUID lp
ZeroMemory(&bufdesc, sizeof(bufdesc));
bufdesc.dwSize=sizeof(bufdesc);
bufdesc.dwFlags=DSBCAPS_GETCURRENTPOSITION2;
- bufdesc.dwBufferBytes=wfx.nAvgBytesPerSec*BUFFER_LEN/1000;
+ bufdesc.dwBufferBytes=align(wfx.nAvgBytesPerSec*BUFFER_LEN/1000,
+ wfx.nBlockAlign);
rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
ok(rc==DSERR_INVALIDPARAM,"IDirectSound8_CreateSoundBuffer() "
"should have returned DSERR_INVALIDPARAM, returned: %s\n",
@@ -705,7 +713,8 @@ static HRESULT test_secondary8(LPGUID lp
ZeroMemory(&bufdesc, sizeof(bufdesc));
bufdesc.dwSize=sizeof(bufdesc);
bufdesc.dwFlags=DSBCAPS_GETCURRENTPOSITION2;
- bufdesc.dwBufferBytes=wfx.nAvgBytesPerSec*BUFFER_LEN/1000;
+ bufdesc.dwBufferBytes=align(wfx.nAvgBytesPerSec*BUFFER_LEN/1000,
+ wfx.nBlockAlign);
bufdesc.lpwfxFormat=&wfx;
if (winetest_interactive) {
trace(" Testing a secondary buffer at %ldx%dx%d "
Index: dlls/dsound/tests/dsound_test.h
===================================================================
RCS file: /home/wine/wine/dlls/dsound/tests/dsound_test.h,v
retrieving revision 1.6
diff -u -p -r1.6 dsound_test.h
--- dlls/dsound/tests/dsound_test.h 13 Dec 2004 21:19:02 -0000 1.6
+++ dlls/dsound/tests/dsound_test.h 15 Feb 2005 20:47:54 -0000
@@ -50,7 +50,6 @@ static const unsigned int formats[][4]={
#define TIME_SLICE 31
#define BUFFER_LEN 400
-
extern char* wave_generate_la(WAVEFORMATEX*,double,DWORD*);
extern HWND get_hwnd(void);
extern void init_format(WAVEFORMATEX*,int,int,int,int);
@@ -61,3 +60,4 @@ extern void test_buffer8(LPDIRECTSOUND8,
BOOL,BOOL,LONG,BOOL,LONG,BOOL,double,BOOL,
LPDIRECTSOUND3DLISTENER,BOOL,BOOL);
extern const char * getDSBCAPS(DWORD xmask);
+extern int align(int length, int align);
More information about the wine-patches
mailing list