Easy Audio ยป FLAC

To read and decode FLAC file or stream you need to follow these steps:
  1. Open a FLAC file/Get a stream with element type (unsigned-byte 8).
  2. Pass the stream to flac:open-flac function which will create and return bitreader:reader object. This object allows easy-audio library to read not just octets, but any amount of bits from audio stream.
  3. Read metadata blocks from the stream, passing the object from previous step to flac:read-metadata.
  4. Do whatever you want with metadata and read the first audio frame with flac:read-frame.
  5. Decode the frame with flac:frame-decode and repeat previous step until all data is read and decoded.
NB: You can reduce consing when reading frames by binding flac:*out-buffers* variable with buffers returned by flac:make-output-buffers.

API

Conditions.
flac-error
General (unspecified) flac error
    flac-bad-metadata
    Flac metadata error
    • metadata
      Current metadata
      OptionValue
      Allocation:instance
      Type:nil
      Initarg::metadata
      Readers:(flac-metadata)
    flac-bad-frame
    Bad flac frame
      Metadata blocks. Please note, that slot accessors are not documented here, but usually available by scheme CLASSNAME-SLOTNAME.
      streaminfo
      OptionValue
      Superclasses:(metadata-header t)
      Metaclass:standard-class
      Default Initargs:nil
      Class for storing STREAMINFO metadata block
      • minblocksize
        The minimum block size (in samples) used in the stream
        OptionValue
        Allocation:instance
        Type:alexandria:non-negative-fixnum
        Accessors:(streaminfo-minblocksize)
      • maxblocksize
        The maximum block size (in samples) used in the stream
        OptionValue
        Allocation:instance
        Type:alexandria:non-negative-fixnum
        Accessors:(streaminfo-maxblocksize)
      • minframesize
        The minimum frame size (in bytes) used in the stream
        OptionValue
        Allocation:instance
        Type:alexandria:non-negative-fixnum
        Accessors:(streaminfo-minframesize)
      • maxframesize
        The maximum frame size (in bytes) used in the stream. May be 0 to imply the value is not known.
        OptionValue
        Allocation:instance
        Type:alexandria:non-negative-fixnum
        Accessors:(streaminfo-maxframesize)
      • samplerate
        Sample rate in Hz
        OptionValue
        Allocation:instance
        Type:alexandria:non-negative-fixnum
        Accessors:(streaminfo-samplerate)
      • channels
        Number of channels in stream. May be from 1 to 8.
        OptionValue
        Allocation:instance
        Type:(integer 1 8)
        Accessors:(streaminfo-channels)
      • bitspersample
        Bits per sample (from 4 to 32)
        OptionValue
        Allocation:instance
        Type:alexandria:non-negative-fixnum
        Accessors:(streaminfo-bitspersample)
      • totalsamples
        Total samples in stream. May be 0 if unknown.
        OptionValue
        Allocation:instance
        Type:alexandria:positive-integer
        Accessors:(streaminfo-totalsamples)
      • md5
        MD5 checksum of the whole unencoded data
        OptionValue
        Allocation:instance
        Type:nil
        Accessors:(streaminfo-md5)
      seektable
      OptionValue
      Superclasses:(metadata-header t)
      Metaclass:standard-class
      Default Initargs:nil
      SEEKTABLE metadata block
      • seekpoints
        List of seekpoints
        OptionValue
        Allocation:instance
        Type:list
        Accessors:(seektable-seekpoints)
      seekpoint
      OptionValue
      Constructor:make-seekpoint
      Predicate:seekpoint-p
      Copier:copy-seekpoint
      A seekpoint (entry in seektable)
      • samplenum
        OptionValue
        Type:(easy-audio.core:ub 64)
        Read Only:nil
        Accessor:easy-audio.flac:seekpoint-samplenum
        Initform:0
      • offset
        OptionValue
        Type:(easy-audio.core:ub 64)
        Read Only:nil
        Accessor:easy-audio.flac:seekpoint-offset
        Initform:0
      • samples-in-frame
        OptionValue
        Type:(easy-audio.core:ub 16)
        Read Only:nil
        Accessor:easy-audio.flac:seekpoint-samples-in-frame
        Initform:0
      vorbis-comment
      OptionValue
      Superclasses:(metadata-header t)
      Metaclass:standard-class
      Default Initargs:nil
      VORBIS_COMMENT metadata block
      • vendor-comment
        Vendor comment
        OptionValue
        Allocation:instance
        Type:string
        Accessors:(vorbis-vendor-comment)
      • user-comments
        List of user comments
        OptionValue
        Allocation:instance
        Type:list
        Accessors:(vorbis-user-comments)
      cuesheet
      OptionValue
      Superclasses:(metadata-header t)
      Metaclass:standard-class
      Default Initargs:nil
      CUESHEET metadata block
      • catalog-id
        Media catalog number
        OptionValue
        Allocation:instance
        Type:string
        Accessors:(cuesheet-catalog-id)
      • lead-in
        For CD-DA cuesheets, number of lead-in samples; 0 otherwise
        OptionValue
        Allocation:instance
        Type:nil
        Accessors:(cuesheet-lead-in)
      • cdp
        t if cueshhet corresponds to Compact Disk
        OptionValue
        Allocation:instance
        Type:boolean
        Accessors:(cuesheet-cdp)
      • tracks
        List of tracks
        OptionValue
        Allocation:instance
        Type:list
        Accessors:(cuesheet-tracks)
      picture
      OptionValue
      Superclasses:(metadata-header t)
      Metaclass:standard-class
      Default Initargs:nil
      PICTURE metadata block
      • picture-type
        One of 21 picture types (see flac format description)
        OptionValue
        Allocation:instance
        Type:easy-audio.flac::picture-type-id
        Accessors:(picture-type)
      • mime-type
        String with MIME type
        OptionValue
        Allocation:instance
        Type:string
        Accessors:(picture-mime-type)
      • description
        Picture description (UTF-8 coded string)
        OptionValue
        Allocation:instance
        Type:string
        Accessors:(picture-description)
      • width
        Picture width
        OptionValue
        Allocation:instance
        Type:alexandria:positive-integer
        Accessors:(picture-width)
      • height
        Picture height
        OptionValue
        Allocation:instance
        Type:alexandria:positive-integer
        Accessors:(picture-height)
      • depth
        Picture color depth
        OptionValue
        Allocation:instance
        Type:alexandria:positive-integer
        Accessors:(picture-depth)
      • color-num
        Number of colors in indexed picture, 0 for non-indexed
        OptionValue
        Allocation:instance
        Type:alexandria:non-negative-integer
        Accessors:(picture-color-num)
      • picture
        The picture itself as array of octets
        OptionValue
        Allocation:instance
        Type:(easy-audio.core:sa-ub 8)
        Accessors:(picture-picture)
      Working with audio frames.
      frame
      OptionValue
      Superclasses:(t)
      Metaclass:standard-class
      Default Initargs:nil
      Audio frame class
      • blocking-strategy
        Is the blocking strategy :FIXED (frame header contains the frame number) or :VARIABLE (frame header contains the sample number)
        OptionValue
        Allocation:instance
        Type:(member :fixed :variable)
        Readers:(frame-blocking-strategy)
      • block-size
        Block size in samples
        OptionValue
        Allocation:instance
        Type:alexandria:non-negative-fixnum
        Readers:(frame-block-size)
      • sample-rate
        Sample rate
        OptionValue
        Allocation:instance
        Type:alexandria:non-negative-fixnum
        Readers:(frame-sample-rate)
      • channel-assignment
        Number of channels or one of :mid/side, :left/side, :right/side
        OptionValue
        Allocation:instance
        Type:(integer 0 10)
        Readers:(frame-channel-assignment)
      • sample-size
        Bits per sample
        OptionValue
        Allocation:instance
        Type:(integer 4 32)
        Readers:(frame-sample-size)
      • number
        Frame/sample number
        OptionValue
        Allocation:instance
        Type:unsigned-byte
        Initform:68719476736
        Readers:(frame-number)
      • crc-8
        CRC8 of a frame header (including the sync code)
        OptionValue
        Allocation:instance
        Type:(easy-audio.core:ub 8)
        Accessors:(frame-crc-8)
      • subframes
        List of subframes (one for each channel)
        OptionValue
        Allocation:instance
        Type:list
        Accessors:(frame-subframes)
      • crc-16
        CRC16 of the frame (back to and including the sync code)
        OptionValue
        Allocation:instance
        Type:fixnum
        Accessors:(frame-crc-16)
      read-frame(stream &optional streaminfo)
      Read a frame from a stream
      frame-decode(frame)
      Decode a frame destructively modifying (and garbaging) all subframes within. Returns list of decoded audio buffers (one buffer for each channel).
      Other functions / helpers.
      open-flac(stream)
      Return bitreader handler of flac stream
      read-metadata(bitreader)
      Return list of metadata blocks in the stream
      seek-sample(bitreader sample &key seektable streaminfo)
      Seeks to an interchannel sample. Sets input to new frame, which contains this sample. Returns position of this sample in the frame. seektable and streaminfo are optional. Providing streaminfo enables additional sanity checks. Currently only fixed block size is supported.
      metadata-find-seektable(metadata)
      Return a seektable from metadata list if any
      make-output-buffers(streaminfo)
      Make output buffers for binding with *output-buffers* to reduce consing
      with-output-buffers((streaminfo) &body body)
      Calls to READ-FRAME can be made inside this macro to avoid unnecessary consing if flac stream is of fixed block size
      It also can decode FLAC data from OGG container. There are flac:open-ogg-flac, flac:read-ogg-metadata and flac:read-ogg-frame functions for that purpose. Seeking does not work with OGG container.