Jump to content
  • Advertisement
Sign in to follow this  
The C modest god

DirectSound buffer question

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

If I have a DirectSoundBuffer, and I lock it to fill the sound buffer with data. Then I get a BYTE pointer by locking the buffer. Lets say I have set the samples to be 16 bit. So the first sample will be the first two bytes pointed by the pointer. However, which is the most significant byre? the first byte or the second? Thanks in advance.

Share this post


Link to post
Share on other sites
Advertisement
You can just cast the BYTE* it to a WORD*, which implies that the first byte is the most significant byte (On a little endian system).

I think...

Share this post


Link to post
Share on other sites
Quote:
Original post by Evil Steve
You can just cast the BYTE* it to a WORD*, which implies that the first byte is the most significant byte (On a little endian system).

I think...


On a little endian system, the first byte will be the _least_ significant byte.

Casting from a BYTE * to a WORD * will work, but since 16-bit samples are signed, you'd probably be better off casting to a pointer to a 16-bit signed type, eg signed short *.

Share this post


Link to post
Share on other sites
I was trying to set a value of a directsound buffer.
However, I wanted to make the method so it suits for all possible bitper sample possibilites.
How would I accomplish that? Do I need to pass this method a signed long and somehow to set the value?

Share this post


Link to post
Share on other sites
Okay first of all, you don't get a BYTE* from lock, you get a void*.

You also have to keep in mind how many channels your buffer has been set to, so how many channels?

You mainly start with 2 channels, which means you want the audio to be stereo (not mono). A buffer size is channels(usuallt 2+)*samplesize(usually 16bits)*samplespersecond(44100hz usually)*seconds so if your sample size is 16-bits each sample(whole) for a 2 channel buffer will be 32 bits.


struct sample{
short leftSpeaker;
short rightSpeaker;
};

short left = 0;
short right = 0;

sample* sndArr = (sample*)buffer->lock(...); // or however you have it setup

sndArr[0].leftChannel = left;
sndArr[0].rightChannel = right;






If this doesn't yeild you the results you want try unsigned shorts.
Now this is just off the top of my head, I'll take another look when I get home but this is how it's done I believe.

Share this post


Link to post
Share on other sites
Quote:
Original post by The C modest god
I was trying to set a value of a directsound buffer.
However, I wanted to make the method so it suits for all possible bitper sample possibilites.
How would I accomplish that? Do I need to pass this method a signed long and somehow to set the value?


Ok...to make your life simpler, DirectSound will only work on Windows based Intel/AMD systems. There for it's little endian aligned.

Share this post


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

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!