<streaming-audio-clip> ( audio-engine source generator buffer-count -- audio-clip/f )
Audio playback engine

Prev:streaming-audio-clip
Next:play-streaming-audio-clip ( audio-engine source generator buffer-count -- audio-clip/f )


Vocabulary
audio.engine

Inputs
audio-enginean audio-engine
sourcean object implementing the Audio source protocol
generatoran object implementing the Audio generator protocol
buffer-countan integer


Outputs
audio-clip/fan audio-clip or f


Word description
Constructs a streaming-audio-clip tied to source and playing audio generated by generator. buffer-count buffers will be allocated for the clip. The clip won't be played until play-clip or play-clips is called on it. The clip will automatically be disposed by the audio-engine when the generator stops supplying data and all the buffered data has played. The clip will in turn dispose its generator when it is disposed. If the engine has no available voices, no clip will be constructed, the generator will be disposed, and f will be returned.

Definition


:: <streaming-audio-clip>
( audio-engine source generator buffer-count -- audio-clip/f )
audio-engine get-available-source :> al-source al-source [
buffer-count dup uint (c-array) [ alGenBuffers ] keep
:> al-buffers generator generator-audio-format
:> ( channels sample-bits sample-rate )
streaming-audio-clip new-disposable audio-engine
>>audio-engine source >>source al-source >>al-source
generator >>generator channels >>channels
sample-bits >>sample-bits sample-rate >>sample-rate
al-buffers >>al-buffers :> clip al-buffers
[ clip swap queue-clip-buffer ] each
clip audio-engine clips>> push clip
] [ generator dispose f ] if ;