Next: 7 Miscellaneous Up: 6 Stream playback Previous: Data types

# Functions

This section describes all functions available for MIDAS stream playback.

## 6.3.1 MIDASfeedStreamData

    unsigned MIDASfeedStreamData(MIDASstreamHandle stream,
        unsigned char *data, unsigned numBytes, BOOL feedAll);

Feeds sound data to a digital audio stream buffer.

### Input

stream
  The stream that will play the data
data
  Pointer to sound data
numBytes
  Number of bytes of sound data available
feedAll
  TRUE if the function should block until all sound data can be fed

### Description

This function is used to feed sample data to a stream that has been started with MIDASplayStreamPolling. Up to numBytes bytes of new sample data from *data will be copied to the stream buffer, and the stream buffer write position is updated accordingly. The function returns the number of bytes of sound data actually used. If feedAll is TRUE, the function will block the current thread of execution until all sound data is used.

### Return value

The number of bytes of sound data actually used.

### Operating systems

Win32, Linux

### See also

MIDASplayStreamPolling

## 6.3.2 MIDASgetStreamBytesBuffered

    DWORD MIDASgetStreamBytesBuffered(MIDASstreamHandle stream)

Gets the number of bytes of stream currently buffered.

### Input

stream
  The stream handle

### Description

This function returns the number of bytes of sound data currently stored in the stream buffer. It can be used to monitor the stream playback, and possibly prepare to feed extra data if the figure gets too low.

### Return value

The number of bytes of sound data currently buffered.

### Operating systems

Win32, Linux

### See also

MIDASfeedStreamData

## 6.3.3 MIDASpauseStream

    BOOL MIDASpauseStream(MIDASstreamHandle stream)

Pauses stream playback.

### Input

stream
  The stream to pause

### Description

This function pauses the playback of a stream. When a stream is paused, stream data can be fed normally with MIDASfeedStreamData, but nothing will actually be played. Playback can be resumed with MIDASresumeStream.

### Return value

TRUE if successful, FALSE if not.

### Operating systems

Win32, Linux

### See also

MIDASresumeStream, MIDASfeedStreamData

## 6.3.4 MIDASplayStreamFile

    MIDASstreamHandle MIDASplayStreamFile(char *fileName,
        unsigned sampleType, unsigned sampleRate,
        unsigned bufferLength, int loopStream)

Starts playing a digital audio stream from a file.

### Input

fileName
  Stream file name
sampleType
  Stream sample type, see `enum` MIDASsampleTypes
sampleRate
  Stream sample rate
bufferLength
  Stream playback buffer length in milliseconds
loopStream
  1 if the stream should be looped, 0 if not

### Description

This function starts playing a digital audio stream from a file. The file must contain raw audio data with no headers -- to play WAVE files, use MIDASplayStreamWaveFile. The function allocates the stream buffer, creates a new thread that will read sample data from the file to the stream buffer, and starts the Sound Device to play the stream. The stream will continue playing until it is stopped with MIDASstopStream. A Sound Device channel will be automatically allocated for the stream.

The stream buffer length should be at least around 500ms if the stream file is being read from a disc, to avoid breaks in stream playback

### Return value

MIDAS stream handle if successful, NULL if failed.

### Operating systems

Win32, Linux

### See also

MIDASplayStreamWaveFile, MIDASstopStream

## 6.3.5 MIDASplayStreamWaveFile

    MIDASstreamHandle MIDASplayStreamWaveFile(char *fileName,
        unsigned bufferLength, int loopStream)

Starts playing a digital audio stream from a RIFF WAVE file.

### Input

fileName
  Stream file name
bufferLength
  Stream playback buffer length in milliseconds
loopStream
  1 if the stream should be looped, 0 if not

### Description

This function starts playing a digital audio stream from a file. The file must be a standard RIFF WAVE (`.wav`) sound file containing raw PCM sound data -- compressed WAVE files are not supported. The function allocates the stream buffer, creates a new thread that will read sample data from the file to the stream buffer, and starts the Sound Device to play the stream. The stream will continue playing until it is stopped with MIDASstopStream. A Sound Device channel will be automatically allocated for the stream.

The stream buffer length should be at least around 500ms if the stream file is being read from a disk, to avoid breaks in stream playback

