Sign in to follow this  
sirlemonhead

DirectSound8

Recommended Posts

sirlemonhead    227
I've got some code here that uses plain old DirectSound I want to "update" it to DirectSound8, even though I think that'll offer me no improvements at all if i'm not going to be using effects and whatnot. My call to QueryInterface is failing when trying to create a LPDIRECTSOUND3DBUFFER8 buffer from a secondary buffer The original code was setting (DSBCAPS_CTRLVOLUME | DSBCAPS_CTRLPAN | DSBCAPS_CTRLFREQUENCY | DSBCAPS_STATIC) for each secondary buffer's description flags. It was then adding DSBCAPS_CTRL3D if 3D buffers were required, but it wasn't removing the pan flag. This apparently isn't allowed on DSound8 - you cant mix DSBCAPS_CTRL3D and DSBCAPS_CTRLPAN So I simply get the code to remove the flag for panning Something like
if(3d)
{
	dsBuffDesc.dwFlags |= DSBCAPS_CTRL3D;
}
else
{
	dsBuffDesc.dwFlags |= DSBCAPS_CTRLPAN;
}


the buffer creates fine, gets locked and populated with wav data then unlocked, just as before in code that works fine. The trouble starts when It tries to play sounds. First, it needs to call DuplicateSoundBuffer. I think I heard that this shouldn't be used anymore..Can anyone confirm that? Anyway, the call works ok. I've got the Dsound debug output going and i'm checking my HRESULTS with the FAILED macro We then need to create the 3d buffer from the "plain" buffer, so the code uses query interface on the plain buffer, passing in the 3d buffer eh PlainBuffer->QueryInterface(IID_IDirectSound3DBuffer8, (void**)3DBuffer); I haven't created 3DBuffer yet at this point - which I assume is normal QueryInterface fails. The debug output spits out DSOUND: Error: Invalid interface buffer. I have no idea where this comes. I have OutputDebugStrings for ever dsound function call and nothing fails before this appears. The HRESULT for the call, when used with DXGetErrorString9 and DXGetErrorDescription9, gives "E_INVALIDARG An invalid parameter was passed to the returning function" How do I find out what parameter it's talking about? what returning function does it mean? does a 3D buffer have to be created at this point?

Share this post


Link to post
Share on other sites
sirlemonhead    227
erm i'm terribly at the terminology :D

It'd be a pointer to IDirectSoundBuffer..

both are

LPDIRECTSOUNDBUFFER dsBufferP;
LPDIRECTSOUND3DBUFFER8 ds3DBufferP;

I wasn't querying for a DSound8 buffer, just querying for a LPDIRECTSOUND3DBUFFER8 from a LPDIRECTSOUNDBUFFER

(I had actually previously tried querying a LPDIRECTSOUND3DBUFFER from a
LPDIRECTSOUNDBUFFER, but this gave the same problem)

I'll do it the way you suggested and see what happens.

Should I still be using the DuplicateBuffer function? I read something on here I think about it being unreliable on modern machies - something about the memory addresses possibly NOT being the same? :\

Share this post


Link to post
Share on other sites
sirlemonhead    227
Ah I see what you were maybe getting at..

I have to pass the buffers into the QueryInterface function by reference. It compiles find either way.

I don't much like those QueryInterface functions :\

Share this post


Link to post
Share on other sites
Mike.Popoloski    3258
No no, it has nothing to do with how you're passing your parameters. This is how your code path should look:


IDirectSound8 *dsound;
IDirectSoundBuffer *baseBuffer;
IDirectSoundBuffer8 *newBuffer;
IDirectSound3DBuffer8 *buffer3D;

dsound->CreateSoundBuffer(&baseBuffer);
baseBuffer->QueryInterface(IID_IDirectSoundBuffer8, &newBuffer);
newBuffer->QueryInterface(IID_IDirect3DSoundBuffer8, &buffer3D);

// now you have the 3D buffer
buffer3D->DoBlah();

Share this post


Link to post
Share on other sites
sirlemonhead    227
I had:

baseBuffer->QueryInterface(IID_IDirectSoundBuffer8, newBuffer);
newBuffer->QueryInterface(IID_IDirect3DSoundBuffer8, buffer3D);

instead, which was causing the problem. Seems to work without error now, only the sound doesn't quite play properly. I'll look into that.

Cheers for the help :)

Share this post


Link to post
Share on other sites
sirlemonhead    227
What would you recommend as the best way to replace the DuplicateSoundBuffer function?

I'm doing this currently, and it seems to work ok..

soundToCopyTo = soundToCopyFrom;
soundToCopyFrom->AddRef();

Is there a better way to do this? I only ask because the Xbox doesn't have the DuplicateSoundBuffer function, so I need an alternative to that anyway

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this