Advertisement Jump to content
Sign in to follow this  


This topic is 4682 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: Here's what I've got so far:
							   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.dwBufferBytes = 3 * waveFormat.nAvgBytesPerSec;	//Hold 3 seconds of data
																// in the buffer
	bufferDesc.lpwfxFormat = &waveFormat;

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

	//Fill the static buffer (secondary)
	LPVOID lpvWrite;
	DWORD dwLength;

Here's where I'm stuck. At Buffer Basics > Filling and Playing Static Buffers (, 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.
  memcpy(lpvWrite, pbData, dwLength);
      lpvWrite,   // Address of lock start.
      dwLength,   // Size of lock.
      NULL,       // No wraparound portion.
      0);         // No wraparound size.
  ErrorHandler();  // Add error-handling here.

Share this post

Link to post
Share on other sites
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

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!