<static-audio-clip> ( audio-engine source audio loop? -- audio-clip/f )
Audio playback engine

Next:play-static-audio-clip ( audio-engine source audio loop? -- audio-clip/f )


audio-enginean audio-engine
sourcean object implementing the Audio source protocol
audioan audio
loop?a boolean

audio-clip/fan audio-clip or f

Word description
Constructs a static-audio-clip tied to source and playing audio generated by generator. The clip won't be played until play-clip or play-clips is called on it. If loop? is true, the clip will repeat indefinitely when played until stopped with stop-clip. Otherwise, the clip will automatically be disposed by the audio-engine after it finishes playing. If the engine has no available voices, no clip will be constructed, and f will be returned.


:: <static-audio-clip>
( audio-engine source audio loop? -- audio-clip/f )
audio-engine get-available-source :> al-source al-source [
1 0 uint <ref> [ alGenBuffers ] keep uint deref
:> al-buffer al-buffer audio {
[ openal-format ]
[ data>> ]
[ size>> ]
[ sample-rate>> ]
} cleave alBufferData
al-source AL_BUFFER al-buffer alSourcei
al-source AL_LOOPING loop? >c-bool alSourcei
static-audio-clip new-disposable audio-engine
>>audio-engine source >>source al-source >>al-source
al-buffer >>al-buffer
:> clip clip audio-engine clips>> push clip
] [ f ] if ;