Sha256: 3124dee9333c28ee64f752d0db2fde1fed148523753ace136b110d68e172626f

Contents?: true

Size: 1.34 KB

Versions: 5

Compression:

Stored size: 1.34 KB

Contents

module Mp3file
  class InvalidXingHeaderError < Mp3fileError; end

  class XingHeader
    attr_reader(:frames, :bytes, :toc, :quality)

    class XingHeaderFormat < BinData::Record
      string(:vbr_id, :length => 4, :check_value => lambda { value == 'Xing' })

      uint8(:unused1, :check_value => lambda { value == 0 })
      uint8(:unused2, :check_value => lambda { value == 0 })
      uint8(:unused3, :check_value => lambda { value == 0 })
      bit4(:unused4, :check_value => lambda { value == 0 })
      bit1(:quality_present)
      bit1(:toc_present)
      bit1(:bytes_present)
      bit1(:frames_present)

      uint32be(:frames, :onlyif => lambda { frames_present == 1 })
      uint32be(:bytes, :onlyif => lambda { bytes_present == 1 })
      array(:toc, :type => :uint8, :read_until => lambda { index == 99 }, :onlyif => lambda { toc_present == 1 })
      uint32be(:quality, :onlyif => lambda { quality_present == 1 })
    end

    def initialize(io)
      head = nil
      begin
        head = XingHeaderFormat.read(io)
      rescue BinData::ValidityError => ve
        raise InvalidXingHeaderError, ve.message
      end

      @frames = head.frames if head.frames_present == 1
      @bytes = head.bytes if head.bytes_present == 1
      @toc = head.toc.dup if head.toc_present == 1
      @quality = head.quality if head.quality_present == 1
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
mp3file-1.0.1 lib/mp3file/xing_header.rb
mp3file-1.0.0 lib/mp3file/xing_header.rb
mp3file-0.0.4 lib/mp3file/xing_header.rb
mp3file-0.0.3 lib/mp3file/xing_header.rb
mp3file-0.0.2 lib/mp3file/xing_header.rb