             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
 

    audio-clip [ size + ] change-next-data-offset drop ; inline

:: queue-clip-buffer ( audio-clip al-buffer -- )
    audio-clip audio-engine>> :> audio-engine
    audio-engine buffer-size>> :> buffer-size
    audio-clip audio>> :> audio
    audio-clip next-data-offset>> :> next-data-offset
    audio size>> next-data-offset - :> remaining-audio

    {
        { [ remaining-audio 0 <= ] [
            audio-clip loop?>> [
                audio-clip 0 >>next-data-offset
                al-buffer queue-clip-buffer
            ] when
        ] }
        { [ remaining-audio buffer-size < ] [
            audio-clip loop?>> [
                audio data>>
                [ next-data-offset swap <displaced-alien> remaining-audio <direct-uchar-array> ]
                [ buffer-size remaining-audio - <direct-uchar-array> ] bi append :> data
                audio-clip al-buffer audio data buffer-size (queue-clip-buffer)

                audio-clip [ audio size>> mod ] change-next-data-offset drop
            ] [
                next-data-offset audio data>> <displaced-alien> :> data
                audio-clip al-buffer audio data remaining-audio (queue-clip-buffer)
            ] if
        ] }
        [
            next-data-offset audio data>> <displaced-alien> :> data
            audio-clip al-buffer audio data buffer-size (queue-clip-buffer)
        ]
    } cond ;

: update-listener ( audio-engine -- )
    listener>> {

: allocate-sources ( audio-engine -- sources )
    voice-count>> dup (uint-array) [ alGenSources ] keep ; inline

:: flush-source ( al-source -- )
    al-source alSourceStop
    0 c:<uint> :> dummy-buffer
    al-source AL_BUFFERS_PROCESSED get-source-param [
        al-source 1 dummy-buffer alSourceUnqueueBuffers
    ] times
    al-source AL_BUFFER 0 alSourcei ;

: free-sources ( sources -- )
    [ length ] keep alDeleteSources ; inline
