Advertisement

DirectSound - Secondary Buffer SetFormat fails

Started by October 31, 2016 01:36 PM
0 comments, last by Capoeirista 8 years, 1 month ago

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");
	}

I think secondary buffers have to be mono, so you'll want to set nChannels in your WaveFormat instance to 1 instead of 2.

This topic is closed to new replies.

Advertisement