Commit c3a01501 authored by Owen Rudge's avatar Owen Rudge Committed by Alexandre Julliard

dsound/tests: Add IEEE float buffer tests.

parent d6f3ca95
......@@ -30,6 +30,8 @@
#include "wine/test.h"
#include "dsound.h"
#include "mmreg.h"
#include "ks.h"
#include "ksmedia.h"
#include "dsound_test.h"
#define PI 3.14159265358979323846
......@@ -39,7 +41,7 @@ static HRESULT (WINAPI *pDirectSoundEnumerateA)(LPDSENUMCALLBACKA,LPVOID)=NULL;
static HRESULT (WINAPI *pDirectSoundCreate)(LPCGUID,LPDIRECTSOUND*,
LPUNKNOWN)=NULL;
char* wave_generate_la(WAVEFORMATEX* wfx, double duration, DWORD* size)
char* wave_generate_la(WAVEFORMATEX* wfx, double duration, DWORD* size, BOOL ieee)
{
int i;
int nb_samples;
......@@ -79,18 +81,31 @@ char* wave_generate_la(WAVEFORMATEX* wfx, double duration, DWORD* size)
b+=3;
}
} else if (wfx->wBitsPerSample == 32) {
signed int sample=(signed int)((double)2147483647.5*y-0.5);
b[0]=sample & 0xff;
b[1]=(sample >> 8)&0xff;
b[2]=(sample >> 16)&0xff;
b[3]=sample >> 24;
b+=4;
if (wfx->nChannels==2) {
if (ieee) {
float *ptr = (float *) b;
*ptr = y;
ptr++;
b+=4;
if (wfx->nChannels==2) {
*ptr = y;
b+=4;
}
} else {
signed int sample=(signed int)((double)2147483647.5*y-0.5);
b[0]=sample & 0xff;
b[1]=(sample >> 8)&0xff;
b[2]=(sample >> 16)&0xff;
b[3]=sample >> 24;
b+=4;
if (wfx->nChannels==2) {
b[0]=sample & 0xff;
b[1]=(sample >> 8)&0xff;
b[2]=(sample >> 16)&0xff;
b[3]=sample >> 24;
b+=4;
}
}
}
}
......@@ -317,6 +332,7 @@ void test_buffer(LPDIRECTSOUND dso, LPDIRECTSOUNDBUFFER *dsbo,
DSBCAPS dsbcaps;
WAVEFORMATEX wfx,wfx2;
DWORD size,status,freq;
BOOL ieee = FALSE;
int ref;
if (set_frequency) {
......@@ -358,11 +374,13 @@ void test_buffer(LPDIRECTSOUND dso, LPDIRECTSOUNDBUFFER *dsbo,
if (size == sizeof(WAVEFORMATEX)) {
rc=IDirectSoundBuffer_GetFormat(*dsbo,&wfx,size,NULL);
ieee = (wfx.wFormatTag == WAVE_FORMAT_IEEE_FLOAT);
}
else if (size == sizeof(WAVEFORMATEXTENSIBLE)) {
WAVEFORMATEXTENSIBLE wfxe;
rc=IDirectSoundBuffer_GetFormat(*dsbo,(WAVEFORMATEX*)&wfxe,size,NULL);
wfx = wfxe.Format;
ieee = IsEqualGUID(&wfxe.SubFormat, &KSDATAFORMAT_SUBTYPE_IEEE_FLOAT);
}
ok(rc==DS_OK,
"IDirectSoundBuffer_GetFormat() failed: %08x\n", rc);
......@@ -600,9 +618,9 @@ void test_buffer(LPDIRECTSOUND dso, LPDIRECTSOUNDBUFFER *dsbo,
"returned DSERR_INVALIDPARAM, returned %08x\n", rc);
if (set_frequency)
state.wave=wave_generate_la(&wfx,(duration*frequency)/wfx.nSamplesPerSec,&state.wave_len);
state.wave=wave_generate_la(&wfx,(duration*frequency)/wfx.nSamplesPerSec,&state.wave_len,ieee);
else
state.wave=wave_generate_la(&wfx,duration,&state.wave_len);
state.wave=wave_generate_la(&wfx,duration,&state.wave_len,ieee);
state.dsbo=*dsbo;
state.wfx=&wfx;
......
......@@ -447,7 +447,7 @@ void test_buffer8(LPDIRECTSOUND8 dso, LPDIRECTSOUNDBUFFER * dsbo,
ok(rc==DSERR_INVALIDPARAM, "IDirectSoundBuffer_Lock() should have "
"returned DSERR_INVALIDPARAM, returned %08x\n", rc);
state.wave=wave_generate_la(&wfx,duration,&state.wave_len);
state.wave=wave_generate_la(&wfx,duration,&state.wave_len,FALSE);
state.dsbo=*dsbo;
state.wfx=&wfx;
......
......@@ -523,7 +523,7 @@ static HRESULT test_primary_secondary(LPGUID lpGuid)
DSBUFFERDESC bufdesc;
DSCAPS dscaps;
WAVEFORMATEX wfx, wfx2;
int f,ref;
int f,ref,tag;
/* Create the DirectSound object */
rc=pDirectSoundCreate(lpGuid,&dso,NULL);
......@@ -556,6 +556,11 @@ static HRESULT test_primary_secondary(LPGUID lpGuid)
if (rc==DS_OK && primary!=NULL) {
for (f=0;f<NB_FORMATS;f++) {
for (tag=0;tag<NB_TAGS;tag++) {
/* if float, we only want to test 32-bit */
if ((format_tags[tag] == WAVE_FORMAT_IEEE_FLOAT) && (formats[f][1] != 32))
continue;
/* We must call SetCooperativeLevel to be allowed to call
* SetFormat */
/* DSOUND: Setting DirectSound cooperative level to
......@@ -565,7 +570,7 @@ static HRESULT test_primary_secondary(LPGUID lpGuid)
if (rc!=DS_OK)
goto EXIT;
init_format(&wfx,WAVE_FORMAT_PCM,formats[f][0],formats[f][1],
init_format(&wfx,format_tags[tag],formats[f][0],formats[f][1],
formats[f][2]);
wfx2=wfx;
rc=IDirectSoundBuffer_SetFormat(primary,&wfx);
......@@ -612,9 +617,9 @@ static HRESULT test_primary_secondary(LPGUID lpGuid)
wfx.nBlockAlign);
bufdesc.lpwfxFormat=&wfx2;
if (winetest_interactive) {
trace(" Testing a primary buffer at %dx%dx%d with a "
trace(" Testing a primary buffer at %dx%dx%d (fmt=%d) with a "
"secondary buffer at %dx%dx%d\n",
wfx.nSamplesPerSec,wfx.wBitsPerSample,wfx.nChannels,
wfx.nSamplesPerSec,wfx.wBitsPerSample,wfx.nChannels,format_tags[tag],
wfx2.nSamplesPerSec,wfx2.wBitsPerSample,wfx2.nChannels);
}
rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
......@@ -629,6 +634,7 @@ static HRESULT test_primary_secondary(LPGUID lpGuid)
ok(ref==0,"IDirectSoundBuffer_Release() has %d references, "
"should have 0\n",ref);
}
}
}
ref=IDirectSoundBuffer_Release(primary);
......@@ -658,7 +664,7 @@ static HRESULT test_secondary(LPGUID lpGuid)
DSBUFFERDESC bufdesc;
DSCAPS dscaps;
WAVEFORMATEX wfx, wfx1;
DWORD f;
DWORD f, tag;
int ref;
/* Create the DirectSound object */
......@@ -697,8 +703,14 @@ static HRESULT test_secondary(LPGUID lpGuid)
goto EXIT1;
for (f=0;f<NB_FORMATS;f++) {
for (tag=0;tag<NB_TAGS;tag++) {
WAVEFORMATEXTENSIBLE wfxe;
init_format(&wfx,WAVE_FORMAT_PCM,formats[f][0],formats[f][1],
/* if float, we only want to test 32-bit */
if ((format_tags[tag] == WAVE_FORMAT_IEEE_FLOAT) && (formats[f][1] != 32))
continue;
init_format(&wfx,format_tags[tag],formats[f][0],formats[f][1],
formats[f][2]);
secondary=NULL;
ZeroMemory(&bufdesc, sizeof(bufdesc));
......@@ -720,7 +732,7 @@ static HRESULT test_secondary(LPGUID lpGuid)
wfx.nBlockAlign);
bufdesc.lpwfxFormat=&wfx;
rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
if (gotdx8 || wfx.wBitsPerSample <= 16)
if (gotdx8 || wfx.wBitsPerSample <= 16 || wfx.wFormatTag == WAVE_FORMAT_IEEE_FLOAT)
{
if (wfx.wBitsPerSample > 16)
ok(((rc == DSERR_CONTROLUNAVAIL || rc == DSERR_INVALIDCALL || rc == DSERR_INVALIDPARAM /* 2003 */) && !secondary)
......@@ -752,7 +764,7 @@ static HRESULT test_secondary(LPGUID lpGuid)
bufdesc.lpwfxFormat=(WAVEFORMATEX*)&wfxe;
wfxe.Format = wfx;
wfxe.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE;
wfxe.SubFormat = KSDATAFORMAT_SUBTYPE_PCM;
wfxe.SubFormat = (format_tags[tag] == WAVE_FORMAT_PCM ? KSDATAFORMAT_SUBTYPE_PCM : KSDATAFORMAT_SUBTYPE_IEEE_FLOAT);
wfxe.Format.cbSize = 1;
wfxe.Samples.wValidBitsPerSample = wfx.wBitsPerSample;
wfxe.dwChannelMask = (wfx.nChannels == 1 ? KSAUDIO_SPEAKER_MONO : KSAUDIO_SPEAKER_STEREO);
......@@ -792,7 +804,7 @@ static HRESULT test_secondary(LPGUID lpGuid)
IDirectSoundBuffer_Release(secondary);
secondary=NULL;
}
wfxe.SubFormat = KSDATAFORMAT_SUBTYPE_PCM;
wfxe.SubFormat = (format_tags[tag] == WAVE_FORMAT_PCM ? KSDATAFORMAT_SUBTYPE_PCM : KSDATAFORMAT_SUBTYPE_IEEE_FLOAT);
++wfxe.Samples.wValidBitsPerSample;
rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
......@@ -825,9 +837,9 @@ static HRESULT test_secondary(LPGUID lpGuid)
no_wfe:
if (rc==DS_OK && secondary!=NULL) {
if (winetest_interactive) {
trace(" Testing a secondary buffer at %dx%dx%d "
trace(" Testing a secondary buffer at %dx%dx%d (fmt=%d) "
"with a primary buffer at %dx%dx%d\n",
wfx.nSamplesPerSec,wfx.wBitsPerSample,wfx.nChannels,
wfx.nSamplesPerSec,wfx.wBitsPerSample,wfx.nChannels,format_tags[tag],
wfx1.nSamplesPerSec,wfx1.wBitsPerSample,wfx1.nChannels);
}
test_buffer(dso,&secondary,0,FALSE,0,FALSE,0,
......@@ -837,6 +849,7 @@ no_wfe:
ok(ref==0,"IDirectSoundBuffer_Release() has %d references, "
"should have 0\n",ref);
}
}
}
EXIT1:
ref=IDirectSoundBuffer_Release(primary);
......
......@@ -18,6 +18,9 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include "wingdi.h"
#include "mmreg.h"
static const unsigned int formats[][4]={
{ 8000, 8, 1, 0 },
{ 8000, 8, 2, 0 },
......@@ -70,11 +73,14 @@ static const unsigned int formats[][4]={
};
#define NB_FORMATS (sizeof(formats)/sizeof(*formats))
static const unsigned int format_tags[] = {WAVE_FORMAT_PCM, WAVE_FORMAT_IEEE_FLOAT};
#define NB_TAGS (sizeof(format_tags)/sizeof(*format_tags))
/* The time slice determines how often we will service the buffer */
#define TIME_SLICE 31
#define BUFFER_LEN 400
extern char* wave_generate_la(WAVEFORMATEX*,double,DWORD*);
extern char* wave_generate_la(WAVEFORMATEX*,double,DWORD*,BOOL);
extern HWND get_hwnd(void);
extern void init_format(WAVEFORMATEX*,int,int,int,int);
extern void test_buffer(LPDIRECTSOUND,LPDIRECTSOUNDBUFFER*,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment