#include "pch.hpp"
//===========================================================================//
// File:	 DirectSound.cpp												 //
// Project:  GameOS					                                         //
// Contents: Interface to DirectSound									     //
//---------------------------------------------------------------------------//
// Date      Who    Modification                                             //
// 01/21/98  AG     Created													 //
//---------------------------------------------------------------------------//
// Copyright (C) 1999 Microsoft Corp.						                 //
// All Rights reserved worldwide                                             //
// This unpublished sourcecode is PROPRIETARY and CONFIDENTIAL               //
//===========================================================================//
#include "ErrorHandler.hpp"
#include "DirectXDebugging.hpp"
#include "Windows.hpp"


HRESULT wDirectSoundEnumerate(LPDSENUMCALLBACK cb, void* vp)
{
	SPEW(( GROUP_DIRECTSOUND, "DirectSoundEnumerate()" ));

	HRESULT result = _DirectSoundEnumerate(cb, vp);

	if ( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - DirectSoundEnumerate()", result, ErrorNumberToMessage(result) ));

	return result;
}

HRESULT wLock( IDirectSoundBuffer* lpdsb, DWORD dwWriteCursor, DWORD dwWriteBytes, void** lplpvAudioPtr1, LPDWORD lpdwAudioBytes1, void** lplpvAudioPtr2, LPDWORD lpdwAudioBytes2, DWORD dwFlags )
{
	SPEW(( GROUP_DIRECTSOUND, "Lock(0x%x: 0x%x,0x%x,0x%x,0x%x,0x%x,0x%x,0x%x)",(int)lpdsb, (int)dwWriteCursor,(int)dwWriteBytes,(int)lplpvAudioPtr1,(int)lpdwAudioBytes1,(int)lplpvAudioPtr2,(int)lpdwAudioBytes2,(int)dwFlags ));

	HRESULT result=lpdsb->Lock( dwWriteCursor, dwWriteBytes, lplpvAudioPtr1, lpdwAudioBytes1, lplpvAudioPtr2, lpdwAudioBytes2, dwFlags );

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - Lock(0x%x: 0x%x,0x%x,0x%x,0x%x,0x%x,0x%x,0x%x)",result,ErrorNumberToMessage(result),(int)lpdsb, (int)dwWriteCursor,(int)dwWriteBytes,(int)lplpvAudioPtr1,(int)lpdwAudioBytes1,(int)lplpvAudioPtr2,(int)lpdwAudioBytes2,(int)dwFlags ));

	return result;
}

HRESULT wUnlock( IDirectSoundBuffer* lpdsb, void* lplpvAudioPtr1, DWORD lpdwAudioBytes1, void* lplpvAudioPtr2, DWORD lpdwAudioBytes2)
{
	SPEW(( GROUP_DIRECTSOUND, "Unlock(0x%x: 0x%x,0x%x,0x%x,0x%x)",(int)lpdsb, (int)lplpvAudioPtr1,(int)lpdwAudioBytes1,(int)lplpvAudioPtr2,(int)lpdwAudioBytes2));

	HRESULT result=lpdsb->Unlock( lplpvAudioPtr1, (unsigned long)lpdwAudioBytes1, lplpvAudioPtr2, (unsigned long)lpdwAudioBytes2);

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - Unlock(0x%x: 0x%x,0x%x,0x%x,0x%x)",result,ErrorNumberToMessage(result),(int)lpdsb, (int)lplpvAudioPtr1,(int)lpdwAudioBytes1,(int)lplpvAudioPtr2,(int)lpdwAudioBytes2));

	return result;
}

HRESULT wGetVolume(IDirectSoundBuffer* lpdsb, LONG* vol )
{
	SPEW(( GROUP_DIRECTSOUND, "GetVolume(0x%x) +",(int)lpdsb ));

	HRESULT result=lpdsb->GetVolume( vol);

	SPEW(( GROUP_DIRECTSOUND, " -%d",*vol ));

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - GetVolume(0x%x)",result,ErrorNumberToMessage(result),(int)lpdsb ));

	return result;
}

HRESULT wGetFrequency(IDirectSoundBuffer* lpdsb, DWORD* freq )
{
	SPEW(( GROUP_DIRECTSOUND, "GetFrequency(0x%x) +",(int)lpdsb));

	HRESULT result=lpdsb->GetFrequency(freq);

	SPEW(( GROUP_DIRECTSOUND, " -%d",*freq ));

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - GetFrequency(0x%x)",result,ErrorNumberToMessage(result),(int)lpdsb ));

	return result;
}

HRESULT wGetPan(IDirectSoundBuffer* lpdsb, LONG* pan )
{
	SPEW(( GROUP_DIRECTSOUND, "GetPan(0x%x) +", (int)lpdsb ));

	HRESULT result=lpdsb->GetPan( pan );

	SPEW(( GROUP_DIRECTSOUND, " -%d",*pan ));

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - GetPan(0x%x)",result,ErrorNumberToMessage(result),(int)lpdsb ));

	return result;
}

HRESULT wSetVolume(IDirectSoundBuffer* lpdsb, LONG vol)
{
	SPEW(( GROUP_DIRECTSOUND, "SetVolume(0x%x: %d)", (int)lpdsb, vol ));

	HRESULT result=lpdsb->SetVolume( vol );

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - SetVolume(0x%x: %d)", result, ErrorNumberToMessage(result), (int)lpdsb, vol ));

	return result;
}

HRESULT wSetFrequency(IDirectSoundBuffer* lpdsb, DWORD freq)
{
	SPEW(( GROUP_DIRECTSOUND, "SetFrequency(0x%x: %d)",(int)lpdsb, freq));

	HRESULT result=lpdsb->SetFrequency(freq);

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - SetFrequency(0x%x: %d)",result,ErrorNumberToMessage(result),(int)lpdsb, freq ));

	return result;
}

HRESULT wSetPan(IDirectSoundBuffer* lpdsb, LONG pan)
{
	SPEW(( GROUP_DIRECTSOUND, "SetPan(0x%x: %d)",(int)lpdsb,pan));

	HRESULT result=lpdsb->SetPan(pan);

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - SetPan(0x%x: %d)",result,ErrorNumberToMessage(result),(int)lpdsb, pan ));

	return result;
}

HRESULT wStop(IDirectSoundBuffer* lpdsb)
{
	SPEW(( GROUP_DIRECTSOUND, "Stop(0x%x)", (int)lpdsb ));

	HRESULT result=lpdsb->Stop();

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - Stop(0x%x)",result,ErrorNumberToMessage(result), (int)lpdsb ));

	return result;
}

HRESULT wGetStatus(IDirectSoundBuffer* lpdsb, LPDWORD status)
{
	SPEW(( GROUP_DIRECTSOUND, "GetStatus(0x%x)+", (int)lpdsb));

	HRESULT result=lpdsb->GetStatus(status);

	SPEW(( GROUP_DIRECTSOUND, " - %s", GetSBStatus(*status) ));

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - GetStatus(0x%x)",result,ErrorNumberToMessage(result), (int)lpdsb));

	return result;
}

HRESULT wSetCurrentPosition(IDirectSoundBuffer* lpdsb, DWORD pos)
{
	SPEW(( GROUP_DIRECTSOUND, "SetCurrentPosition(0x%x: %d)", (int)lpdsb, pos));

	HRESULT result=lpdsb->SetCurrentPosition(pos);

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - SetCurrentPosition(0x%x: %d)",result,ErrorNumberToMessage(result), (int)lpdsb, pos));

	return result;
}

HRESULT wGetCurrentPosition(IDirectSoundBuffer* lpdsb, LPDWORD lpdwCurrentPlayCursor, LPDWORD lpdwCurrentWriteCursor)
{
	SPEW(( GROUP_DIRECTSOUND, "GetCurrentPosition(0x%x)+", (int)lpdsb));

	HRESULT result=lpdsb->GetCurrentPosition(lpdwCurrentPlayCursor, lpdwCurrentWriteCursor);

	SPEW(( GROUP_DIRECTSOUND, " -0x%x, 0x%x", (lpdwCurrentPlayCursor ? (int)*lpdwCurrentPlayCursor : 0), (lpdwCurrentWriteCursor ? (int)*lpdwCurrentWriteCursor : 0) ));

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - GetCurrentPosition(0x%x)",result,ErrorNumberToMessage(result),(int)lpdsb ));

	return result;
}

HRESULT wCreateSoundBuffer(IDirectSound* lpds, LPCDSBUFFERDESC lpcDSBufferDesc, LPLPDIRECTSOUNDBUFFER lplpDirectSoundBuffer, IUnknown* pUnkOuter)
{
	char Buffer[128];
	SPEW(( GROUP_DIRECTSOUND, "CreateSoundBuffer(0x%x: %s, %s)+", (int)lpds, GetDSBDFlags(lpcDSBufferDesc->dwFlags), GetWaveFormat(Buffer,lpcDSBufferDesc->lpwfxFormat) ));

	HRESULT result=lpds->CreateSoundBuffer(lpcDSBufferDesc, lplpDirectSoundBuffer, pUnkOuter);

	SPEW(( GROUP_DIRECTSOUND, " - 0x%x",(int)*lplpDirectSoundBuffer ));

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - CreateSoundBuffer(0x%x: %s, %s)",result,ErrorNumberToMessage(result), (int)lpds, GetDSBDFlags(lpcDSBufferDesc->dwFlags),  GetWaveFormat(Buffer,lpcDSBufferDesc->lpwfxFormat) ));

	return result;
}

HRESULT wGetCaps( LPDIRECTSOUND ppDS, DSCAPS* dsc )
{
	SPEW(( GROUP_DIRECTSOUND, "GetCaps(0x%x)",(int)ppDS ));

	HRESULT result=ppDS->GetCaps( dsc );

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - GetCaps(0x%x)",result,ErrorNumberToMessage(result),(int)ppDS ));

	return result;
}
//
// Altered to use COM
//
HRESULT wDirectSoundCreate( LPGUID lpGuid, LPDIRECTSOUND* ppDS, IUnknown* pUnkOuter )
{
	SPEW(( GROUP_DIRECTSOUND, "DirectSoundCreate(0x%x)+",(int)lpGuid));

	HRESULT result=_DirectSoundCreate( lpGuid, ppDS, pUnkOuter );

	SPEW(( GROUP_DIRECTSOUND, " -0x%x",(int)*ppDS));

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - DirectSoundCreate(0x%x)",result,ErrorNumberToMessage(result),(int)lpGuid));

	return result;
}

HRESULT wSetCooperativeLevel(IDirectSound* lpds, HWND hwnd, DWORD dwLevel )
{
	SPEW(( GROUP_DIRECTSOUND, "SetCooperativeLevel(0x%x: 0x%x, %s)", (int)lpds, hwnd, GetDSoundCoopLevel(dwLevel) ));

	HRESULT result=lpds->SetCooperativeLevel(hwnd,dwLevel);

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - SetCooperativeLevel(0x%x: 0x%x, %s)", (int)lpds, hwnd, GetDSoundCoopLevel(dwLevel) ));

	return result;
}

HRESULT wSetFormat( IDirectSoundBuffer* lpdsb, LPCWAVEFORMATEX lpcfxFormat )
{
	char Buffer[128];
	SPEW(( GROUP_DIRECTSOUND, "SetFormat(0x%x: %s)", (int)lpdsb, GetWaveFormat(Buffer,lpcfxFormat) ));

	HRESULT result=lpdsb->SetFormat(lpcfxFormat);

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - SetFormat(0x%x: %s)",result,ErrorNumberToMessage(result), (int)lpdsb, GetWaveFormat(Buffer,lpcfxFormat) ));

	return result;
}

HRESULT wPlay( IDirectSoundBuffer* lpdsb, DWORD dwReserved1, DWORD dwPriority, DWORD dwFlags )
{
	SPEW(( GROUP_DIRECTSOUND, "Play(0x%x: %s)", (int)lpdsb,(dwFlags&DSBPLAY_LOOPING ? "Looping" : "Not Looping") ));

	HRESULT result=lpdsb->Play(dwReserved1,dwPriority,dwFlags);

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - Play(0x%x: %s)",result,ErrorNumberToMessage(result),(int)lpdsb,(dwFlags&DSBPLAY_LOOPING ? "Looping" : "Not Looping") ));

	return result;
}

HRESULT wGetCaps( LPDIRECTSOUNDBUFFER ppDSB, DSBCAPS * dsbc )
{
	SPEW(( GROUP_DIRECTSOUND, "GetCaps(0x%x)+", (int)ppDSB ));

	HRESULT result=ppDSB->GetCaps( dsbc );

	SPEW(( GROUP_DIRECTSOUND, " - %s", GetDSBDFlags(dsbc->dwFlags) ));

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - GetCaps(0x%x)",result,ErrorNumberToMessage(result), (int)ppDSB ));

	return result;
}

HRESULT wSetDistanceFactor(IDirectSound3DListener* lpdsb, float dist, DWORD flag)
{
	SPEW(( GROUP_DIRECTSOUND, "SetDistanceFactor(0x%x: %f %s)",(int)lpdsb, dist, GetApplyFlag(flag) ));

	HRESULT result=lpdsb->SetDistanceFactor(dist, flag);

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - SetDistanceFactorPan(0x%x: %f %s)", result, ErrorNumberToMessage(result), (int)lpdsb, dist, GetApplyFlag(flag) ));

	return result;
}

HRESULT wSetDopplerFactor(IDirectSound3DListener* lpdsb, float dist, DWORD flag)
{
	SPEW(( GROUP_DIRECTSOUND, "wSetDopplerFactor(0x%x: %f %s)",(int)lpdsb, dist, GetApplyFlag(flag) ));

	HRESULT result=lpdsb->SetDopplerFactor(dist, flag);

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - wSetDopplerFactor(0x%x: %f %s)", result, ErrorNumberToMessage(result),(int)lpdsb, dist, GetApplyFlag(flag) ));

	return result;
}


HRESULT wSetRolloffFactor(IDirectSound3DListener* lpdsb, float dist, DWORD flag)
{
	SPEW(( GROUP_DIRECTSOUND, "SetRolloffFactor(0x%x: %f %s)",(int)lpdsb, dist, GetApplyFlag(flag) ));

	HRESULT result=lpdsb->SetRolloffFactor(dist, flag);

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - SetRolloffFactor(0x%x: %f %s)", result, ErrorNumberToMessage(result),(int)lpdsb, dist, GetApplyFlag(flag)));

	return result;
}

HRESULT wSetOrientation(IDirectSound3DListener* lpdsb, float fx, float fy, float fz, float tx, float ty, float tz, DWORD flag)
{
	SPEW(( GROUP_DIRECTSOUND, "SetOrientation(0x%x: Front=%f,%f,%f Top=%f,%f,%f %s)", (int)lpdsb, fx, fy, fz, tx, ty, tz, GetApplyFlag(flag) ));

	HRESULT result=lpdsb->SetOrientation( fx, fy, fz, tx, ty, tz, flag );

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - SetOrientation(0x%x: Front=%f,%f,%f Top=%f,%f,%f %s)", result, ErrorNumberToMessage(result), (int)lpdsb, fx, fy, fz, tx, ty, tz, GetApplyFlag(flag) ));

	return result;
}

HRESULT wSetPosition(IDirectSound3DBuffer* lpdsb, float x, float y, float z, DWORD flag)
{
	SPEW(( GROUP_DIRECTSOUND, "SetPosition(0x%x: x=%f y=%f z=%f %s)",(int)lpdsb, x, y, z, GetApplyFlag(flag) ));

	HRESULT result=lpdsb->SetPosition( x, y, z, flag );

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - SetPosition(0x%x: x=%f y=%f z=%f %s)", result, ErrorNumberToMessage(result),(int)lpdsb, x, y, z, GetApplyFlag(flag) ));

	return result;
}

HRESULT wSetPosition(IDirectSound3DListener* lpdsb, float x, float y, float z, DWORD flag)
{
	SPEW(( GROUP_DIRECTSOUND, "SetPosition(0x%x: x=%f y=%f z=%f %s)",(int)lpdsb, x, y, z, GetApplyFlag(flag) ));

	HRESULT result=lpdsb->SetPosition( x, y, z, flag );

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - wSetPosition(0x%x: x=%f y=%f z=%f %s)", result, ErrorNumberToMessage(result),(int)lpdsb, x, y, z, GetApplyFlag(flag) ));

	return result;
}

HRESULT wSetVelocity(IDirectSound3DBuffer* lpdsb, float x, float y, float z, DWORD flag)
{
	SPEW(( GROUP_DIRECTSOUND, "SetVelocity(0x%x: x=%f y=%f z=%f %s)",(int)lpdsb, x, y, z, GetApplyFlag(flag) ));

	HRESULT result=lpdsb->SetVelocity( x, y, z, flag );

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - SetVelocity(0x%x: x=%f y=%f z=%f %s)", result, ErrorNumberToMessage(result),(int)lpdsb, x, y, z, GetApplyFlag(flag) ));

	return result;
}

HRESULT wSetVelocity(IDirectSound3DListener* lpdsb, float x, float y, float z, DWORD flag)
{
	SPEW(( GROUP_DIRECTSOUND, "SetVelocity(0x%x: %f, %d)",(int)lpdsb, x, y, z, flag ));

	HRESULT result=lpdsb->SetVelocity( x, y, z, flag );

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - SetVelocity(0x%x: %f, %f, %f, %d)", result, ErrorNumberToMessage(result),(int)lpdsb, x, y, z, flag ));

	return result;
}

HRESULT wSetMinDistance(IDirectSound3DBuffer* lpdsb, float x, DWORD flag)
{
	SPEW(( GROUP_DIRECTSOUND, "SetMinDistance(0x%x: %f %s)",(int)lpdsb, x, GetApplyFlag(flag) ));

	HRESULT result=lpdsb->SetMinDistance( x, flag );

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - SetMinDistance(0x%x: %f %s)", result, ErrorNumberToMessage(result),(int)lpdsb, x, GetApplyFlag(flag) ));

	return result;
}

HRESULT wSetMaxDistance(IDirectSound3DBuffer* lpdsb, float x, DWORD flag)
{
	SPEW(( GROUP_DIRECTSOUND, "SetMaxDistance(0x%x: %f, %s)", (int)lpdsb, x, GetApplyFlag(flag) ));

	HRESULT result=lpdsb->SetMaxDistance(x, flag);

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - SetMaxDistance(0x%x: %f %s)", result, ErrorNumberToMessage(result),(int)lpdsb, x, GetApplyFlag(flag) ));

	return result;
}

HRESULT	wSetSpeakerConfig( LPDIRECTSOUND ppDS, DWORD dsflags )
{
	SPEW(( GROUP_DIRECTSOUND, "SetSpeakerConfig(0x%x: %s)", (int)ppDS, GetDSSpeakerConfig(dsflags) ));

	HRESULT result=ppDS->SetSpeakerConfig( dsflags );

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - SetSpeakerConfig(0x%x: %s)", result, ErrorNumberToMessage(result), (int)ppDS, GetDSSpeakerConfig(dsflags) ));

	return result;
}

HRESULT	wGetSpeakerConfig( LPDIRECTSOUND ppDS, DWORD *dsflags )
{
	SPEW(( GROUP_DIRECTSOUND, "GetSpeakerConfig(0x%x: 0x%x)", (int)ppDS, dsflags ));

	HRESULT result=ppDS->GetSpeakerConfig( dsflags );

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - GetSpeakerConfig(0x%x: 0x%x)", result, ErrorNumberToMessage(result), (int)ppDS, dsflags ));

	return result;
}

HRESULT	wSetConeAngles( LPDIRECTSOUND3DBUFFER ppDSB3D, DWORD min, DWORD max, DWORD flag )
{
	SPEW(( GROUP_DIRECTSOUND, "SetConeAngles(0x%x: Min=%f Max=%f %s)", (int)ppDSB3D, min, max, GetApplyFlag(flag) ));

	HRESULT result=ppDSB3D->SetConeAngles( min, max, flag );

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - SetConeAngles(0x%x: Min=%f Max=%f %s)", result, ErrorNumberToMessage(result), (int)ppDSB3D, min, max, GetApplyFlag(flag) ));

	return result;
}

HRESULT	wSetConeOrientation( LPDIRECTSOUND3DBUFFER ppDSB3D, float x, float y, float z, DWORD flag )
{
	SPEW(( GROUP_DIRECTSOUND, "SetConeOrientation(0x%x: x=%f y=%f z=%f %s)", (int)ppDSB3D, x, y, z, GetApplyFlag(flag) ));

	HRESULT result=ppDSB3D->SetConeOrientation( x, y, z, flag );

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - SetConeOrientation(0x%x: x=%f y=%f z=%f %s)", result, ErrorNumberToMessage(result), (int)ppDSB3D, x, y, z, GetApplyFlag(flag)  ));

	return result;
}

HRESULT wCommitDeferredSettings( LPDIRECTSOUND3DLISTENER lpList )
{
	SPEW(( GROUP_DIRECTSOUND, "CommitDeferredSettings(0x%x)",(int)lpList ));

	HRESULT result=lpList->CommitDeferredSettings();

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - CommitDeferredSettings(0x%x)", result, ErrorNumberToMessage(result),(int)lpList ));

	return result;
}

HRESULT wQuerySupport( LPKSPROPERTYSET lpPS, REFGUID rGUID, ULONG uLong, ULONG* support )
{
	SPEW(( GROUP_DIRECTSOUND, "QuerySupport(0x%x: %s, %s)+",(int)lpPS, GetPropertySet(rGUID),GetPropertyItem(rGUID,uLong) ));

	HRESULT result=lpPS->QuerySupport(rGUID, uLong, support);

	SPEW(( GROUP_DIRECTSOUND, " - %s",GetQSupport(*support) ));

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - QuerySupport(0x%x: %s, %s)", result, ErrorNumberToMessage(result),(int)lpPS, GetPropertySet(rGUID),GetPropertyItem(rGUID,uLong) ));

	return result;
}

HRESULT wSet( LPKSPROPERTYSET lpPS, REFGUID rguidPropSet, ULONG ulId, LPVOID pInstanceData, ULONG ulInstanceLength, LPVOID pPropertyData, ULONG ulDataLength )
{
	SPEW(( GROUP_DIRECTSOUND, "Set(0x%x: %s, %s)",(int)lpPS, GetPropertySet(rguidPropSet),GetPropertyItem(rguidPropSet,ulId) ));

	HRESULT result=lpPS->Set(rguidPropSet,ulId,pInstanceData,ulInstanceLength,pPropertyData,ulDataLength);

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - Set(0x%x: %s, %s)", result, ErrorNumberToMessage(result),(int)lpPS, GetPropertySet(rguidPropSet),GetPropertyItem(rguidPropSet,ulId) ));

	return result;
}

HRESULT wGetFormat( LPDIRECTSOUNDBUFFER lpdsb, LPWAVEFORMATEX lpwf, DWORD sizeIn, DWORD *sizeOut )
{
	SPEW(( GROUP_DIRECTSOUND, "GetFormat(0x%x)+", (int)lpdsb ));

	HRESULT result=lpdsb->GetFormat(lpwf,sizeIn,sizeOut);

	char Buffer[128];
	GetWaveFormat( Buffer, lpwf );

	SPEW(( GROUP_DIRECTSOUND, " -", Buffer ));

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - GetFormat(0x%x)", result, ErrorNumberToMessage(result), (int)lpdsb ));

	return result;
}

HRESULT wSetAllParameters(IDirectSound3DBuffer* lpdsb, DS3DBUFFER* ds3d, DWORD flag)
{
	SPEW(( GROUP_DIRECTSOUND, "SetAllParameters(0x%x: 0x%x, %s)", (int)lpdsb, ds3d, GetApplyFlag(flag) ));

	HRESULT result=lpdsb->SetAllParameters( ds3d, flag );

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - SetAllPameteres(0x%x: 0x%x, %s)", result, ErrorNumberToMessage(result), (int)lpdsb, ds3d, GetApplyFlag(flag) ));

	return result;
}

HRESULT wSetAllParameters(IDirectSound3DListener* lpdsb, DS3DLISTENER* ds3d, DWORD flag)
{
	SPEW(( GROUP_DIRECTSOUND, "SetAllParameters(0x%x: 0x%x, %s)", (int)lpdsb, ds3d, GetApplyFlag(flag) ));

	HRESULT result=lpdsb->SetAllParameters( ds3d, flag );

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - SetAllPameteres(0x%x: 0x%x, %s)", result, ErrorNumberToMessage(result), (int)lpdsb, ds3d, GetApplyFlag(flag) ));

	return result;
}

HRESULT wDuplicateSoundBuffer(IDirectSound* lpds, LPDIRECTSOUNDBUFFER src, LPDIRECTSOUNDBUFFER * dst )
{
	SPEW(( GROUP_DIRECTSOUND, "DuplicateSoundBuffer(0x%x: 0x%x)+", (int)lpds, src ));

	HRESULT result=lpds->DuplicateSoundBuffer(src,dst);

	SPEW(( GROUP_DIRECTSOUND, " -0x%x", (int)*dst ));

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - DuplicateSoundBuffer(0x%x: 0x%x)", (int)lpds, src ));

	return result;
}