### Return value

MIDAS stream handle if successful, NULL if failed.

### Operating systems

Win32, Linux

### See also

MIDASplayStreamFile, MIDASstopStream

## 6.3.6 MIDASplayStreamPolling

    MIDASstreamHandle MIDASplayStreamPolling(unsigned sampleType,
        unsigned sampleRate, unsigned bufferLength)

Starts playing a digital audio stream in polling mode.

### Input

sampleType
  Stream sample type, see `enum` MIDASsampleTypes
sampleRate
  Stream sample rate
bufferLength
  Stream playback buffer length in milliseconds

### Description

This function starts playing a digital audio stream in polling mode. It allocates and empty stream buffer, and starts the Sound Device to play the stream. Sample data can be fed to the stream buffer with MIDASfeedStreamData. The stream will continue playing until it is stopped with MIDASstopStream. This function will automatically allocate a Sound Device channel for the stream.

To avoid breaks in playback, the stream buffer size should be at least twice the expected polling period. That is, if you will be feeding data 5 times per second (every 200ms), the buffer should be at least 400ms long.

### Return value

MIDAS stream handle if successful, NULL if failed.

### Operating systems

Win32, Linux

### See also

MIDASstopStream, MIDASfeedStreamData

## 6.3.7 MIDASresumeStream

    BOOL MIDASresumeStream(MIDASstreamHandle stream)

Resumes stream playback after pause.

### Input

stream
  The stream to resume

### Description

This function resumes the playback of a stream that has been paused with MIDASpauseStream.

### Return value

TRUE if successful, FALSE if not.

### Operating systems

Win32, Linux

### See also

MIDASpauseStream

## 6.3.8 MIDASsetStreamPanning

    BOOL MIDASsetStreamPanning(MIDASstreamHandle stream,
        int panning);

Changes stream panning position.

### Input

stream
  Stream handle for the stream
panning
  New panning position for the stream

### Description

This function changes the panning position for a stream that is being played. The initial volume is 0 (center). See description of `enum` MIDASpanning for information about the panning position values.

### Return value

TRUE if successful, FALSE if not.

### Operating systems

Win32, Linux

### See also

MIDASsetStreamVolume, MIDASsetStreamRate

## 6.3.9 MIDASsetStreamRate

    BOOL MIDASsetStreamRate(MIDASstreamHandle stream,
        unsigned rate);

Changes stream playback sample rate.

### Input

stream
  Stream handle for the stream
rate
  New playback sample rate for the stream, in Hertz.

### Description

This function changes the playback sample rate for a stream that is being played. The initial sample rate is given as an argument to the function that starts stream playback.

Note that the stream playback buffer size is calculated based on the initial sample rate, so the stream sample rate should not be changed very far from that figure. In particular, playback sample rates over two times the initial value may cause breaks in stream playback. Too low rates, on the other hand, will increase latency.

### Return value

TRUE if successful, FALSE if not.

### Operating systems

Win32, Linux

### See also

MIDASsetStreamVolume, MIDASsetStreamPanning

## 6.3.10 MIDASsetStreamVolume

    BOOL MIDASsetStreamVolume(MIDASstreamHandle stream,
        unsigned volume);

Changes stream playback volume.

### Input

stream
  Stream handle for the stream
volume
  New volume for the stream, 0-64.

### Description

This function changes the playback volume for a stream that is being played. The initial volume is 64 (maximum).

### Return value

TRUE if successful, FALSE if not.

### Operating systems

Win32, Linux

### See also

MIDASsetStreamRate, MIDASsetStreamPanning

## 6.3.11 MIDASstopStream

    BOOL MIDASstopStream(MIDASstreamHandle stream)

Stops playing a digital audio stream.

### Input

stream
  The stream that will be stopped

### Description

This function stops playing a digital audio stream. It stops the stream player thread, deallocates the stream buffer, closes the stream file (if playing from a file) and deallocates the stream playback channel.

### Return value

TRUE if successful, FALSE if not.

### Operating systems

Win32, Linux

### See also

MIDASplayStreamFile, MIDASplayStreamPolling

Next: 7 Miscellaneous Up: 6 Stream playback Previous: Data types