flac-decoder
| (require "flac-decoder.rkt") | package: base |
This module provides a small decoder interface on top of the FLAC -FFI layer. It opens a decoder for a file, reads stream metadata, -reads audio frames, exposes the current decoder state, and allows -an active read loop to be stopped. It also re-exports the bindings -from "flac-definitions.rkt".
A decoder handle stores the native decoder handler together with -optional callbacks for stream metadata and decoded audio.
1 Procedures
procedure
(flac-open flac-file* cb-stream-info cb-audio) → (or/c flac-handle? #f) flac-file* : (or/c path? string?) cb-stream-info : (or/c procedure? #f) cb-audio : (or/c procedure? #f)
Otherwise a native decoder handler is created with -flac-ffi-decoder-handler, initialized with the file, and -wrapped in a flac-handle. The given callbacks are stored -in the handle.
When metadata of type 'streaminfo is processed and -cb-stream-info is a procedure, it is called with a -flac-stream-info value.
When decoded audio data is processed and cb-audio is a -procedure, it is called as -(cb-audio header buffers), where header is a -mutable hash containing the frame header fields plus -'duration, and buffers is the decoded channel -data returned by the FFI layer.
Before reading starts, the handle fields stop-reading -and reading are set to #f and #t. If a -stop has been requested with flac-stop, reading ends -with 'stopped-reading and reading is reset to -#f.
Whenever pending metadata is available, it is processed with -process-meta. For metadata of type -'streaminfo, a flac-stream-info value is -constructed, stored in the handle, and passed to the -stream-info callback.
Whenever pending frame data is available, it is processed with -process-frame. The frame header is converted to a -mutable hash, extended with a 'duration entry taken -from flac-duration, and passed together with the -decoded buffers to the audio callback.
For each processed frame, the module also updates -last-buffer, last-buf-len, and kinds.
The procedure prints diagnostic messages for state changes, -metadata, stream errors, and stop handling.
If the resulting state is 'read-metadata, pending -metadata is processed and the stored stream info is returned. -Otherwise the result is #f.
Only metadata of type 'streaminfo is converted into a -flac-stream-info value by this module.
procedure
(flac-stop handle) → void?
handle : flac-handle?
The procedure prints timing information before and after the -wait.
2 Diagnostic bindings
value
kinds : hash?
value
last-buffer : (or/c #f list?)
value
last-buf-len : (or/c #f exact-integer?)
3 Notes
The frame-header hash passed to the audio callback is produced -by flac-ffi-frame-header. In this module it is extended -with a 'duration field before the callback is called.
All bindings from "flac-definitions.rkt" are -re-exported.