Jump to content
  • Advertisement
  • entries
    743
  • comments
    1924
  • views
    584358

Ogg Fun

Sign in to follow this  
Aardvajk

284 views

Spent most of today writing an implementation of streaming Ogg Vorbis files from memory into a small DirectSound buffer. Been emotional at times, but finally got there.

I can't stand all this DirectSound notification thread WaitForSingleObject nonsense, so the approach I've used is slightly different from the other approaches I saw when researching on the internet.

Streaming from Ogg Vorbis is complicated slightly by the fact that you have no idea how much data is going to be returned from each ov_read(), only the maximum amount. However, my method depends on updating the buffer every quarter second or so for a two second buffer, and it is the space available in the buffer that dictates how much needs to be written.

So I ov_read() into a separate cache, then if there is room in the buffer for all of that data, bung it in and read again.

When there is too much in the cache to fit in the buffer, I put in what will fit, then move the remainder to the front of the cache, storing the size of the data in the cache.

Then, prior to the next ov_read() in the next update, I check to see if there is pending data in the cache and write it to the buffer first if so.

Seems to work okay. When you start playing the data, you can specify how many times you want it to loop (or pass 0 for infinite). It correctly fills the buffer with silence after playing is finished although you do have to stop the buffer manually.

Oh, yeah, by the way sound effects are back in Squishy with facility to load, play and assign them in the editor, so all the above was to get music back in.

I'm sure you hip and trendy cool cats are all using XACT these days, but if anyone could make use of an Ogg and DirectSound8 streaming library, just shout and I'll supply the code.
Sign in to follow this  


0 Comments


Recommended Comments

There are no comments to display.

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
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!