Skip to main content
gamedev.net
🔒 Locked

Streaming buffer?

Started by The C modest god Jul 10, 2006 at 2:57 AM 5 replies 850+ views
Original Post
The C modest god
The C modest god
I read that in directSound you can make a streaming buffer. That is, a buffer that you play it and simultanously write new data into to it (in a portion different then the currently played). So does that mean that lock a directSoundBuffer does not stop the sound card from playing other sounds? From what I understood in direct3D, if you lock a texture, then the 3D card cannot simultanously render things while you locked the texture. So direct3D is different then directSound in this manner? Am I correct? 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:
katsh
katsh
ya u right.
in directsound,u can write(into buffer) and play at the sametime.
thats the main concept of streaming-play.

btw theres no "streaming buffer".
The C modest god
The C modest god
Quote:
Original post by katsh
ya u right.
in directsound,u can write(into buffer) and play at the sametime.
thats the main concept of streaming-play.

btw theres no "streaming buffer".

You mean there is no interface called like that? Because if you will look at the directSound documentation:

Quote:

Using Streaming Buffers
A streaming buffer plays a long sound that cannot all fit into the buffer at once. As the buffer plays, old data is periodically replaced with new data.

To play a streaming buffer, call the IDirectSoundBuffer8::Play method, specifying DSBPLAY_LOOPING in the dwFlags parameter.

To halt playback, call the IDirectSoundBuffer8::Stop method. This method stops the buffer immediately, so you need to be sure that all data has been played. This can be done by polling the play position or by setting a notification position.

Streaming into a buffer requires the following steps:

Ascertain whether the buffer is ready to receive new data. This can be done either by polling the play cursor or by waiting for a notification.
Lock a portion of the buffer by using IDirectSoundBuffer8::Lock. This method returns one or two addresses where data can now be written.
Write the audio data to the returned address or addresses by using a standard memory-copy routine.
Unlock the buffer using IDirectSoundBuffer8::Unlock.
The reason IDirectSoundBuffer8::Lock might return two addresses is that you can lock any number of bytes, up to the size of the buffer, regardless of the start point. If necessary, the locked portion wraps around to the beginning of the buffer. If it does, you have to perform two separate memory copies.

For example, say you lock 30,000 bytes beginning at offset 20,000 in a 40,000-byte buffer. When you call Lock in this case, it returns four values:

The memory address of offset 20,000.
The number of bytes locked from that point to the end of the buffer; that is, 20,000 bytes. You write this number of bytes to the first address.
The memory address of offset 0.
The number of bytes locked from that point; that is, 10,000 bytes. You write this number of bytes to the second address.
If no wraparound is necessary, the last two values are NULL and 0 respectively.

Although it's possible to lock the entire buffer, you must not do so while it is playing. Normally you refresh only a fraction of the buffer each time. For example, you might lock and write to the first quarter of the buffer as soon as the play cursor reaches the second quarter, and so on. You must never write to the part of the buffer that lies between the play cursor and the write cursor.

The following function writes data to a sound buffer, starting at the position passed in dwOffset:



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:
katsh
katsh
theres no object(com object,directsoud object) like that.
so it mean theres no intetface like that.(of course)
Evil Steve
Evil Steve
I think what katsh means is there's no seperate interface (Like IDirectSoundStreamingBuffer8 or someting).

The way it works is you only lock part of the buffer, so the sound card can still use the part of the buffer that's not locked. What I guess DSound does, is just copies the chunk of the buffer you want into system memory, then gives you a pointer to that data. Then when you unlock, it chucks it back to memory addressable by the sound card.
paradoxnj
paradoxnj
You only want to use streaming buffers for conversation or music. For performance reasons, small sounds like gunshots should be a static buffer.
katsh
katsh
Quote:
Original post by Evil Steve
I think what katsh means is there's no seperate interface (Like IDirectSoundStreamingBuffer8 or someting).

hmm..yes,its 1 of i meant.
but not only a name.

Quote:
Original post by Evil Steve
The way it works is you only lock part of the buffer, so the sound card can still use the part of the buffer that's not locked.

Dsound can lock where playing right now.
so its programmers responsibilty that lock right position where not playing.
if u lock where playing,output sound must be something strange.

Quote:
Original post by Evil Steve
What I guess DSound does, is just copies the chunk of the buffer you want into system memory, then gives you a pointer to that data. Then when you unlock, it chucks it back to memory addressable by the sound card.

in the streaming play,we have to copy the "part of the chunk"
not "chunk" because wave-data is one chunk,so it mean entire of wave-data.

Quote:
Original post by paradoxnj
You only want to use streaming buffers for conversation or music. For performance reasons, small sounds like gunshots should be a static buffer.

of course. i think modest god knows it.
we use streaming for resource reasons than performance reasons.

sorry i should not speak too much, cuz my english is not understandable. :P


Topic Locked

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

Sign in to reply to this topic.