• Advertisement
Sign in to follow this  

'IDirectSoundBuffer8::Lock'ing

This topic is 4341 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

All right, as I can't get CSound working without strange linking errors that I can't get around, I'm trying to work with DirectSound objects directly. I just updated to the Feb 2006 SDK so I'm completely up to date now. The documentation I'm using is here: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/dx9_directsound_programming_guide.asp Here's what I've got so far:
	CoInitialize(NULL);
	if(FAILED(CoCreateInstance(CLSID_DirectSound8, NULL, CLSCTX_INPROC_SERVER,
							   IID_IDirectSound8, (LPVOID*)&pSound)))
		return false;
	if(FAILED(pSound->Initialize(NULL))) return false;
	if(FAILED(pSound->SetCooperativeLevel(*(window->gethWnd()),DSSCL_PRIORITY))) return false;

	//Set up WAV format structure
	memset(&waveFormat, 0, sizeof(WAVEFORMATEX));
	waveFormat.wFormatTag = WAVE_FORMAT_PCM;
	waveFormat.nChannels = 2;
	waveFormat.nSamplesPerSec = 22050;
	waveFormat.nBlockAlign = 4;
	waveFormat.nAvgBytesPerSec = waveFormat.nSamplesPerSec * waveFormat.nBlockAlign;
	waveFormat.wBitsPerSample = 16;

	//Set up buffer desc structer
	memset(&bufferDesc, 0, sizeof(DSBUFFERDESC));
	bufferDesc.dwSize = sizeof(DSBUFFERDESC);
	bufferDesc.dwFlags = DSBCAPS_CTRLPAN | DSBCAPS_CTRLVOLUME | DSBCAPS_CTRLFREQUENCY
		| DSBCAPS_GLOBALFOCUS;
	bufferDesc.dwBufferBytes = 3 * waveFormat.nAvgBytesPerSec;	//Hold 3 seconds of data
																// in the buffer
	bufferDesc.lpwfxFormat = &waveFormat;

	//Create buffer
	LPDIRECTSOUNDBUFFER pDsb = NULL;
	if(FAILED(pSound->CreateSoundBuffer(&bufferDesc, &pDsb, NULL)))
		return false;
	pDsb->QueryInterface(IID_IDirectSoundBuffer8, (LPVOID*)pSecondaryBuffer);
	pDsb->Release();

	//Fill the static buffer (secondary)
	LPVOID lpvWrite;
	DWORD dwLength;
	if(DS_OK==pSecondaryBuffer->Lock(
		0,
		0,
		&lpvWrite,
		&dwLength,
		NULL,
		NULL,
		DSBLOCK_ENTIREBUFFER))
	{

Here's where I'm stuck. At Buffer Basics > Filling and Playing Static Buffers (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/Filling_and_Playing_Static_Buffers.asp), there's a piece right after the 'if' statement that I stopped at that uses memcpy: memcpy(lpvWrite, pbData, dwLength); Leave it to Microsoft to not document what "pbData" is. Can anyone tell me what this should be? Here's what MS's code looks like:
LPVOID lpvWrite;
DWORD  dwLength;

if (DS_OK == lpdsbStatic->Lock(
      0,          // Offset at which to start lock.
      0,          // Size of lock; ignored because of flag.
      &lpvWrite,  // Gets address of first part of lock.
      &dwLength,  // Gets size of first part of lock.
      NULL,       // Address of wraparound not needed. 
      NULL,       // Size of wraparound not needed.
      DSBLOCK_ENTIREBUFFER))  // Flag.
{
  memcpy(lpvWrite, pbData, dwLength);
  lpdsbStatic->Unlock(
      lpvWrite,   // Address of lock start.
      dwLength,   // Size of lock.
      NULL,       // No wraparound portion.
      0);         // No wraparound size.
}
else
(
  ErrorHandler();  // Add error-handling here.
}

Share this post


Link to post
Share on other sites
Advertisement
It's probably the raw, uncompressed, PCM sound data. It is assumed that the reader is either generating this data or reading it in from a file. In the case of secondary sound buffers, this will be the sound stored in the buffer for later playback.

[shameless self plug]
I have a few documents about getting up and running with DirectSound on my site. If you would like to view them, just follow the link in my quote. (Keep in mind I have a very off-beat sense of humor and I'm not very good at writting informatively ;)

Share this post


Link to post
Share on other sites
Hmm your tutorials don't seem to go into COM for initialization, do they? Thank you! That whole system scares me. I've only ever done it for DirectMusic so if I can do this with just the objects I'm quite happy. Continue shamelessly plugging away! Wish this tutorial would have shown up in google or yahoo!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement