             voice-count >>voice-count
             al-device >>al-device
             al-context >>al-context
-            buffer-size >>buffer-size
-            buffer-count >>buffer-count
     ] with-destructors ;
 
 : <standard-audio-engine> ( -- engine )
-    f 16 8192 2 <audio-engine> ;
+    f 16 <audio-engine> ;
 
 <PRIVATE
 

    [ [ alcCloseDevice*   ] when* f ] change-al-device
    drop ;

:: (audio-clip) ( audio-engine audio source loop? -- audio-clip/f )
    audio-engine get-available-source :> al-source

    al-source [
        audio-engine buffer-count>> :> buffer-count
        buffer-count dup (uint-array) [ alGenBuffers ] keep :> al-buffers

        audio-clip new-disposable
            audio-engine >>audio-engine
            audio >>audio
            source >>source
            loop? >>loop?
            al-source >>al-source
            al-buffers >>al-buffers
            0 >>next-data-offset :> clip
        al-buffers [ clip swap queue-clip-buffer ] each
        clip audio-engine clips>> push

        clip
    ] [ f ] if ;

M: audio-clip dispose*
    {
        [ al-source>> flush-source ]
        [ al-buffers>> [ length ] keep alDeleteBuffers ]
        [ dup audio-engine>> clips>> remove! drop ]
    } cleave ;

: play-clip ( audio-clip -- )
    [ update-source ]


TUPLE: audio-clip < disposable
    { audio-engine audio-engine }
    source
    { al-source integer } ;

TUPLE: static-audio-clip < audio-clip
    { al-buffer integer } ;

TUPLE: streaming-audio-clip < audio-clip
    generator
    { buffer-size integer }
    { channels integer }
    { sample-bits integer }
    { sample-rate integer }
    { al-buffers uint-array } ;

ERROR: audio-device-not-found device-name ;
ERROR: audio-context-not-available device-name ;

:: <audio-engine> ( device-name voice-count -- engine )
    [
        device-name alcOpenDevice :> al-device
        al-device [ device-name audio-device-not-found ] unless
