Class: WahWah::Mp3::VbriHeader

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

Overview

VBRI header structure:

Position Length Meaning 0 4 VBR header ID in 4 ASCII chars, always ‘VBRI’, not NULL-terminated

4 2 Version ID as Big-Endian 16-bit unsigned

6 2 Delay as Big-Endian float

8 2 Quality indicator

10 4 Number of Bytes as Big-Endian 32-bit unsigned

14 4 Number of Frames as Big-Endian 32-bit unsigned

18 2 Number of entries within TOC table as Big-Endian 16-bit unsigned

20 2 Scale factor of TOC table entries as Big-Endian 32-bit unsigned

22 2 Size per table entry in bytes (max 4) as Big-Endian 16-bit unsigned

24 2 Frames per table entry as Big-Endian 16-bit unsigned

26 TOC entries for seeking as Big-Endian integral.

From size per table entry and number of entries,
you can calculate the length of this field.

Constant Summary collapse

HEADER_SIZE =
32
HEADER_FORMAT =
"A4x6NN"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_io, offset = 0) ⇒ VbriHeader

Returns a new instance of VbriHeader.



37
38
39
40
# File 'lib/wahwah/mp3/vbri_header.rb', line 37

def initialize(file_io, offset = 0)
  file_io.seek(offset)
  @id, @bytes_count, @frames_count = file_io.read(HEADER_SIZE)&.unpack(HEADER_FORMAT)
end

Instance Attribute Details

#bytes_countObject (readonly)

Returns the value of attribute bytes_count.



35
36
37
# File 'lib/wahwah/mp3/vbri_header.rb', line 35

def bytes_count
  @bytes_count
end

#frames_countObject (readonly)

Returns the value of attribute frames_count.



35
36
37
# File 'lib/wahwah/mp3/vbri_header.rb', line 35

def frames_count
  @frames_count
end

Instance Method Details

#valid?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/wahwah/mp3/vbri_header.rb', line 42

def valid?
  @id == "VBRI"
end