Next: 3.3 Channels Up: 3 MIDAS concepts Previous: 3.1 Samples

# 3.2 Streams

In MIDAS, streams are continuous flows of sample data. Unlike samples, streams are not stored in the Sound Devices themselves, but are instead read from the system memory as they are played. Because of this, the complete data for the stream does not need to be available when playing starts, but can instead be read from disk, or even generated on the fly, as playback proceeds. The playback properties of the stream -- sampling rate, volume and panning -- can be changed in real time just like those of a sample. However, as the sample data for the stream is not stored anywhere in the Sound Device, each stream can only be played once.

The MIDAS API offers three ways for playing streams: file playback, polling playback and callbacks. For file playback, the application simply supplies the system the name of the file containing the sample data for the stream, and playback proceeds automatically. In polling playback mode, the application opens the stream and periodically feeds new sample data to be played. In callback mode, the application sets a callback function that is called each time the stream buffer loops, and can there fill the buffer with new sample data.

The most obvious use for streams is to play long sections of digital sound or music directly from disk, without needing to load everything into memory first. Stream playback could also be used to mix the output of a separate sound generator, such as a speech synthesizer, with the rest of the sound and music in the system.

Currently streams can only be played with software mixing Sound Devices. In addition, file playback is only possible under operating systems that support multithreading.