Ogg Vorbis is nice

Phew, just managed to get the ogg streamer code to run good enough. Ended up rewriting it twice, it turned out to be much more complicated than I thought.

The way it works now, there are two threads.
The reader thread loads the song from disk in four second buffers. When a buffer is full, it’s placed on the play queue, and the next read buffer is retrieved from the read queue.
The player thread pops buffers from the play queue and writes the song to the audio stream. After a buffer has been read, it gets cleared and placed at the end of the read queue.

If the read or play queues ever get empty, the thread silently waits for a while. This is not a problem for the read queue, but for the play queue this results in a pause in the audio. It’s a good thing the read queue is much faster than the play queue. ;)

There are only two buffers in play at any given time, the queues are only there for synchronization. Most of the time, there’s one active play buffer and one buffer in the play queue, and the read queue is totally empty.

Now to implement some 3d panning and volume transformations. =D

This is the library I’m using: http://www.j-ogg.de/

posted 13 years ago