SetFormat function call gives error code 0x88780032. It works just fine with Primary Buffer.
Before SetFormat() call debuging shows following values:
BufferDescription.dwSize = 40
BufferDescription.dwFlags = 0;
BufferDescription.dwBufferBytes = 192000
WaveFormat.wFormatTag = 1
WaveFormat.nChannels = 2
WaveFormat.nSamplesPerSec = 48000
WaveFormat.wBitsPerSample = 16
WaveFormat.nBlockAlign = 4
WaveFormat.nAvgBytesPerSec = 192000
WaveFormat.cbSize = 0;
This is from Handmade Hero series (Day 7).
WAVEFORMATEX WaveFormat = {};
WaveFormat.wFormatTag = WAVE_FORMAT_PCM;
WaveFormat.nChannels = 2;
WaveFormat.nSamplesPerSec = SamplesPerSecond;
WaveFormat.wBitsPerSample = 16;
WaveFormat.nBlockAlign = (WaveFormat.nChannels * WaveFormat.wBitsPerSample) / 8;
WaveFormat.nAvgBytesPerSec = WaveFormat.nBlockAlign * WaveFormat.nSamplesPerSec;
WaveFormat.cbSize = 0;
DSBUFFERDESC BufferDescription = {};
BufferDescription.dwSize = sizeof(BufferDescription);
BufferDescription.dwFlags = 0;
BufferDescription.dwBufferBytes = BufferSize;
BufferDescription.lpwfxFormat = &WaveFormat;
LPDIRECTSOUNDBUFFER SecondaryBuffer;
if (SUCCEEDED(DirectSound->CreateSoundBuffer(&BufferDescription, &SecondaryBuffer, 0)))
{
HRESULT Error = SecondaryBuffer->SetFormat(&WaveFormat);
if (SUCCEEDED(Error))
{
OutputDebugStringA("SecondaryBuffer is fine!\n");
}