CreateSoundBuffer returning DSERR_INVALIDPARAM

878aef26c9c578084c44642e137f001f
0
kooper 101 May 20, 2009 at 10:47

Im making a simple 2D game for a university project and when I try to create a sound buffer its returning the error DSERR_INVALIDPARAM and I cant figure out why. I know direct sound is pretty much dead but its what we were told to use so I have to stick with it. Any help would be greatly appreciated.

void Sound::InitializeSound(HWND hWnd)
{

    HRESULT snd = DirectSoundCreate8(NULL, &d3dSound, NULL);

    if (FAILED(snd))
        MessageBox(NULL, "failed to create sound device", "FAIL!", MB_ICONEXCLAMATION | MB_OK);

    HRESULT spr = d3dSound->SetCooperativeLevel(hWnd, DSSCL_NORMAL);

    if (FAILED(spr))
        MessageBox(NULL, "failed to set sound priority", "FAIL!", MB_ICONEXCLAMATION | MB_OK);


    WAVEFORMATEX wfx;
    memset(&wfx, 0, sizeof(WAVEFORMATEX)); 
    wfx.wFormatTag = WAVE_FORMAT_PCM; 
    wfx.nChannels = dwPrimaryChannels; 
    wfx.nSamplesPerSec = dwPrimaryFreq; 
    wfx.wBitsPerSample = dwPrimaryBitRate;
    wfx.nBlockAlign = (wfx.wBitsPerSample / 8 * wfx.nChannels);
    wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign; 


    LPDIRECTSOUNDBUFFER pDSBPrimary = NULL;
    DSBUFFERDESC dsbd;
    memset( &dsbd, 0, sizeof(DSBUFFERDESC) );
    dsbd.dwSize        = sizeof(DSBUFFERDESC);
    dsbd.dwFlags = DSBCAPS_CTRLPAN | DSBCAPS_CTRLVOLUME | DSBCAPS_CTRLFREQUENCY | DSBCAPS_PRIMARYBUFFER; 
    dsbd.dwBufferBytes = 0;
    dsbd.lpwfxFormat   = &wfx;
    

    HRESULT csb = d3dSound->CreateSoundBuffer( &dsbd, &pDSBPrimary, NULL );
    if (FAILED(csb))
        MessageBox(NULL, "failed to create sound buffer", "FAIL!", MB_ICONEXCLAMATION | MB_OK);

    if(pDSBPrimary)
        pDSBPrimary->Release();
}

thanks in advance for any help you can give

1 Reply

Please log in or register to post a reply.

46407cc1bdfbd2db4f6e8876d74f990a
0
Kenneth_Gorking 101 May 20, 2009 at 13:37

lpwfxFormat has to be null for primary buffers.