For most voices, the entire buffer of samples in an audio file can be kept in memory for playback. However, keeping the entire audio file in memory for a single voice may be impractical in some cases. For instance, ten minutes of uncompressed music in 32KHz PCM16 format is over 50 MB in size. The standard way of handling such large audio files is streaming. By using streaming, any size audio file may be played with a relatively small buffer in RAM.
When playing an audio file, two sets of samples must be kept in RAM:
When streaming, pieces of an audio file are loaded only as they are needed, and then are discarded when they are no longer needed. The basic steps involved in streaming are as follows:
By streaming audio this way, an arbitrarily large audio file may be played without requiring more than two stream buffer blocks be loaded in to RAM at any given time. However, this benefit comes with a cost: the audio file must be accessed each time that a new block of samples must be loaded.
If a given voice has looping enabled and the playback reaches its
endOffset, then playback
continues at the
loopOffset does not need to be a point within
the same buffer that the voice was previously playing. Because of this, the
loopOffset of a
voice can be used to jump to an arbitrary location in memory.
The essential steps are as follows.
AXGetVoiceLoopCountto get the number of times the voice has looped. If the voice's loop count increased, then it has started to play the next stream buffer block. When this occurs, take the following steps:
endOffsetto be the ending offset of the newly playing stream buffer block.
loopOffsetfor the voice to the starting offset of the loaded stream buffer block.
AXSetVoiceType. For more information, see the Voice Type section in AX Overview.
AX_PB_TYPE_NORMAL. It is not necessary to perform this for PCM formats.
As a convenience, the SDK provides a library, streamlib, that implements the management of voice offsets as described above. To use it, applications need to supply stream buffer blocks periodically and call an update function once per audio frame.
Source for the library can be found among the SDK demos in the following directory:
Instructions for using streamlib can be found in the
file located in the above folder.
The SDK includes a few demo applications as examples of how to perform streaming on Cafe. These demos are located in the following folder:
axstream.c) is an example of streaming where streaming is performed with a static buffer.
axstream2.c) is a more advanced version of the axstream demo. The streaming loop points and buffers are managed dynamically during playback.
streamlib/streamdemo.hdemo demonstrates the use of streamlib to stream audio.
2013/05/08 Automated cleanup pass.
2013/02/18 Initial version.