Class: WahWah::Mp3::XingHeader

Inherits:
Object
  • Object
show all
Defined in:
lib/wahwah/mp3/xing_header.rb

Overview

Xing header structure:

Position Length Meaning 0 4 VBR header ID in 4 ASCII chars, either ‘Xing’ or ‘Info’,

not NULL-terminated

4 4 Flags which indicate what fields are present,

flags are combined with a logical OR. Field is mandatory.

0x0001 - Frames field is present
0x0002 - Bytes field is present
0x0004 - TOC field is present
0x0008 - Quality indicator field is present

8 4 Number of Frames as Big-Endian 32-bit unsigned (optional)

8 or 12 4 Number of Bytes in file as Big-Endian 32-bit unsigned (optional)

8,12 or 16 100 100 TOC entries for seeking as integral BYTE (optional)

8,12,16,108,112 or 116 4 Quality indicator as Big-Endian 32-bit unsigned

from 0 - best quality to 100 - worst quality (optional)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_io, offset = 0) ⇒ XingHeader

Returns a new instance of XingHeader.



30
31
32
33
34
35
36
37
38
# File 'lib/wahwah/mp3/xing_header.rb', line 30

def initialize(file_io, offset = 0)
  file_io.seek(offset)

  @id, @flags = file_io.read(8)&.unpack("A4N")
  return unless valid?

  @frames_count = @flags & 1 == 1 ? file_io.read(4).unpack1("N") : 0
  @bytes_count = @flags & 2 == 2 ? file_io.read(4).unpack1("N") : 0
end

Instance Attribute Details

#bytes_countObject (readonly)

Returns the value of attribute bytes_count.



28
29
30
# File 'lib/wahwah/mp3/xing_header.rb', line 28

def bytes_count
  @bytes_count
end

#frames_countObject (readonly)

Returns the value of attribute frames_count.



28
29
30
# File 'lib/wahwah/mp3/xing_header.rb', line 28

def frames_count
  @frames_count
end

Instance Method Details

#valid?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/wahwah/mp3/xing_header.rb', line 40

def valid?
  %w[Xing Info].include? @id
end