Mr Violent 0 Newbie Poster

Hey there, I'm having a problem with the WAVEFORMATEX format, and setting my primary buffer's format. My code is below:

void ErrorBox(string strMessage) {
MessageBox(NULL, strMessage.c_str(), "Error", MB_OK | MB_ICONEXCLAMATION);
return;
}

bool DSPlayer::SetPrimaryBuffer() {

	if (lpDS == NULL) {
		ErrorBox("Direct sound not initialized.");
		return false;
	}

	ZeroMemory(&dsBufferDesc, sizeof(DSBUFFERDESC));

	dsBufferDesc.dwSize = sizeof(DSBUFFERDESC);
	dsBufferDesc.dwFlags = DSBCAPS_PRIMARYBUFFER;
	dsBufferDesc.dwBufferBytes = 0;
	dsBufferDesc.lpwfxFormat = NULL;

	if (FAILED(lpDS->CreateSoundBuffer(&dsBufferDesc, &lpDSPrimary, NULL))) {
		ErrorBox("Unable to create primary buffer.");
		return false;
	}

	WAVEFORMATEX wfx;
	ZeroMemory(&wfx, sizeof(WAVEFORMATEX));

	
	// 1ff9fe86
	wfx.wFormatTag = WAVE_FORMAT_PCM;
	wfx.nChannels = 2;
	wfx.nSamplesPerSec = 22050;
	wfx.wBitsPerSample = 16;
	wfx.nBlockAlign = ((wfx.wBitsPerSample * wfx.nChannels) / 8);
	wfx.nAvgBytesPerSec = (wfx.nSamplesPerSec * wfx.nBlockAlign);
	wfx.cbSize = 0;
	

	HRESULT hr;

	if (FAILED(hr = lpDSPrimary->SetFormat(&wfx))) {
		ErrorBox("Failed to set primary buffer's format");
		return false;
	}
	

	return true;
}

My error is telling me that I don't have the priority level I need to set the format. How do I get this priority level?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.