         } cleave
     ] with-destructors ;
 
-: read-vorbis-stream ( filename -- vorbis-stream )
-    binary <file-reader> <vorbis-stream> ; inline
+: read-vorbis-stream ( filename buffer-size -- vorbis-stream )
+    [ binary <file-reader> ] dip <vorbis-stream> ; inline
 
 M: vorbis-stream dispose*
     {

: get-pending-decoded-audio ( vorbis-stream -- pcm len )
    dsp-state>> f <void*> [ vorbis_synthesis_pcmout ] keep *void* swap ;

:: make-pcm-buffer ( vorbis-stream pcm len -- short-array )
    vorbis-stream info>> channels>> :> #channels
    pcm #channels <direct-void*-array> :> channel*s
    #channels len * <short-vector> :> output

    len iota [| sample |
        #channels iota [| channel |
            channel channel*s nth len <direct-float-array> :> samples
            sample samples nth
            -32767.0 * >integer -32767 32767 clamp
            output push
        ] each
    ] each
    output >short-array ; inline

: read-samples ( vorbis-stream pcm len -- )
    [ dsp-state>> ] [ drop ] [ ] tri* vorbis_synthesis_read drop ; inline

: queue-audio ( vorbis-stream -- ? )
    dup [ stream-state>> ] [ packet>> ] bi ogg_stream_packetout 0 > [

M: vorbis-stream generator-audio-format
    [ info>> channels>> ] [ drop 16 ] [ info>> rate>> ] tri ;
M: vorbis-stream generate-audio
    [ buffer>> ] [ 0 decode-audio ] bi ;
