# NNSSndStrmCallback

## Syntax

      #include <nnsys/snd.h>

      typedef void (*NNSSndStrmCallback)(
              NNSSndStrmCallbackStatus status,
              int numChannles,
              void* buffer[],
              u32 len,
              NNSSndStrmFormat format,
              void* arg );

## Arguments

`status` | The callback state.
`numChannles` | The number of channels.
`buffer` | The array of the top address of the buffer for every channel.
`len` | The byte length of the buffer for each channel.
`format` | The sample data format.
`arg` | The user argument.

## Return Values

None.

## Description

The callback function called when waveform data must be supplied during stream play.

This callback function is registered by the `NNS_SndStrmSetup`, `NNS_SndArcStrmStartEx2`, and the `NNS_SndArcStrmPrepareEx2` functions.

Callback functions registered with the `NNS_SndStrmSetup` function are responsible for supplying the waveform data for the passed buffer. Callback functions registered with the `NNS_SndArcStrmStartEx2` or `NNS_SndArcStrmPrepareEx2` functions are called after waveform data is supplied by the sound archive stream library, so they are not responsible for supplying waveform data. However, they can process waveform data.

The callback function is called at two possible different points. One point to call it is before starting stream play, in order to pass waveform data in advance to all stream buffers. At this time, `NNS_SND_STRM_CALLBACK_SETUP` is passed in the callback state `status`. The other point to call the callback is during stream play. Here it is called in order to supply the continuation of the waveform data to the buffer, which has been consumed by playback. At this time, `NNS_SND_STRM_CALLBACK_INTERVAL` is passed in the callback state `status`.

The number of channels used for stream play is passed in `numChannles`. The number of elements in the array `buffer`, which holds the top addresses of the buffers, is the same as the value of `numChannles`. The buffer size for each channel is `len` bytes.

The sample data format `format` is one of the following values.

Table: NNSSndStrmFormat

Label | Description
--- | ---
NNS_SND_STRM_FORMAT_PCM8 | 8-bit PCM.
NNS_SND_STRM_FORMAT_PCM16 | 16-bit PCM.

### Note

After supplying and/or processing the waveform data, call the `DC_FlushRange` function or a similar function to ensure that it is written to main memory.

Note: Be aware that the callback functions registered with the `NNS_SndStrmSetup` function are called while interrupts are prohibited. On the other hand, be aware that callback functions registered with the `NNS_SndArcStrmStartEx2` or the `NNS_SndArcStrmPrepareEx2` functions are called from the stream thread.

It is not always necessary to finish supplying the waveform data within the callback function. However, the supplying of this data must be complete before that region is next played. Otherwise the proper audio will not be output.

## See Also

`NNS_SndStrmSetup, NNS_SndArcStrmStartEx2, NNS_SndArcStrmPrepareEx2`

## Revision History

2004/11/26 Extracted from description of the `NNS_SndStrmSetup` function.

CONFIDENTIAL