Skip to main content
gamedev.net
🔒 Locked

DirectSound buffer question

Started by The C modest god 5 replies 650+ views
Original Post
The C modest god
The C modest god
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.
It's all about the wheel.Never blindly trust technoligy.I love my internal organs.Real men don't shower. Quote: Original post by Toolmaker Quote:
Evil Steve
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...
bakery2k1
bakery2k1
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 *.
The C modest god
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?
It's all about the wheel.Never blindly trust technoligy.I love my internal organs.Real men don't shower. Quote: Original post by Toolmaker Quote:
PumpkinPieman
PumpkinPieman
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 setupsndArr[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.
paradoxnj
paradoxnj
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.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.