IDirectSound8::CreateSoundBuffer returns DSERR_BUFFERLOST

674 Views Asked by At

What does IDirectSound8::CreateSoundBuffer returning DSERR_BUFFERLOST mean?

According to the documentation DSERR_BUFFERLOST isn't a valid return code from CreateSoundBuffer.

Two of our users have report errors where CreateSoundBuffer is returning DSERR_BUFFERLOST (out of hundreds). We've shipped products with this code to thousands of users without any reported issues. Both users report having latest sound drivers. One reports having an Alienware 17 R4 laptop, the other an MSI laptop.

One user on Windows-10 reported that using Windows-8 compatibility mode fixed this issue.

Other internet references include this link. One user tried restarting their Windows Audio service and it had no effect. This link seems to describe an identical issue in another game.

Here is the rest of the setup for that call:

WAVEFORMATEX w = {};
w.wFormatTag = WAVE_FORMAT_PCM;
w.nSamplesPerSec = pSoundData->sampleRate;
w.wBitsPerSample = (WORD)pSoundData->bitsPerSample;
w.nChannels = (WORD)pSoundData->numChannels;

w.nBlockAlign = w.nChannels * w.wBitsPerSample / 8;
w.nAvgBytesPerSec = w.nSamplesPerSec * w.nBlockAlign;
w.cbSize = 0;

int bufferSize = pSoundData->decodedSize;


int bufferFlags = DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_CTRLVOLUME | DSBCAPS_CTRLFREQUENCY | DSBCAPS_CTRLPAN | DSBCAPS_GLOBALFOCUS;

DSBUFFERDESC bufferDesc = { sizeof(DSBUFFERDESC), (DWORD)bufferFlags, (DWORD)bufferSize, 0, &w, DS3DALG_DEFAULT };


LPDIRECTSOUNDBUFFER pBuffer;
HRESULT hr = pSoundInterface->mDevice->CreateSoundBuffer(&bufferDesc, &pBuffer, NULL);
1

There are 1 best solutions below

0
Chuck Walbourn On

The DirectSound docs haven't been edited in ages, but I can tell you that DSERR_BUFFERLOST is a valid error from a number of methods: GetCurrentPosition, Play, Stop, Lock, Unlock, and Restore.

DirectSound on all versions of Windows since Windows Vista isn't "direct" at all. It is using Windows Core Audio (WASAPI) to output. The primary reason you get a DSERR_BUFFERLOST is whenever you get a 'critical error' from WASAPI. Normally this only happens if you are losing the current playback device, but it's handled internally to switch devices so that really shouldn't be the case here.

If you are able to repro this issue, you could try enabling DirectSound ETW events to look for the error code happening here.

8a93b54b-c75a-49b5-a5be-9060715b1a33    Microsoft-Windows-DirectSound
ae4bd3be-f36f-45b6-8d21-bdd6fb832853    Microsoft-Windows-Audio

Otherwise, it could be a driver or hardware bug at play.