diff --git a/flac-decoder.rkt b/flac-decoder.rkt index 8ff7a90..4dccf82 100644 --- a/flac-decoder.rkt +++ b/flac-decoder.rkt @@ -171,14 +171,21 @@ (define (flac-stop handle) (let ((ct (current-milliseconds))) (dbg-sound "requesting stop at: ~a" ct) - (set-flac-handle-stop-reading! handle #t) - (while (flac-handle-reading handle) - (sleep 0.01)) + (if (flac-handle-reading handle) + (begin ; in reading + (set-flac-handle-stop-reading! handle #t) + (while (flac-handle-reading handle) + (sleep 0.01))) + (begin ; never starte reading, or reading finished + (dbg-sound "not reading flac, need to finish flac") + (let ((ffi-handler (flac-handle-ffi-decoder-handler handle))) + (unless (eq? ffi-handler #f) + (ffi-handle 'delete)))) + ) (let ((ct* (current-milliseconds))) (dbg-sound "stop came back at: ~a" ct*) (dbg-sound "flac-stop took: ~a ms" (- ct* ct))) ) ) - ); end of module