Streaming Sound in games
hello,
can anyone tell me how streaming (directsound) can be
done in real-time apps such as games?
specifically, how do i handle the notification
events?
okay, so far, I have set up directsoundnotify, which
will signal me to update the buffer content whenever
certain position has been reached..
now the question is, how am I supposed to "capture"
and handle the event objects?
In one of the DirectX SDK examples, it shows handling
of notification events using the WIN32 function
MsgWaitForMultipleObjects().
However, the function will not return until one of the
pre-defined events has been received, and that''s not
ideal for games.. (I wish there is a way to just supply
a callback function and handle it myself )
well, i''ve came up couple workarounds to this problem..
1. go radical and stuff everything onto a static
sound buffer
2. determine the current read postion in every game
cycle.. (kinda risky)
3. set the expiration time in MsgWaitForMultipleObjects
call...
Help... can anyone show me the proper (elegant) way to
handle a notification event?
Thanks!!!!!!!
1) Use WaitForMultipleObjects with zero-timeout; that is, it returns immediately in any case. If it was successful (message was available), handle it. If not, proceed to next frame.
2) Create separate low-priority thread that handles exclusively sound buffering by constantly calling WaitForMultipleObjects.
In either case use fairly long buffers - a second or so - to avoid skipping if main process "halts" for a few moments. I''d recommend method #2, as it is fairly transparent, and requires no extra stuff in main...
~~~ "'impossible' is a word in the dictonary of fools" --Napoleon
quote: Original post by Hway
In either case use fairly long buffers - a second or so - to avoid skipping if main process "halts" for a few moments. I''d recommend method #2, as it is fairly transparent, and requires no extra stuff in main...
Hello,
thanks for the response!
I have decided to go with you suggestion, since I want
to encapsulate everything inside a "CMusic" class and
avoid messing around in WinMain...
However, another question came up while I was reading
the SDK docs.. just wondering if you can answer
it for me..
okay, now, let''s say i''m maintaining a buffer pointer
which is one second behind the play cursor. (The block
between my pointer and the play cursor contains data
that has already been played).
my pointer marks the beginning point where I want to
have the data updated.. (it implies that each update
will load one second worth of data onto the streaming
buffer)
Question 1:
when I lock the streaming buffer, which flag should
I specify in my lock() call?
DSBLOCK_FROMWRITECURSOR or DSBLOCK_ENTIREBUFFER?
(both flags seem inappropriate to me )
if i use DSBLOCK_ENTIREBUFFER flag, will it interrupt
the playing process?
Question 2:
maybe later...
just wanna clear up a few things in my previous post..
My concerns with the DSBLOCK_ENTIREBUFFER flag..
[Question 1]:
If i use DSBLOCK_ENTIREBUFFER to lock the entire buffer,
do i need to stop playing first? (which is not what i want,
since i'm doing streaming)
[Question 2]:
How do I maintain my buffer pointer? I think my buffer
pointer should probably be an offset into the buffer,
right? (in bytes, from start of buffer)
the pointer will also be used in each Lock() call.
Since the buffer is circular, I probably will need to check to
see if the end of buffer has reached...
here's the pseudo code:
DWORD buffer_ptr = 0; //start at beginning...
if(UPDATE_OCCURRED)
{
if(end is not reached)
{
buffer_ptr += 1_sec_worth_of_data;
}
else
{
buffer_ptr wraps around...
}
}
would you validate my logic for me?
[Question 3]:
What would you recommend for the data size for each
update?
1-sec worth of data for a 3-sec buffer is
good?
Thanks again!
Edited by - nobody321 on September 15, 2000 8:51:21 AM
Edited by - nobody321 on September 15, 2000 8:57:30 AM
My concerns with the DSBLOCK_ENTIREBUFFER flag..
[Question 1]:
If i use DSBLOCK_ENTIREBUFFER to lock the entire buffer,
do i need to stop playing first? (which is not what i want,
since i'm doing streaming)
[Question 2]:
How do I maintain my buffer pointer? I think my buffer
pointer should probably be an offset into the buffer,
right? (in bytes, from start of buffer)
the pointer will also be used in each Lock() call.
Since the buffer is circular, I probably will need to check to
see if the end of buffer has reached...
here's the pseudo code:
DWORD buffer_ptr = 0; //start at beginning...
if(UPDATE_OCCURRED)
{
if(end is not reached)
{
buffer_ptr += 1_sec_worth_of_data;
}
else
{
buffer_ptr wraps around...
}
}
would you validate my logic for me?
[Question 3]:
What would you recommend for the data size for each
update?
1-sec worth of data for a 3-sec buffer is
good?
Thanks again!
Edited by - nobody321 on September 15, 2000 8:51:21 AM
Edited by - nobody321 on September 15, 2000 8:57:30 AM
Go check out the sound core in the Gauntlet Style Project section here. It contains streaming sound, using a seperate thread to handle messages. A perfect example of what you are trying to do.
Jim Adams
Jim Adams
Jim Adams, Author"Programming Role-Playing Games with DirectX""Advanced Animation with DirectX""Programming Role-Playing Games with DirectX, 2nd Edition"
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement