static gboolean gst_directsound_create_buffer (GstRingBuffer * buf) { GstDirectSoundRingBuffer * dsoundbuffer = GST_DIRECTSOUND_RING_BUFFER (buf); HRESULT hr; DSBUFFERDESC descSecondary; LPDIRECTSOUNDBUFFER pDSB; memset (&descSecondary, 0, sizeof (DSBUFFERDESC)); descSecondary.dwSize = sizeof (DSBUFFERDESC); descSecondary.dwFlags = DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_GLOBALFOCUS | DSBCAPS_CTRLVOLUME; descSecondary.dwBufferBytes = dsoundbuffer->buffer_size; descSecondary.lpwfxFormat = (WAVEFORMATEX *) & dsoundbuffer->wave_format; hr = IDirectSound8_CreateSoundBuffer (dsoundbuffer->pDS8, &descSecondary, &pDSB, NULL); if (G_UNLIKELY (FAILED (hr))) { GST_WARNING ("gst_directsound_ring_buffer_acquire: IDirectSound8_CreateSoundBuffer, hr = %X", (unsigned int) hr); return FALSE; } hr = IDirectSoundBuffer_QueryInterface (pDSB, &IID_IDirectSoundBuffer8, (LPVOID *) &dsoundbuffer->pDSB8); if (G_UNLIKELY (FAILED (hr))) { IDirectSoundBuffer_Release (pDSB); GST_WARNING ("gst_directsound_ring_buffer_acquire: IDirectSoundBuffer_QueryInterface, hr = %X", (unsigned int) hr); return FALSE; } IDirectSoundBuffer_Release (pDSB); return TRUE; }
static HRESULT WINAPI IDirectSoundFullDuplex_IDirectSound8_CreateSoundBuffer( LPDIRECTSOUND8 iface, LPCDSBUFFERDESC dsbd, LPLPDIRECTSOUNDBUFFER ppdsb, LPUNKNOWN lpunk) { IDirectSoundFullDuplex_IDirectSound8 *This = (IDirectSoundFullDuplex_IDirectSound8 *)iface; TRACE("(%p,%p,%p,%p)\n",This,dsbd,ppdsb,lpunk); return IDirectSound8_CreateSoundBuffer(This->pdsfd->renderer_device,dsbd,ppdsb,lpunk); }
static HRESULT test_secondary8(LPGUID lpGuid) { HRESULT rc; LPDIRECTSOUND8 dso=NULL; LPDIRECTSOUNDBUFFER primary=NULL,secondary=NULL; DSBUFFERDESC bufdesc; DSCAPS dscaps; WAVEFORMATEX wfx, wfx1; DWORD f; int ref; /* Create the DirectSound object */ rc=pDirectSoundCreate8(lpGuid,&dso,NULL); ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED, "DirectSoundCreate8() failed: %s\n",DXGetErrorString8(rc)); if (rc!=DS_OK) return rc; /* Get the device capabilities */ ZeroMemory(&dscaps, sizeof(dscaps)); dscaps.dwSize=sizeof(dscaps); rc=IDirectSound8_GetCaps(dso,&dscaps); ok(rc==DS_OK,"IDirectSound8_GetCaps() failed: %s\n",DXGetErrorString8(rc)); if (rc!=DS_OK) goto EXIT; /* We must call SetCooperativeLevel before creating primary buffer */ /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */ rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY); ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel() failed: %s\n", DXGetErrorString8(rc)); if (rc!=DS_OK) goto EXIT; ZeroMemory(&bufdesc, sizeof(bufdesc)); bufdesc.dwSize=sizeof(bufdesc); bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER; rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&primary,NULL); ok(rc==DS_OK && primary!=NULL, "IDirectSound8_CreateSoundBuffer() failed to create a primary buffer " "%s\n",DXGetErrorString8(rc)); if (rc==DS_OK && primary!=NULL) { rc=IDirectSoundBuffer_GetFormat(primary,&wfx1,sizeof(wfx1),NULL); ok(rc==DS_OK,"IDirectSoundBuffer8_Getformat() failed: %s\n", DXGetErrorString8(rc)); if (rc!=DS_OK) goto EXIT1; for (f=0;f<NB_FORMATS;f++) { init_format(&wfx,WAVE_FORMAT_PCM,formats[f][0],formats[f][1], formats[f][2]); secondary=NULL; ZeroMemory(&bufdesc, sizeof(bufdesc)); bufdesc.dwSize=sizeof(bufdesc); bufdesc.dwFlags=DSBCAPS_GETCURRENTPOSITION2; 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", DXGetErrorString8(rc)); if (rc==DS_OK && secondary!=NULL) IDirectSoundBuffer_Release(secondary); secondary=NULL; ZeroMemory(&bufdesc, sizeof(bufdesc)); bufdesc.dwSize=sizeof(bufdesc); bufdesc.dwFlags=DSBCAPS_GETCURRENTPOSITION2; 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 " "with a primary buffer at %ldx%dx%d\n", wfx.nSamplesPerSec,wfx.wBitsPerSample,wfx.nChannels, wfx1.nSamplesPerSec,wfx1.wBitsPerSample,wfx1.nChannels); } rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL); ok(rc==DS_OK && secondary!=NULL, "IDirectSound8_CreateSoundBuffer() failed to create a secondary " "buffer: %s\n",DXGetErrorString8(rc)); if (rc==DS_OK && secondary!=NULL) { test_buffer8(dso,secondary,0,FALSE,0,FALSE,0, winetest_interactive,1.0,0,NULL,0,0); ref=IDirectSoundBuffer_Release(secondary); ok(ref==0,"IDirectSoundBuffer_Release() has %d references, " "should have 0\n",ref); } } EXIT1: ref=IDirectSoundBuffer_Release(primary); ok(ref==0,"IDirectSoundBuffer_Release() primary has %d references, " "should have 0\n",ref); } /* Set the CooperativeLevel back to normal */ /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */ rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL); ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel() failed: %s\n", DXGetErrorString8(rc)); EXIT: ref=IDirectSound8_Release(dso); ok(ref==0,"IDirectSound8_Release() has %d references, should have 0\n",ref); if (ref!=0) return DSERR_GENERIC; return rc; }
/* * Test the primary buffer at different formats while keeping the * secondary buffer at a constant format. */ static HRESULT test_primary_secondary8(LPGUID lpGuid) { HRESULT rc; LPDIRECTSOUND8 dso=NULL; LPDIRECTSOUNDBUFFER primary=NULL,secondary=NULL; DSBUFFERDESC bufdesc; DSCAPS dscaps; WAVEFORMATEX wfx, wfx2; int ref; unsigned int f; /* Create the DirectSound object */ rc=pDirectSoundCreate8(lpGuid,&dso,NULL); ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED, "DirectSoundCreate8() failed: %s\n",DXGetErrorString8(rc)); if (rc!=DS_OK) return rc; /* Get the device capabilities */ ZeroMemory(&dscaps, sizeof(dscaps)); dscaps.dwSize=sizeof(dscaps); rc=IDirectSound8_GetCaps(dso,&dscaps); ok(rc==DS_OK,"IDirectSound8_GetCaps() failed: %s\n",DXGetErrorString8(rc)); if (rc!=DS_OK) goto EXIT; /* We must call SetCooperativeLevel before creating primary buffer */ /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */ rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY); ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel() failed: %s\n", DXGetErrorString8(rc)); if (rc!=DS_OK) goto EXIT; ZeroMemory(&bufdesc, sizeof(bufdesc)); bufdesc.dwSize=sizeof(bufdesc); bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER; rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&primary,NULL); ok(rc==DS_OK && primary!=NULL, "IDirectSound8_CreateSoundBuffer() failed to create a primary buffer " "%s\n",DXGetErrorString8(rc)); if (rc==DS_OK && primary!=NULL) { for (f=0;f<NB_FORMATS;f++) { /* We must call SetCooperativeLevel to be allowed to call * SetFormat */ /* DSOUND: Setting DirectSound cooperative level to * DSSCL_PRIORITY */ rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY); ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel() failed: %s\n", DXGetErrorString8(rc)); if (rc!=DS_OK) goto EXIT; init_format(&wfx,WAVE_FORMAT_PCM,formats[f][0],formats[f][1], formats[f][2]); wfx2=wfx; rc=IDirectSoundBuffer_SetFormat(primary,&wfx); ok(rc==DS_OK,"IDirectSoundBuffer_SetFormat() failed: %s\n", DXGetErrorString8(rc)); /* There is no garantee that SetFormat will actually change the * format to what we asked for. It depends on what the soundcard * supports. So we must re-query the format. */ rc=IDirectSoundBuffer_GetFormat(primary,&wfx,sizeof(wfx),NULL); ok(rc==DS_OK,"IDirectSoundBuffer_GetFormat() failed: %s\n", DXGetErrorString8(rc)); if (rc==DS_OK && (wfx.wFormatTag!=wfx2.wFormatTag || wfx.nSamplesPerSec!=wfx2.nSamplesPerSec || wfx.wBitsPerSample!=wfx2.wBitsPerSample || wfx.nChannels!=wfx2.nChannels)) { trace("Requested primary format tag=0x%04x %ldx%dx%d " "avg.B/s=%ld align=%d\n", wfx2.wFormatTag,wfx2.nSamplesPerSec,wfx2.wBitsPerSample, wfx2.nChannels,wfx2.nAvgBytesPerSec,wfx2.nBlockAlign); trace("Got tag=0x%04x %ldx%dx%d avg.B/s=%ld align=%d\n", wfx.wFormatTag,wfx.nSamplesPerSec,wfx.wBitsPerSample, wfx.nChannels,wfx.nAvgBytesPerSec,wfx.nBlockAlign); } /* Set the CooperativeLevel back to normal */ /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */ rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL); ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel() failed: %s\n", DXGetErrorString8(rc)); init_format(&wfx2,WAVE_FORMAT_PCM,11025,16,2); secondary=NULL; ZeroMemory(&bufdesc, sizeof(bufdesc)); bufdesc.dwSize=sizeof(bufdesc); bufdesc.dwFlags=DSBCAPS_GETCURRENTPOSITION2; 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 " "secondary buffer at %ldx%dx%d\n", wfx.nSamplesPerSec,wfx.wBitsPerSample,wfx.nChannels, wfx2.nSamplesPerSec,wfx2.wBitsPerSample,wfx2.nChannels); } rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL); ok(rc==DS_OK && secondary!=NULL, "IDirectSound_CreateSoundBuffer() failed to create a secondary " "buffer %s\n",DXGetErrorString8(rc)); if (rc==DS_OK && secondary!=NULL) { test_buffer8(dso,secondary,0,FALSE,0,FALSE,0, winetest_interactive,1.0,0,NULL,0,0); ref=IDirectSoundBuffer_Release(secondary); ok(ref==0,"IDirectSoundBuffer_Release() has %d references, " "should have 0\n",ref); } } ref=IDirectSoundBuffer_Release(primary); ok(ref==0,"IDirectSoundBuffer_Release() primary has %d references, " "should have 0\n",ref); } /* Set the CooperativeLevel back to normal */ /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */ rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL); ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel() failed: %s\n", DXGetErrorString8(rc)); EXIT: ref=IDirectSound8_Release(dso); ok(ref==0,"IDirectSound8_Release() has %d references, should have 0\n",ref); if (ref!=0) return DSERR_GENERIC; return rc; }
static HRESULT test_primary8(LPGUID lpGuid) { HRESULT rc; LPDIRECTSOUND8 dso=NULL; LPDIRECTSOUNDBUFFER primary=NULL,second=NULL,third=NULL; DSBUFFERDESC bufdesc; DSCAPS dscaps; WAVEFORMATEX wfx; int ref; /* Create the DirectSound object */ rc=pDirectSoundCreate8(lpGuid,&dso,NULL); ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED, "DirectSoundCreate8() failed: %s\n",DXGetErrorString8(rc)); if (rc!=DS_OK) return rc; /* Get the device capabilities */ ZeroMemory(&dscaps, sizeof(dscaps)); dscaps.dwSize=sizeof(dscaps); rc=IDirectSound8_GetCaps(dso,&dscaps); ok(rc==DS_OK,"IDirectSound8_GetCaps() failed: %s\n",DXGetErrorString8(rc)); if (rc!=DS_OK) goto EXIT; /* DSOUND: Error: Invalid buffer description pointer */ rc=IDirectSound8_CreateSoundBuffer(dso,0,0,NULL); ok(rc==DSERR_INVALIDPARAM, "IDirectSound8_CreateSoundBuffer should have returned " "DSERR_INVALIDPARAM, returned: %s\n",DXGetErrorString8(rc)); /* DSOUND: Error: Invalid buffer description pointer */ rc=IDirectSound8_CreateSoundBuffer(dso,0,&primary,NULL); ok(rc==DSERR_INVALIDPARAM && primary==0, "IDirectSound8_CreateSoundBuffer() should have returned " "DSERR_INVALIDPARAM, returned: rc=%s,dsbo=%p\n", DXGetErrorString8(rc),primary); /* DSOUND: Error: Invalid buffer description pointer */ rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,0,NULL); ok(rc==DSERR_INVALIDPARAM && primary==0, "IDirectSound8_CreateSoundBuffer() should have failed: rc=%s," "dsbo=%p\n",DXGetErrorString8(rc),primary); ZeroMemory(&bufdesc, sizeof(bufdesc)); /* DSOUND: Error: Invalid size */ /* DSOUND: Error: Invalid buffer description */ rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&primary,NULL); ok(rc==DSERR_INVALIDPARAM && primary==0, "IDirectSound8_CreateSoundBuffer() should have failed: rc=%s," "primary=%p\n",DXGetErrorString8(rc),primary); /* We must call SetCooperativeLevel before calling CreateSoundBuffer */ /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */ rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY); ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel() failed: %s\n", DXGetErrorString8(rc)); if (rc!=DS_OK) goto EXIT; /* Testing the primary buffer */ primary=NULL; ZeroMemory(&bufdesc, sizeof(bufdesc)); bufdesc.dwSize=sizeof(bufdesc); bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER|DSBCAPS_CTRLVOLUME; bufdesc.lpwfxFormat = &wfx; init_format(&wfx,WAVE_FORMAT_PCM,11025,8,2); rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&primary,NULL); ok(rc==DSERR_INVALIDPARAM,"IDirectSound8_CreateSoundBuffer() should have " "returned DSERR_INVALIDPARAM, returned: %s\n", DXGetErrorString8(rc)); if (rc==DS_OK && primary!=NULL) IDirectSoundBuffer_Release(primary); primary=NULL; ZeroMemory(&bufdesc, sizeof(bufdesc)); bufdesc.dwSize=sizeof(bufdesc); bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER|DSBCAPS_CTRLVOLUME; rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&primary,NULL); ok((rc==DS_OK && primary!=NULL) || (rc==DSERR_CONTROLUNAVAIL), "IDirectSound8_CreateSoundBuffer() failed to create a primary buffer: " "%s\n",DXGetErrorString8(rc)); if (rc==DSERR_CONTROLUNAVAIL) trace(" No Primary\n"); else if (rc==DS_OK && primary!=NULL) { LONG vol; /* Try to create a second primary buffer */ /* DSOUND: Error: The primary buffer already exists. * Any changes made to the buffer description will be ignored. */ rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&second,NULL); ok(rc==DS_OK && second==primary, "IDirectSound8_CreateSoundBuffer() should have returned original " "primary buffer: %s\n",DXGetErrorString8(rc)); ref=IDirectSoundBuffer_Release(second); ok(ref==1,"IDirectSoundBuffer_Release() primary has %d references, " "should have 1\n",ref); /* Try to duplicate a primary buffer */ /* DSOUND: Error: Can't duplicate primary buffers */ rc=IDirectSound8_DuplicateSoundBuffer(dso,primary,&third); /* rc=0x88780032 */ ok(rc!=DS_OK,"IDirectSound8_DuplicateSoundBuffer() primary buffer " "should have failed %s\n",DXGetErrorString8(rc)); rc=IDirectSoundBuffer_GetVolume(primary,&vol); ok(rc==DS_OK,"IDirectSoundBuffer_GetVolume() failed: %s\n", DXGetErrorString8(rc)); if (winetest_interactive) { trace("Playing a 5 seconds reference tone at the current volume.\n"); if (rc==DS_OK) trace("(the current volume is %ld according to DirectSound)\n", vol); trace("All subsequent tones should be identical to this one.\n"); trace("Listen for stutter, changes in pitch, volume, etc.\n"); } test_buffer8(dso,primary,1,FALSE,0,FALSE,0,winetest_interactive && !(dscaps.dwFlags & DSCAPS_EMULDRIVER),5.0,0,0,0,0); ref=IDirectSoundBuffer_Release(primary); ok(ref==0,"IDirectSoundBuffer_Release() primary has %d references, " "should have 0\n",ref); } /* Set the CooperativeLevel back to normal */ /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */ rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL); ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel() failed: %s\n", DXGetErrorString8(rc)); EXIT: ref=IDirectSound8_Release(dso); ok(ref==0,"IDirectSound8_Release() has %d references, should have 0\n",ref); if (ref!=0) return DSERR_GENERIC; return rc; }
static HRESULT test_dsound8(LPGUID lpGuid) { HRESULT rc; LPDIRECTSOUND8 dso=NULL; int ref; /* DSOUND: Error: Invalid interface buffer */ rc=pDirectSoundCreate8(lpGuid,0,NULL); ok(rc==DSERR_INVALIDPARAM,"DirectSoundCreate8() should have returned " "DSERR_INVALIDPARAM, returned: %s\n",DXGetErrorString8(rc)); /* Create the DirectSound8 object */ rc=pDirectSoundCreate8(lpGuid,&dso,NULL); ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED||rc==E_FAIL, "DirectSoundCreate8() failed: %s\n",DXGetErrorString8(rc)); if (rc!=DS_OK) return rc; /* Try the enumerated device */ IDirectSound8_test(dso, TRUE, lpGuid); /* Try the COM class factory method of creation with enumerated device */ rc=CoCreateInstance(&CLSID_DirectSound8, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectSound8, (void**)&dso); ok(rc==S_OK,"CoCreateInstance(CLSID_DirectSound) failed: %s\n", DXGetErrorString8(rc)); if (dso) IDirectSound8_test(dso, FALSE, lpGuid); /* Create a DirectSound8 object */ rc=pDirectSoundCreate8(lpGuid,&dso,NULL); ok(rc==DS_OK,"DirectSoundCreate8() failed: %s\n",DXGetErrorString8(rc)); if (rc==DS_OK) { LPDIRECTSOUND8 dso1=NULL; /* Create a second DirectSound8 object */ rc=pDirectSoundCreate8(lpGuid,&dso1,NULL); ok(rc==DS_OK,"DirectSoundCreate8() failed: %s\n",DXGetErrorString8(rc)); if (rc==DS_OK) { /* Release the second DirectSound8 object */ ref=IDirectSound8_Release(dso1); ok(ref==0,"IDirectSound8_Release() has %d references, " "should have 0\n",ref); ok(dso!=dso1,"DirectSound8 objects should be unique: " "dso=%p,dso1=%p\n",dso,dso1); } /* Release the first DirectSound8 object */ ref=IDirectSound8_Release(dso); ok(ref==0,"IDirectSound8_Release() has %d references, should have 0\n", ref); if (ref!=0) return DSERR_GENERIC; } else return rc; /* Create a DirectSound8 object */ rc=pDirectSoundCreate8(lpGuid,&dso,NULL); ok(rc==DS_OK,"DirectSoundCreate8() failed: %s\n",DXGetErrorString8(rc)); if (rc==DS_OK) { LPDIRECTSOUNDBUFFER secondary; DSBUFFERDESC bufdesc; WAVEFORMATEX wfx; init_format(&wfx,WAVE_FORMAT_PCM,11025,8,1); ZeroMemory(&bufdesc, sizeof(bufdesc)); bufdesc.dwSize=sizeof(bufdesc); bufdesc.dwFlags=DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_CTRL3D; 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, "IDirectSound8_CreateSoundBuffer() failed to create a secondary " "buffer: %s\n",DXGetErrorString8(rc)); if (rc==DS_OK && secondary!=NULL) { LPDIRECTSOUND3DBUFFER buffer3d; LPDIRECTSOUNDBUFFER8 buffer8; rc=IDirectSound8_QueryInterface(secondary, &IID_IDirectSound3DBuffer, (void **)&buffer3d); ok(rc==DS_OK && buffer3d!=NULL, "IDirectSound8_QueryInterface() failed: %s\n", DXGetErrorString8(rc)); if (rc==DS_OK && buffer3d!=NULL) { ref=IDirectSound3DBuffer_AddRef(buffer3d); ok(ref==2,"IDirectSound3DBuffer_AddRef() has %d references, " "should have 2\n",ref); } rc=IDirectSound8_QueryInterface(secondary, &IID_IDirectSoundBuffer8, (void **)&buffer8); if (rc==DS_OK && buffer8!=NULL) { ref=IDirectSoundBuffer8_AddRef(buffer8); ok(ref==3,"IDirectSoundBuffer8_AddRef() has %d references, " "should have 3\n",ref); } ref=IDirectSoundBuffer_AddRef(secondary); ok(ref==4,"IDirectSoundBuffer_AddRef() has %d references, " "should have 4\n",ref); } /* release with buffer */ ref=IDirectSound8_Release(dso); ok(ref==0,"IDirectSound8_Release() has %d references, should have 0\n", ref); if (ref!=0) return DSERR_GENERIC; } else return rc; return DS_OK; }
static void test_hw_buffers(void) { IDirectSound8 *ds; IDirectSoundBuffer *primary, *primary2, **secondaries, *secondary; IDirectSoundBuffer8 *buf8; DSCAPS caps; DSBCAPS bufcaps; DSBUFFERDESC bufdesc; WAVEFORMATEX fmt; UINT i; HRESULT hr; hr = pDirectSoundCreate8(NULL, &ds, NULL); ok(hr == S_OK || hr == DSERR_NODRIVER || hr == DSERR_ALLOCATED || hr == E_FAIL, "DirectSoundCreate8 failed: %08x\n", hr); if(hr != S_OK) return; caps.dwSize = sizeof(caps); hr = IDirectSound8_GetCaps(ds, &caps); ok(hr == S_OK, "GetCaps failed: %08x\n", hr); ok(caps.dwPrimaryBuffers == 1, "Got wrong number of primary buffers: %u\n", caps.dwPrimaryBuffers); /* DSBCAPS_LOC* is ignored for primary buffers */ bufdesc.dwSize = sizeof(bufdesc); bufdesc.dwFlags = DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_LOCHARDWARE | DSBCAPS_PRIMARYBUFFER; bufdesc.dwBufferBytes = 0; bufdesc.dwReserved = 0; bufdesc.lpwfxFormat = NULL; bufdesc.guid3DAlgorithm = GUID_NULL; hr = IDirectSound8_CreateSoundBuffer(ds, &bufdesc, &primary, NULL); ok(hr == S_OK, "CreateSoundBuffer failed: %08x\n", hr); if(hr != S_OK){ IDirectSound8_Release(ds); return; } bufdesc.dwFlags = DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_LOCSOFTWARE | DSBCAPS_PRIMARYBUFFER; hr = IDirectSound8_CreateSoundBuffer(ds, &bufdesc, &primary2, NULL); ok(hr == S_OK, "CreateSoundBuffer failed: %08x\n", hr); ok(primary == primary2, "Got different primary buffers: %p, %p\n", primary, primary2); if(hr == S_OK) IDirectSoundBuffer_Release(primary2); buf8 = (IDirectSoundBuffer8 *)0xDEADBEEF; hr = IDirectSoundBuffer_QueryInterface(primary, &IID_IDirectSoundBuffer8, (void**)&buf8); ok(hr == E_NOINTERFACE, "QueryInterface gave wrong failure: %08x\n", hr); ok(buf8 == NULL, "Pointer didn't get set to NULL\n"); fmt.wFormatTag = WAVE_FORMAT_PCM; fmt.nChannels = 2; fmt.nSamplesPerSec = 48000; fmt.wBitsPerSample = 16; fmt.nBlockAlign = fmt.nChannels * fmt.wBitsPerSample / 8; fmt.nAvgBytesPerSec = fmt.nBlockAlign * fmt.nSamplesPerSec; fmt.cbSize = 0; bufdesc.lpwfxFormat = &fmt; bufdesc.dwBufferBytes = fmt.nSamplesPerSec * fmt.nBlockAlign / 10; bufdesc.dwFlags = DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_LOCHARDWARE | DSBCAPS_CTRLVOLUME; secondaries = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectSoundBuffer *) * caps.dwMaxHwMixingAllBuffers); /* try to fill all of the hw buffers */ trace("dwMaxHwMixingAllBuffers: %u\n", caps.dwMaxHwMixingAllBuffers); trace("dwMaxHwMixingStaticBuffers: %u\n", caps.dwMaxHwMixingStaticBuffers); trace("dwMaxHwMixingStreamingBuffers: %u\n", caps.dwMaxHwMixingStreamingBuffers); for(i = 0; i < caps.dwMaxHwMixingAllBuffers; ++i){ hr = IDirectSound8_CreateSoundBuffer(ds, &bufdesc, &secondaries[i], NULL); ok(hr == S_OK || hr == E_NOTIMPL || broken(hr == DSERR_CONTROLUNAVAIL) || broken(hr == E_FAIL), "CreateSoundBuffer(%u) failed: %08x\n", i, hr); if(hr != S_OK) break; bufcaps.dwSize = sizeof(bufcaps); hr = IDirectSoundBuffer_GetCaps(secondaries[i], &bufcaps); ok(hr == S_OK, "GetCaps failed: %08x\n", hr); ok((bufcaps.dwFlags & DSBCAPS_LOCHARDWARE) != 0, "Buffer wasn't allocated in hardware, dwFlags: %x\n", bufcaps.dwFlags); } /* see if we can create one more */ hr = IDirectSound8_CreateSoundBuffer(ds, &bufdesc, &secondary, NULL); ok((i == caps.dwMaxHwMixingAllBuffers && hr == DSERR_ALLOCATED) || /* out of hw buffers */ (caps.dwMaxHwMixingAllBuffers == 0 && hr == DSERR_INVALIDCALL) || /* no hw buffers at all */ hr == E_NOTIMPL || /* don't support hw buffers */ broken(hr == DSERR_CONTROLUNAVAIL) || /* vmware winxp, others? */ broken(hr == E_FAIL) || /* broken AC97 driver */ broken(hr == S_OK) /* broken driver allows more hw bufs than dscaps claims */, "CreateSoundBuffer(%u) gave wrong error: %08x\n", i, hr); if(hr == S_OK) IDirectSoundBuffer_Release(secondary); for(i = 0; i < caps.dwMaxHwMixingAllBuffers; ++i) if(secondaries[i]) IDirectSoundBuffer_Release(secondaries[i]); HeapFree(GetProcessHeap(), 0, secondaries); IDirectSoundBuffer_Release(primary); IDirectSound8_Release(ds); }
static HRESULT test_secondary8(LPGUID lpGuid) { HRESULT rc; LPDIRECTSOUND8 dso=NULL; LPDIRECTSOUNDBUFFER primary=NULL,secondary=NULL; DSBUFFERDESC bufdesc; DSCAPS dscaps; WAVEFORMATEX wfx, wfx1; DWORD f, tag; int ref; /* Create the DirectSound object */ rc=pDirectSoundCreate8(lpGuid,&dso,NULL); ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED, "DirectSoundCreate8() failed: %08x\n",rc); if (rc!=DS_OK) return rc; /* Get the device capabilities */ ZeroMemory(&dscaps, sizeof(dscaps)); dscaps.dwSize=sizeof(dscaps); rc=IDirectSound8_GetCaps(dso,&dscaps); ok(rc==DS_OK,"IDirectSound8_GetCaps() failed: %08x\n",rc); if (rc!=DS_OK) goto EXIT; /* We must call SetCooperativeLevel before creating primary buffer */ /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */ rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY); ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel() failed: %08x\n", rc); if (rc!=DS_OK) goto EXIT; ZeroMemory(&bufdesc, sizeof(bufdesc)); bufdesc.dwSize=sizeof(bufdesc); bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER; rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&primary,NULL); ok(rc==DS_OK && primary!=NULL, "IDirectSound8_CreateSoundBuffer() failed to create a primary buffer " "%08x\n",rc); if (rc==DS_OK && primary!=NULL) { rc=IDirectSoundBuffer_GetFormat(primary,&wfx1,sizeof(wfx1),NULL); ok(rc==DS_OK,"IDirectSoundBuffer8_Getformat() failed: %08x\n", rc); if (rc!=DS_OK) goto EXIT1; for (f=0;f<NB_FORMATS;f++) { for (tag=0;tag<NB_TAGS;tag++) { WAVEFORMATEXTENSIBLE wfxe; /* 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)); bufdesc.dwSize=sizeof(bufdesc); bufdesc.dwFlags=DSBCAPS_GETCURRENTPOSITION2; 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: %08x\n", rc); if (rc==DS_OK && secondary!=NULL) IDirectSoundBuffer_Release(secondary); secondary=NULL; ZeroMemory(&bufdesc, sizeof(bufdesc)); bufdesc.dwSize=sizeof(bufdesc); bufdesc.dwFlags=DSBCAPS_GETCURRENTPOSITION2; bufdesc.dwBufferBytes=align(wfx.nAvgBytesPerSec*BUFFER_LEN/1000, wfx.nBlockAlign); bufdesc.lpwfxFormat=&wfx; rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL); if (wfx.wBitsPerSample != 8 && wfx.wBitsPerSample != 16) ok(((rc == DSERR_CONTROLUNAVAIL || rc == DSERR_INVALIDCALL || rc == DSERR_INVALIDPARAM /* 2003 */) && !secondary) || rc == DS_OK, /* driver dependent? */ "IDirectSound_CreateSoundBuffer() " "should have returned (DSERR_CONTROLUNAVAIL or DSERR_INVALIDCALL) " "and NULL, returned: %08x %p\n", rc, secondary); else ok(rc==DS_OK && secondary!=NULL, "IDirectSound_CreateSoundBuffer() failed to create a secondary " "buffer %08x\n",rc); if (secondary) IDirectSoundBuffer_Release(secondary); secondary = NULL; bufdesc.lpwfxFormat=(WAVEFORMATEX*)&wfxe; wfxe.Format = wfx; wfxe.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE; 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); rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL); ok(rc==DSERR_INVALIDPARAM && !secondary, "IDirectSound_CreateSoundBuffer() returned: %08x %p\n", rc, secondary); if (secondary) { IDirectSoundBuffer_Release(secondary); secondary=NULL; } wfxe.Format.cbSize = sizeof(wfxe) - sizeof(wfx) + 1; rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL); ok(((rc==DSERR_CONTROLUNAVAIL || rc==DSERR_INVALIDCALL /* 2003 */) && !secondary) || rc==DS_OK /* driver dependent? */, "IDirectSound_CreateSoundBuffer() returned: %08x %p\n", rc, secondary); if (secondary) { IDirectSoundBuffer_Release(secondary); secondary=NULL; } wfxe.Format.cbSize = sizeof(wfxe) - sizeof(wfx); wfxe.SubFormat = GUID_NULL; rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL); ok((rc==DSERR_INVALIDPARAM || rc==DSERR_INVALIDCALL) && !secondary, "IDirectSound_CreateSoundBuffer() returned: %08x %p\n", rc, secondary); if (secondary) { IDirectSoundBuffer_Release(secondary); secondary=NULL; } wfxe.Format.cbSize = sizeof(wfxe); rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL); ok((rc==DSERR_CONTROLUNAVAIL || rc==DSERR_INVALIDCALL || rc==E_INVALIDARG) && !secondary, "IDirectSound_CreateSoundBuffer() returned: %08x %p\n", rc, secondary); if (secondary) { IDirectSoundBuffer_Release(secondary); secondary=NULL; } wfxe.SubFormat = (format_tags[tag] == WAVE_FORMAT_PCM ? KSDATAFORMAT_SUBTYPE_PCM : KSDATAFORMAT_SUBTYPE_IEEE_FLOAT); rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL); ok(rc==DS_OK && secondary, "IDirectSound_CreateSoundBuffer() returned: %08x %p\n", rc, secondary); if (secondary) { IDirectSoundBuffer_Release(secondary); secondary=NULL; } wfxe.Format.cbSize = sizeof(wfxe) + 1; rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL); ok(((rc==DSERR_CONTROLUNAVAIL || rc==DSERR_INVALIDCALL /* 2003 */) && !secondary) || rc==DS_OK /* driver dependent? */, "IDirectSound_CreateSoundBuffer() returned: %08x %p\n", rc, secondary); if (secondary) { IDirectSoundBuffer_Release(secondary); secondary=NULL; } wfxe.Format.cbSize = sizeof(wfxe) - sizeof(wfx); ++wfxe.Samples.wValidBitsPerSample; rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL); ok(rc==DSERR_INVALIDPARAM && !secondary, "IDirectSound_CreateSoundBuffer() returned: %08x %p\n", rc, secondary); if (secondary) { IDirectSoundBuffer_Release(secondary); secondary=NULL; } --wfxe.Samples.wValidBitsPerSample; wfxe.Samples.wValidBitsPerSample = 0; rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL); ok(rc==DS_OK && secondary, "IDirectSound_CreateSoundBuffer() returned: %08x %p\n", rc, secondary); if (secondary) { IDirectSoundBuffer_Release(secondary); secondary=NULL; } wfxe.Samples.wValidBitsPerSample = wfxe.Format.wBitsPerSample; rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL); ok(rc==DS_OK && secondary!=NULL, "IDirectSound_CreateSoundBuffer() failed to create a secondary " "buffer %08x\n",rc); if (rc==DS_OK && secondary!=NULL) { if (winetest_interactive) { 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,format_tags[tag], wfx1.nSamplesPerSec,wfx1.wBitsPerSample,wfx1.nChannels); } test_buffer8(dso,&secondary,0,FALSE,0,FALSE,0, winetest_interactive,1.0,0,NULL,0,0); ref=IDirectSoundBuffer_Release(secondary); ok(ref==0,"IDirectSoundBuffer_Release() has %d references, " "should have 0\n",ref); } } } EXIT1: ref=IDirectSoundBuffer_Release(primary); ok(ref==0,"IDirectSoundBuffer_Release() primary has %d references, " "should have 0\n",ref); } /* Set the CooperativeLevel back to normal */ /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */ rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL); ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel() failed: %08x\n", rc); EXIT: ref=IDirectSound8_Release(dso); ok(ref==0,"IDirectSound8_Release() has %d references, should have 0\n",ref); if (ref!=0) return DSERR_GENERIC; return rc; }
int SNDDXInit(int buffersize) { DSBUFFERDESC dsbdesc; WAVEFORMATEX wfx; HRESULT ret; char tempstr[512]; if ((ret = DirectSoundCreate8(NULL, &lpDS8, NULL)) != DS_OK) { sprintf(tempstr, "DirectSound8Create error: %s - %s", DXGetErrorString8(ret), DXGetErrorDescription8(ret)); MessageBox (NULL, tempstr, "Error", MB_OK | MB_ICONINFORMATION); return -1; } if ((ret = IDirectSound8_SetCooperativeLevel(lpDS8, hwnd, DSSCL_PRIORITY)) != DS_OK) { sprintf(tempstr, "IDirectSound8_SetCooperativeLevel error: %s - %s", DXGetErrorString8(ret), DXGetErrorDescription8(ret)); MessageBox (NULL, tempstr, "Error", MB_OK | MB_ICONINFORMATION); return -1; } memset(&dsbdesc, 0, sizeof(dsbdesc)); dsbdesc.dwSize = sizeof(DSBUFFERDESC); dsbdesc.dwFlags = DSBCAPS_PRIMARYBUFFER; dsbdesc.dwBufferBytes = 0; dsbdesc.lpwfxFormat = NULL; if ((ret = IDirectSound8_CreateSoundBuffer(lpDS8, &dsbdesc, &lpDSB, NULL)) != DS_OK) { sprintf(tempstr, "Error when creating primary sound buffer: %s - %s", DXGetErrorString8(ret), DXGetErrorDescription8(ret)); MessageBox (NULL, tempstr, "Error", MB_OK | MB_ICONINFORMATION); return -1; } soundbufsize = buffersize * 2 * 2; memset(&wfx, 0, sizeof(wfx)); wfx.wFormatTag = WAVE_FORMAT_PCM; wfx.nChannels = 2; wfx.nSamplesPerSec = 44100; wfx.wBitsPerSample = 16; wfx.nBlockAlign = (wfx.wBitsPerSample / 8) * wfx.nChannels; wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign; if ((ret = IDirectSoundBuffer8_SetFormat(lpDSB, &wfx)) != DS_OK) { sprintf(tempstr, "IDirectSoundBuffer8_SetFormat error: %s - %s", DXGetErrorString8(ret), DXGetErrorDescription8(ret)); MessageBox (NULL, tempstr, "Error", MB_OK | MB_ICONINFORMATION); return -1; } memset(&dsbdesc, 0, sizeof(dsbdesc)); dsbdesc.dwSize = sizeof(DSBUFFERDESC); dsbdesc.dwFlags = DSBCAPS_GLOBALFOCUS | DSBCAPS_STICKYFOCUS | DSBCAPS_CTRLVOLUME | DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_LOCHARDWARE; dsbdesc.dwBufferBytes = soundbufsize; dsbdesc.lpwfxFormat = &wfx; if ((ret = IDirectSound8_CreateSoundBuffer(lpDS8, &dsbdesc, &lpDSB2, NULL)) != DS_OK) { if (ret == DSERR_CONTROLUNAVAIL || ret == DSERR_INVALIDCALL || ret == E_FAIL || ret == E_NOTIMPL) { // Try using a software buffer instead dsbdesc.dwFlags = DSBCAPS_GLOBALFOCUS | DSBCAPS_STICKYFOCUS | DSBCAPS_CTRLVOLUME | DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_LOCSOFTWARE; if ((ret = IDirectSound8_CreateSoundBuffer(lpDS8, &dsbdesc, &lpDSB2, NULL)) != DS_OK) { sprintf(tempstr, "Error when creating secondary sound buffer: %s - %s", DXGetErrorString8(ret), DXGetErrorDescription8(ret)); MessageBox (NULL, tempstr, "Error", MB_OK | MB_ICONINFORMATION); return -1; } } else { sprintf(tempstr, "Error when creating secondary sound buffer: %s - %s", DXGetErrorString8(ret), DXGetErrorDescription8(ret)); MessageBox (NULL, tempstr, "Error", MB_OK | MB_ICONINFORMATION); return -1; } } IDirectSoundBuffer8_Play(lpDSB2, 0, 0, DSBPLAY_LOOPING); if ((stereodata16 = (s16 *)malloc(soundbufsize)) == NULL) return -1; memset(stereodata16, 0, soundbufsize); soundvolume = DSBVOLUME_MAX; issoundmuted = 0; return 0; }
static HRESULT WINAPI IDirectMusicPerformance8Impl_CreateStandardAudioPath (LPDIRECTMUSICPERFORMANCE8 iface, DWORD dwType, DWORD dwPChannelCount, BOOL fActivate, IDirectMusicAudioPath** ppNewPath) { IDirectMusicAudioPathImpl *default_path; IDirectMusicAudioPath *pPath; DSBUFFERDESC desc; WAVEFORMATEX format; LPDIRECTSOUNDBUFFER buffer; HRESULT hr = S_OK; IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface; FIXME("(%p)->(%d, %d, %d, %p): semi-stub\n", This, dwType, dwPChannelCount, fActivate, ppNewPath); if (NULL == ppNewPath) { return E_POINTER; } DMUSIC_CreateDirectMusicAudioPathImpl (&IID_IDirectMusicAudioPath, (LPVOID*)&pPath, NULL); default_path = (IDirectMusicAudioPathImpl*)((char*)(pPath) - offsetof(IDirectMusicAudioPathImpl,AudioPathVtbl)); default_path->pPerf = (IDirectMusicPerformance8*) This; /* Secondary buffer description */ memset(&format, 0, sizeof(format)); format.wFormatTag = WAVE_FORMAT_PCM; format.nChannels = 1; format.nSamplesPerSec = 44000; format.nAvgBytesPerSec = 44000*2; format.nBlockAlign = 2; format.wBitsPerSample = 16; format.cbSize = 0; memset(&desc, 0, sizeof(desc)); desc.dwSize = sizeof(desc); desc.dwFlags = DSBCAPS_CTRLFX | DSBCAPS_CTRLPAN | DSBCAPS_CTRLVOLUME | DSBCAPS_GLOBALFOCUS; desc.dwBufferBytes = DSBSIZE_MIN; desc.dwReserved = 0; desc.lpwfxFormat = &format; desc.guid3DAlgorithm = GUID_NULL; switch(dwType) { case DMUS_APATH_DYNAMIC_3D: desc.dwFlags |= DSBCAPS_CTRL3D | DSBCAPS_CTRLFREQUENCY | DSBCAPS_MUTE3DATMAXDISTANCE; break; case DMUS_APATH_DYNAMIC_MONO: desc.dwFlags |= DSBCAPS_CTRLFREQUENCY; break; case DMUS_APATH_SHARED_STEREOPLUSREVERB: /* normally we have to create 2 buffers (one for music other for reverb) * in this case. See msdn */ case DMUS_APATH_DYNAMIC_STEREO: desc.dwFlags |= DSBCAPS_CTRLFREQUENCY; format.nChannels = 2; format.nBlockAlign *= 2; format.nAvgBytesPerSec *=2; break; default: HeapFree(GetProcessHeap(), 0, default_path); *ppNewPath = NULL; return E_INVALIDARG; } /* FIXME: Should we create one secondary buffer for each PChannel? */ hr = IDirectSound8_CreateSoundBuffer ((LPDIRECTSOUND8) This->pDirectSound, &desc, &buffer, NULL); if (FAILED(hr)) { HeapFree(GetProcessHeap(), 0, default_path); *ppNewPath = NULL; return DSERR_BUFFERLOST; } default_path->pDSBuffer = buffer; /* Update description for creating primary buffer */ desc.dwFlags |= DSBCAPS_PRIMARYBUFFER; desc.dwBufferBytes = 0; desc.lpwfxFormat = NULL; hr = IDirectSound8_CreateSoundBuffer ((LPDIRECTSOUND8) This->pDirectSound, &desc, &buffer, NULL); if (FAILED(hr)) { IDirectSoundBuffer_Release(default_path->pDSBuffer); HeapFree(GetProcessHeap(), 0, default_path); *ppNewPath = NULL; return DSERR_BUFFERLOST; } default_path->pPrimary = buffer; *ppNewPath = pPath; TRACE(" returning IDirectMusicPerformance interface at %p.\n", *ppNewPath); return IDirectMusicAudioPath_Activate(*ppNewPath, fActivate); }
static b32 punp_win32_sound_init(void) { HRESULT hr; HMODULE dsound_lib; DirectSoundCreate8F DirectSoundCreate8; DSBUFFERDESC primary_buffer_description = {sizeof(primary_buffer_description)}; LPDIRECTSOUNDBUFFER primary_buffer; dsound_lib = LoadLibraryA("dsound.dll"); if (!dsound_lib) { printf("LoadLibrary(dsound.dll) failed.\n"); return 0; } DirectSoundCreate8 = (DirectSoundCreate8F)GetProcAddress(dsound_lib, "DirectSoundCreate8"); if (!DirectSoundCreate8) { printf("GetProcAddress(DirectSoundCreate8) failed.\n"); return 0; } hr = DirectSoundCreate8(0, &punp_win32_direct_sound, 0); if (hr != DS_OK) { printf("DirectSoundCreate failed.\n"); return 0; } hr = IDirectSound8_SetCooperativeLevel(punp_win32_direct_sound, punp_win32_window, DSSCL_PRIORITY); if (hr != DS_OK) { printf("punp_win32_direct_sound->SetCooperativeLevel failed.\n"); return 0; } primary_buffer_description.dwFlags = DSBCAPS_PRIMARYBUFFER; hr = IDirectSound8_CreateSoundBuffer(punp_win32_direct_sound, &primary_buffer_description, &primary_buffer, 0); if (hr != DS_OK) { printf("punp_win32_direct_sound->CreateSoundBuffer for primary buffer failed.\n"); return 0; } punp_win32_audio_format.wFormatTag = WAVE_FORMAT_PCM; punp_win32_audio_format.nChannels = PUNP_SOUND_CHANNELS; punp_win32_audio_format.nSamplesPerSec = SOUND_SAMPLE_RATE; punp_win32_audio_format.wBitsPerSample = 16; punp_win32_audio_format.nBlockAlign = (punp_win32_audio_format.nChannels * punp_win32_audio_format.wBitsPerSample) / 8; punp_win32_audio_format.nAvgBytesPerSec = punp_win32_audio_format.nSamplesPerSec * punp_win32_audio_format.nBlockAlign; punp_win32_audio_format.cbSize = 0; hr = IDirectSoundBuffer8_SetFormat(primary_buffer, &punp_win32_audio_format); if (hr != DS_OK) { printf("primary_buffer->SetFormat failed."); return 0; } // DSBSIZE_MIN DSBSIZE_MAX punp_win32_audio_buffer_description.dwSize = sizeof(punp_win32_audio_buffer_description); // 2 seconds. punp_win32_audio_buffer_description.dwBufferBytes = PUNP_SOUND_BUFFER_BYTES; punp_win32_audio_buffer_description.lpwfxFormat = &punp_win32_audio_format; // dicates that IDirectSoundBuffer::GetCurrentPosition should use the new behavior of the play cursor. // In DirectSound in DirectX 1, the play cursor was significantly ahead of the actual playing sound on // emulated sound cards; it was directly behind the write cursor. // Now, if the DSBCAPS_GETCURRENTPOSITION2 flag is specified, the application can get a more accurate // play position. If this flag is not specified, the old behavior is preserved for compatibility. // Note that this flag affects only emulated sound cards; if a DirectSound driver is present, the play // cursor is accurate for DirectSound in all versions of DirectX. punp_win32_audio_buffer_description.dwFlags = DSBCAPS_GETCURRENTPOSITION2; hr = IDirectSound8_CreateSoundBuffer(punp_win32_direct_sound, &punp_win32_audio_buffer_description, &punp_win32_audio_buffer, 0); if (hr != DS_OK) { printf("punp_win32_direct_sound->CreateSoundBuffer for secondary buffer failed.\n"); return 0; } // IDirectSoundBuffer8_SetFormat(punp_win32_audio_buffer, &punp_win32_audio_format); // Clear the initial buffer. { LPVOID region1, region2; DWORD region1_size, region2_size; hr = IDirectSoundBuffer8_Lock(punp_win32_audio_buffer, 0, punp_win32_audio_buffer_description.dwBufferBytes, (LPVOID *)®ion1, ®ion1_size, (LPVOID *)®ion2, ®ion2_size, DSBLOCK_ENTIREBUFFER); if (hr == DS_OK) { memset(region1, 0, region1_size); IDirectSoundBuffer8_Unlock(punp_win32_audio_buffer, region1, region1_size, region2, region2_size); } } hr = IDirectSoundBuffer8_Play(punp_win32_audio_buffer, 0, 0, DSBPLAY_LOOPING); if (hr != DS_OK) { ASSERT(0); } return 1; }
static HRESULT WINAPI IDirectSoundFullDuplexImpl_Initialize( LPDIRECTSOUNDFULLDUPLEX iface, LPCGUID pCaptureGuid, LPCGUID pRendererGuid, LPCDSCBUFFERDESC lpDscBufferDesc, LPCDSBUFFERDESC lpDsBufferDesc, HWND hWnd, DWORD dwLevel, LPLPDIRECTSOUNDCAPTUREBUFFER8 lplpDirectSoundCaptureBuffer8, LPLPDIRECTSOUNDBUFFER8 lplpDirectSoundBuffer8 ) { HRESULT hr; IDirectSoundFullDuplexImpl *This = (IDirectSoundFullDuplexImpl *)iface; TRACE("(%p,%s,%s,%p,%p,%p,%x,%p,%p)\n", This, debugstr_guid(pCaptureGuid), debugstr_guid(pRendererGuid), lpDscBufferDesc, lpDsBufferDesc, hWnd, dwLevel, lplpDirectSoundCaptureBuffer8, lplpDirectSoundBuffer8); if (This->renderer_device != NULL || This->capture_device != NULL) { WARN("already initialized\n"); *lplpDirectSoundCaptureBuffer8 = NULL; *lplpDirectSoundBuffer8 = NULL; return DSERR_ALREADYINITIALIZED; } hr = DSOUND_Create8(&IID_IDirectSound8, &This->renderer_device); if (SUCCEEDED(hr)) hr = IDirectSound_Initialize(This->renderer_device, pRendererGuid); if (hr != DS_OK) { WARN("DirectSoundDevice_Initialize() failed\n"); *lplpDirectSoundCaptureBuffer8 = NULL; *lplpDirectSoundBuffer8 = NULL; return hr; } IDirectSound8_SetCooperativeLevel(This->renderer_device, hWnd, dwLevel); hr = IDirectSound8_CreateSoundBuffer(This->renderer_device, lpDsBufferDesc, (IDirectSoundBuffer**)lplpDirectSoundBuffer8, NULL); if (hr != DS_OK) { WARN("IDirectSoundBufferImpl_Create() failed\n"); *lplpDirectSoundCaptureBuffer8 = NULL; *lplpDirectSoundBuffer8 = NULL; return hr; } hr = DSOUND_CaptureCreate8(&IID_IDirectSoundCapture8, &This->capture_device); if (SUCCEEDED(hr)) hr = IDirectSoundCapture_Initialize(This->capture_device, pCaptureGuid); if (hr != DS_OK) { WARN("DirectSoundCaptureDevice_Initialize() failed\n"); *lplpDirectSoundCaptureBuffer8 = NULL; *lplpDirectSoundBuffer8 = NULL; return hr; } hr = IDirectSoundCapture_CreateCaptureBuffer(This->capture_device, lpDscBufferDesc, (IDirectSoundCaptureBuffer**)lplpDirectSoundCaptureBuffer8, NULL); if (hr != DS_OK) { WARN("IDirectSoundCaptureBufferImpl_Create() failed\n"); *lplpDirectSoundCaptureBuffer8 = NULL; *lplpDirectSoundBuffer8 = NULL; return hr; } return hr; }
static HRESULT WINAPI IDirectSoundFullDuplexImpl_Initialize(IDirectSoundFullDuplex *iface, const GUID *capture_dev, const GUID *render_dev, const DSCBUFFERDESC *cbufdesc, const DSBUFFERDESC *bufdesc, HWND hwnd, DWORD level, IDirectSoundCaptureBuffer8 **dscb8, IDirectSoundBuffer8 **dsb8) { IDirectSoundFullDuplexImpl *This = impl_from_IDirectSoundFullDuplex(iface); IDirectSound8 *ds8 = NULL; IDirectSoundCapture8 *dsc8 = NULL; HRESULT hr; TRACE("(%p,%s,%s,%p,%p,%p,%x,%p,%p)\n", This, debugstr_guid(capture_dev), debugstr_guid(render_dev), cbufdesc, bufdesc, hwnd, level, dscb8, dsb8); if (!dscb8 || !dsb8) return E_INVALIDARG; *dscb8 = NULL; *dsb8 = NULL; if (This->ds8_unk || This->dsc8_unk) { WARN("already initialized\n"); return DSERR_ALREADYINITIALIZED; } hr = IDirectSoundImpl_Create(&This->IUnknown_iface, &IID_IUnknown, (void**)&This->ds8_unk, TRUE); if (SUCCEEDED(hr)) { IUnknown_QueryInterface(This->ds8_unk, &IID_IDirectSound8, (void**)&ds8); hr = IDirectSound8_Initialize(ds8, render_dev); } if (hr != DS_OK) { WARN("Creating/initializing IDirectSound8 failed\n"); goto error; } IDirectSound8_SetCooperativeLevel(ds8, hwnd, level); hr = IDirectSound8_CreateSoundBuffer(ds8, bufdesc, (IDirectSoundBuffer**)dsb8, NULL); if (hr != DS_OK) { WARN("IDirectSoundBuffer_Create() failed\n"); goto error; } hr = IDirectSoundCaptureImpl_Create(&This->IUnknown_iface, &IID_IUnknown, (void**)&This->dsc8_unk, TRUE); if (SUCCEEDED(hr)) { IUnknown_QueryInterface(This->dsc8_unk, &IID_IDirectSoundCapture8, (void**)&dsc8); hr = IDirectSoundCapture_Initialize(dsc8, capture_dev); } if (hr != DS_OK) { WARN("Creating/initializing IDirectSoundCapture8 failed\n"); goto error; } hr = IDirectSoundCapture_CreateCaptureBuffer(dsc8, cbufdesc, (IDirectSoundCaptureBuffer**)dscb8, NULL); if (hr != DS_OK) { WARN("IDirectSoundCapture_CreateCaptureBuffer() failed\n"); goto error; } IDirectSound8_Release(ds8); IDirectSoundCapture_Release(dsc8); return DS_OK; error: if (*dsb8) { IDirectSoundBuffer8_Release(*dsb8); *dsb8 = NULL; } if (ds8) IDirectSound8_Release(ds8); if (This->ds8_unk) { IUnknown_Release(This->ds8_unk); This->ds8_unk = NULL; } if (*dscb8) { IDirectSoundCaptureBuffer8_Release(*dscb8); *dscb8 = NULL; } if (dsc8) IDirectSoundCapture_Release(dsc8); if (This->dsc8_unk) { IUnknown_Release(This->dsc8_unk); This->dsc8_unk = NULL; } return hr; }
void SetupDSoundBuffers(void) { LPDIRECTSOUNDBUFFER lpdsb; DSBUFFERDESC dsPrimaryBuff, dsbdesc; WAVEFORMATEX wfm; HRESULT hr; int count; if (lpdsbuf) { CloseDLL(); InitiateAudio(AudioInfo);} if ( FAILED( hr = DirectSoundCreate( NULL, &lpds, NULL ) ) ) { return FALSE; } if ( FAILED( hr = IDirectSound8_SetCooperativeLevel(lpds, AudioInfo.hwnd, DSSCL_PRIORITY ))) { return FALSE; } for ( count = 0; count < NUMCAPTUREEVENTS; count++ ) { rghEvent[count] = CreateEvent( NULL, FALSE, FALSE, NULL ); if (rghEvent[count] == NULL ) { return FALSE; } } memset( &dsPrimaryBuff, 0, sizeof( DSBUFFERDESC ) ); dsPrimaryBuff.dwSize = sizeof( DSBUFFERDESC ); dsPrimaryBuff.dwFlags = DSBCAPS_PRIMARYBUFFER; dsPrimaryBuff.dwBufferBytes = 0; dsPrimaryBuff.lpwfxFormat = NULL; memset( &wfm, 0, sizeof( WAVEFORMATEX ) ); wfm.wFormatTag = WAVE_FORMAT_PCM; wfm.nChannels = 2; wfm.nSamplesPerSec = 44100; wfm.wBitsPerSample = 16; wfm.nBlockAlign = wfm.wBitsPerSample / 8 * wfm.nChannels; wfm.nAvgBytesPerSec = wfm.nSamplesPerSec * wfm.nBlockAlign; hr = IDirectSound8_CreateSoundBuffer(lpds,&dsPrimaryBuff, &lpdsb, NULL); if (SUCCEEDED ( hr ) ) { IDirectSoundBuffer8_SetFormat(lpdsb, &wfm ); IDirectSoundBuffer8_Play(lpdsb, 0, 0, DSBPLAY_LOOPING ); } wfm.nSamplesPerSec = Frequency; wfm.wBitsPerSample = 16; wfm.nBlockAlign = wfm.wBitsPerSample / 8 * wfm.nChannels; wfm.nAvgBytesPerSec = wfm.nSamplesPerSec * wfm.nBlockAlign; memset( &dsbdesc, 0, sizeof( DSBUFFERDESC ) ); dsbdesc.dwSize = sizeof( DSBUFFERDESC ); dsbdesc.dwFlags = DSBCAPS_GLOBALFOCUS | DSBCAPS_CTRLPOSITIONNOTIFY; dsbdesc.dwBufferBytes = BufferSize * 3; dsbdesc.lpwfxFormat = &wfm; if ( FAILED( hr = IDirectSound8_CreateSoundBuffer(lpds, &dsbdesc, &lpdsbuf, NULL ) ) ) { DisplayError("Failed in creation of Play buffer 1"); } FillBufferWithSilence( lpdsbuf ); rgdscbpn[0].dwOffset = ( BufferSize ) - 1; rgdscbpn[0].hEventNotify = rghEvent[0]; rgdscbpn[1].dwOffset = ( BufferSize * 2) - 1; rgdscbpn[1].hEventNotify = rghEvent[1]; rgdscbpn[2].dwOffset = ( BufferSize * 3) - 1; rgdscbpn[2].hEventNotify = rghEvent[2]; rgdscbpn[3].dwOffset = DSBPN_OFFSETSTOP; rgdscbpn[3].hEventNotify = rghEvent[3]; if ( FAILED( hr = IDirectSound8_QueryInterface(lpdsbuf, &IID_IDirectSoundNotify, ( VOID ** )&lpdsNotify ) ) ) { DisplayError("IDirectSound8_QueryInterface: Failed\n"); return; } // Set capture buffer notifications. if ( FAILED( hr = IDirectSoundNotify_SetNotificationPositions(lpdsNotify, NUMCAPTUREEVENTS, rgdscbpn ) ) ) { DisplayError("IDirectSoundNotify_SetNotificationPositions: Failed"); return; } //AddEffect(); }