View Full Version : Trouble compiling my DSound app
Onikhaosifix
08-25-2005, 09:27 PM
Hello,
Earlier today I decided to take a crack at DirectX Audio, more specifically, DirectSound. Some very low level stuff but I figured after I read some documentation on it carefully I could get it up and running in no time. However, this isn't the case for me here.
I get tons of compiling errors and most of them are in dsound.h so I figured it isn't me. The type of errors I get include syntax, missing-storage type(LPCWAVEFORMATEX), and all that jazz.
At first, I suspected it had something to do with defining INITGUID but I already did that weeks ago because I was using DirectX Input8. So I tried the alternative by linking to dxguid.lib and the errors are still there.
It's strange how Direct3D doesn't need this crap. Also, it's weird how the object creation function in DirectSound is DirectSoundCreate8 and in DirectInput it's DirectInput8Create. You would think that the naming conventions between the APIs were consistent. I guess the API designers....aren't good API designers :)
bladder
08-25-2005, 10:27 PM
Try including windows.h before dsound.h. IIRC that was the fix to this problem.
Onikhaosifix
08-26-2005, 10:24 AM
Nevermind, I forgot to define DIRECTSOUND_VERSION. It compiles fine now. I'm having some more trouble now with setting the playback format of the primary sound buffer. Here is my code snippet.
VOID framework::InitDSound( DWORD dwLevel, WORD nChannels, WORD nBitsPerSample, WORD nFrequency )
{
if( FAILED(DirectSoundCreate8( NULL, &_pDS, NULL )) )
*_pELog << "Unable to create DSound object.";
if( FAILED(_pDS->SetCooperativeLevel( _pW->GetHandle(), dwLevel )) )
*_pELog << "Unable to set cooperative of this application for the sound device.";
DSBUFFERDESC dbd;
ZeroMemory( &dbd, sizeof(DSBUFFERDESC) );
dbd.dwSize = sizeof(DSBUFFERDESC);
dbd.dwFlags = DSBCAPS_PRIMARYBUFFER | DSBCAPS_CTRLVOLUME;
dbd.dwBufferBytes = 0;
dbd.lpwfxFormat = NULL;
if( FAILED(_pDS->CreateSoundBuffer( &dbd, &_pDSPrimary, NULL )) )
*_pELog << "Unable to create primary sound buffer.";
WAVEFORMATEX wf;
ZeroMemory( &wf, sizeof(WAVEFORMATEX) );
wf.wFormatTag = WAVE_FORMAT_PCM;
wf.nChannels = nChannels;
wf.nSamplesPerSec = nFrequency;
wf.nAvgBytesPerSec = nFrequency * (nChannels * nBitsPerSample); // samples per second * block alignment.
wf.nBlockAlign = 4 /*nChannels * nBitsPerSample / 8*/; // # of channels * bits per sample / 8.
wf.wBitsPerSample = nBitsPerSample;
if( FAILED(_pDSPrimary->SetFormat( &wf )) )
*_pELog << "Unable to set playback format of primary sound buffer.";
}
////////////////////////////////////////////////////////////////////////////////////////////////
'_pELog' is of type LPLOGERROR which is my error log class. Anyways, the last if statement in that function is true which isn't good. Am I doing something wrong with setting up the WAVEFORMATEX structure?
bignobody
08-29-2005, 11:48 AM
I had a look through my own DSound code, and it seems I never set the format for any sound buffer directly (meaning it gets it from the lpwfxFormat parameter of the DSBUFFERDESC struct that gets passed in on Initialize).
The first thing to try is to determine what error code is being reported (don't just hand the result of the function to the FAILED macro. Assign the method's return value to a variable so you can find out what's gone wrong).
One possibility from the the SDK documentation:
Since primary sound buffers do not support the IDirectSoundBuffer8 interface, this method must be called on IDirectSoundBuffer.
Other than that, do you really need to do this? Another nugget from the docs:
When you obtain write access to the primary buffer, other DirectSound features become unavailable. Secondary buffers are not mixed, so hardware-accelerated mixing is unavailable.
Most applications should use secondary buffers instead of directly accessing the primary buffer.
That's all I can offer at the moment. Good luck!
-bignobody
Onikhaosifix
08-31-2005, 09:08 PM
Ah thanks I already solved the problem ages ago.
vBulletin, Copyright ©2000-2009, Jelsoft Enterprises Ltd.