Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Gyannea

Play sound buffer position stops updating

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

I have a streaming audio buffer where I write data every ''x'' milliseconds or so and I check the current position with ->GetCurrentPosition(¤tposition, &safewrite); Every time I write new data to the sound buffer I write ''currentposition'' to the screen. As long as I keep writing data to the buffer using ''->Lock()'' [and ->Unlock()] the pointer cycles as expected through the buffer. However, when I stop writing new data into the buffer (but don''t stop the playback) the current position oscillates about a region; it doesn''t continue to advance. Sound is still played but its just loud garbage. What I wanted to do is to stop the play after the last data written was actually played. Since the writes occur ahead of time, there is a delay. So what I hoped was to use the ''currentposition'' and compare it with the final value of my write position to see when it goes by my last data. Clearly that won''t work if ''currentposition'' is not updated. Anyone understand? Do you have to keep writing data to the buffer for ->GetCurrentPosition() to work? Thanks, Brian

Share this post


Link to post
Share on other sites
Advertisement
Oh yes, I have fought with this same issue a bunch. Part of the problem is, by the time you know what the position is, it has changed a little. I''ve tried a bunch of different things, including using notification events, timing, blah blah. Had various problems and dissatisfactions. Here''s what I do at this point:

I use a fairly small buffer, about 128k to 256k or so.

I clear the whole buffer before using it at all.

I write half the buffer at a time.

I check the position about 10 times a second. As soon as the position gets to being somewhere in the half I last wrote, I write the other half. (half = 1 - half, so it toggles between 0 and 1)

When I run of data to write, I clear the rest of that half buffer that I''m writing at the time I run out of data, but I don''t stop the buffer.

When the position gets somewhere in the partially filled half, I completely clear the other half, but I still don''t stop the buffer.

When the position is in the completely cleared half, I finally stop the buffer.

It''s pretty simple and it works great. If you''d like, I''d be happy to send you some sample code. Write to shavais@hotmail.com, and put "gamedev post response" in the subject, and include an e-mail address that I should reply to. =)

~Kulerasi

Share this post


Link to post
Share on other sites
Sounds like a good approach (though I still don''t understand why the pointer stops updating) however, I update the buffer very frequently like once every 10 ms. Necessary for a scanning radio. So I have to keep a couple of writes ahead and check before every write where my pointer is compared to the safepointer. The buffer is also several writes in size, even though it is actually smaller than your buffer.

I am able to look at the current position and see it update until I stop writing to the buffer. So I can get at it fast enough, that''s clear. But after I stop writing new data, the cursor just wiggles a bit. Something weird is going on.

What I am trying to do now is keep writing to the buffer as if the data is not done but fill it with silence and see if the pointer keeps updating. If it does, hopefully I will be able to tag a ''final position'' to check against so I can kill the playing.

None of this makes sense.

Brian

Brian

Share this post


Link to post
Share on other sites

  • 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!