Chapter 6: Streaming Sounds into Circular Buffers


Overview

Streaming is a good word to describe the flow of audio data from a hard disk into a buffer at just the right rate to keep it playing smoothly. The main advantage of streaming a sound from a hard disk (or CD) is that the buffer used to play the sound can be much shorter than the length of the sound file. As always, there are issues. The main issue that stands out is the obvious additional complexity imposed by having two methods of playing a file, streaming and non-streaming.

In addition, there are several ways of handling streaming; unfortunately , one of the most publicized ways of handling streaming uses Windows notifications, which is not the model recommended by developers at Microsoft. However, the only sample that ships with the DirectSound SDK uses notifications, and the CStreamingSound class that is an integral part of the utility code ( dsutil .cpp) only supports the notifications model.

The recommended model of handling streaming is to use a polling system, tracking the play cursor and topping up a circular buffer as the sound is being played . The reasons why this model is preferred are numerous although not obvious, and center around the reported unreliability of notifications when used with certain types of audio hardware. In other words, you may well (as we did) get your notification sample to work well on your new development system, but somewhere out there in the world some of your customers will get a glitch-ridden experience. Other advantages of the polling system include that you can create hardware buffers and apply special effects, whereas the notification-based system should be created in software to avoid glitching , which noticeably affects performance if special effects are applied.

This chapter describes two samples; the Circular Streams sample, which uses the recommended model of polling, and, for the sake of comparison, the Three Streams sample, which uses notifications. Both have identical UIs so you can compare and test their performance. Start by loading and running the Circular Streams sample, located in the AVBook\bin directory.




Fundamentals of Audio and Video Programming for Games
Fundamentals of Audio and Video Programming for Games (Pro-Developer)
ISBN: 073561945X
EAN: 2147483647
Year: 2003
Pages: 120

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net