Sign in to follow this  

DirectSound buffer question

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

This topic is 4203 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this