Play / Stop

Play

In order to reproduce a sound, it is necessary to initialize the system and load the data to playback.
This is done on the program side.

craftv2_tips_program_doing_playstop00.png

To play the loaded data, the program sets and starts the Cue on the Player.

When the Cue is started, the sequence created on the data side is controlled by the ADX run-time and the playback of the waveforms in the sequence is performed.

In-Memory Playback

Since the data to be played is already in memory, playback is always started within the initial server processing after the call of the Start function. Playback will be started with a minimal latency.
This consumes a lot of memory, but all the playback data is contained in the ACB file, making memory management easy.
If there is enough memory available (for example for a simple game) the ideal solution is to play all sounds in-memory.
However, usually songs and long-duration audio data that is rarely played back, should be configured for streaming playback to save resources.

craftv2_tips_program_doing_playstop07.png

Streaming Playback

Streaming playback sequentially reads blocks of data from a storage media and plays them. Therefore, although reading buffers are necessary, they don't need to be big enough to contain the whole data.
Also, unlike with in-memory playback, playback can not be started without delay (i.e. in the next server processing right after the call of the Start function).

In the case of streaming playback, access to the playback data file starts within the initial server processing after the Start function. Therefore, there will be a delay before playback, until a sufficient amount of audio data has been read.

craftv2_tips_program_doing_playstop08.png

Preparing the stream and resuming it

If you know the timing of the playback in advance, you can prepare the Cue - putting it in pause - and resume it later to avoid any latency. With this method, the first audio buffers are read while the Cue is prepared/paused and when you resume it, the Cue is played without the delay usually due to streaming.
It is possible to know when the playback preparation is done by checking the player's status. If you resume before the preparation is finished, the playback will be performed as soon as it is completed.

By default, playback preparation only works on waveforms placed at the beginning of a sequence. If you wish to prepare waveforms other than the first ones, please set the sequence prefetch time separately. Also, because of the preparation step, the resources necessary for playback are secured ahead of playback, at the start of preparation process. For this reason, this technique is not compatible with automatic limiting (at the Cue and the Voice levels) at playback.

craftv2_tips_program_doing_playstop05.png

How to reduce the delay due to streaming playback in the middle of a sequence

By calling the criAtomExPlayer_SetSequencePrepareTime function on a player, it is possible to prefetch the sequence for the specified time.
By performing prefetching, it becomes possible to eliminate or reduce delays even for streaming playback requests emanating from the middle of a sequence.
However, this technique is not compatible with automatic limiting at playback time.

craftv2_tips_program_doing_playstop06.png

Stop

A one-shot sound automatically stops after playback is completed. However, in the case of a looping sound, the playback will continue until it is stopped by a call to the Stop function (or by another processing such as voice limiting or a Stop action.)
In order to stop the sound from being played on the Player at any time, call the Stop function on the Player.

craftv2_tips_program_doing_playstop01.png

Seeking Playback

You can specify at which position in the audio data to start the playback.
Even if the specified position is in the middle of the waveform, playback will start from that position.

craftv2_tips_program_doing_playstop02.png

Block Playback

You can specify the starting block of the block sequence data and play it.
If you specify a destination block during the playback of block sequence data, the current block will switch to the new one at the next transition point.

craftv2_tips_program_doing_playstop03.png

Playback from data other than CueSheets

Although it is limited to simple cases, playback is possible by specifying file names or memory addresses of data in the ADX, HCA, WAV, AIFF etc. formats.
Also, the data can come from another source such as encoding at runtime and input from a microphone.

craftv2_tips_program_doing_playstop04.png