Next: 3.7 Using echo effects Up: 3 Using MIDAS Digital Previous: 3.5 Using streams

# 3.6 Playing streams

There are two different ways of playing streams in MIDAS Digital Audio System: stream file playback and polling stream playback. In stream file playback, MIDAS creates a new thread that will read the stream data from a given file and plays it automatically on the background. In polling stream playback the user needs to read or generate the stream data, and feed it to MIDAS.

Stream files are played with MIDASplayStreamFile and MIDASplayStreamWaveFile. Both functions require as arguments the stream file name, stream playback buffer length and stream looping flag. The files played with MIDASplayStreamFile should contain only raw sample data, and the function will therefore require as arguments also the stream data sample type and playback rate. MIDASplayStreamWaveFile plays RIFF WAVE files, and can read the information from the file header. The playback functions will return a stream handle that can be used to refer to the stream.

Polling stream playback is started with MIDASplayStreamPolling. It requires as its arguments the stream sample type, playback rate and buffer length. The actual stream playback will not start, however, until some stream data is fed to the system with MIDASfeedStreamData. After the playback has starter, MIDASfeedStreamData needs to be called periodically to feed the system new stream data to play, otherwise the system will run out of stream data and stop playback.

The stream playback buffer length controls the amount of stream data buffered for stream playback. The longer the buffer is, the longer the system can play the stream when new data is not available until the playback needs to be stopped. Running out of stream data will result in irritating breaks in the sound and should be avoided. Longer playback buffers will, however, add delay to the stream playback, and consume more memory. For stream file playback, a stream buffer length of 500ms should be suitable. For polling stream playback, the buffer length should be at least twice the longest expected delay between two calls to MIDASfeedStreamData.

Stream playback is stopped with MIDASstopStream, regardless of the stream type.

## 3.6.1 Controlling stream playback

The stream playback properties can be changed while it is being played. MIDASsetStreamRate can be used to change its playback rate, MIDASsetStreamVolume its volume and MIDASsetStreamPanning its panning position. All of these functions take as an argument the stream handle from the stream playback function, and the new value for the playback property.

The playback of the stream can also be paused with MIDASpauseStream, and resumed after pausing with MIDASresumeStream. This can be useful if your application knows it will run out of stream data soon, and wishes to fade the stream out and pause it until more data is available. Stream data reading and feeding can continue while the stream is paused until the stream buffer is full.

## 3.6.2 Getting stream information

The amount of data currently in the stream buffer can be monitored with MIDASgetStreamBytesBuffered. The information could be used to determine how soon new stream data is needed to continue playback, or whether or not enough space exists in the stream buffer for a complete new block of data.

Note that with ADPCM streams the stream buffer contains the decompressed data, as 16-bit samples, instead of the compressed ADPCM data.

Next: 3.7 Using echo effects Up: 3 Using MIDAS Digital Previous: 3.5 Using streams