Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Sounding you out...

This topic is 6927 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

Hey you Directsound freaks out there, About a year ago, I wrote all the directsound code I ever thought I''d need. It did it in a sort of stupid way-- since all my sound files were going to be in the same format, I wrote a little routine to peel out the wave header, and leave me with a file that just contained the wave data. Worked nicely. But now, a year later, I want to mix and match my wave files, because I''m going to let users add new sounds in. Well-- I read up on wave format, and I switched my routine over, with the help of the dsutil.c file in the sdk. Kaboom! Whenever I play a sound now, I get the most miserable cacaphony of sound you''ve ever heard. So, I ask nicely, can someone give me a tip on coding a simple routine that makes a directsound sound buffer from a wave file, no questions asked? I already have my directsound object made-- I''m looking for advice-- or actual code, if anyone has it, to put in my WavefileToSoundbuffer(dsoundinstance,filename) routine. Thanks a gazillion! -- Goodlife ----------------------------- Think of your mind as a door on a house. Leave the door always closed, and it's not a house, it's a prison. Leave the door always open, and it's not a house, it's a wilderness-- all the vermin creep in.

Share this post

Link to post
Share on other sites

I am still sounding out DirectSound myself. Here is the code (sans errorchecking) I use to load a static buffer:

fc is a wave "Format Chunk", designated by the "fmt " tag in the wave file.


memset(&dsbdesc, 0, sizeof(DSBUFFERDESC));
dsbdesc.dwSize = sizeof(DSBUFFERDESC);
dsbdesc.dwFlags = DSBCAPS_STATIC;
dsbdesc.dwBufferBytes = data_size;

w.cbSize = sizeof(WAVEFORMATEX);
w.nAvgBytesPerSec = fc.average_bytes_per_second ;
w.nBlockAlign = fc.blockalign;
w.nChannels = fc.channels;
w.nSamplesPerSec = fc.samplerate;
w.wBitsPerSample = fc.bits_per_sample;
w.wFormatTag = fc.formattag;

dsbdesc.lpwfxFormat = &w;

void *data = 0L;
DWORD bytes = 0L;

//: may be unsupported

//: note: buffer is an IDirectSoundBuffer * being
//: returned via method parameter, so its already
//: IDirectSoundBuffer**

HRESULT hr = m_sound->CreateSoundBuffer(&dsbdesc, buffer, 0L);

hr = (*buffer)->Lock( 0, 0, &data, &bytes, 0,0, DSBLOCK_ENTIREBUFFER );

//: fip is a file input pointer positioned to
//: the start of our wave data ..
//: fill our buffer with data
fip.read( (char*)data, data_size );

hr = (*buffer)->Unlock(data, data_size, 0,0);

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net 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!