Class: WahWah::Ogg::VorbisTag

Inherits:
Object
  • Object
show all
Includes:
VorbisComment
Defined in:
lib/wahwah/ogg/vorbis_tag.rb

Constant Summary

Constants included from VorbisComment

WahWah::Ogg::VorbisComment::COMMET_FIELD_MAPPING

Instance Method Summary collapse

Methods included from VorbisComment

#parse_vorbis_comment

Constructor Details

#initialize(identification_packet, comment_packet) ⇒ VorbisTag

Returns a new instance of VorbisTag.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/wahwah/ogg/vorbis_tag.rb', line 10

def initialize(identification_packet, comment_packet)
  # Identification packet structure:
  #
  # 1) "\x01vorbis"
  # 2) [vorbis_version] = read 32 bits as unsigned integer
  # 3) [audio_channels] = read 8 bit integer as unsigned
  # 4) [audio_sample_rate] = read 32 bits as unsigned integer
  # 5) [bitrate_maximum] = read 32 bits as signed integer
  # 6) [bitrate_nominal] = read 32 bits as signed integer
  # 7) [bitrate_minimum] = read 32 bits as signed integer
  # 8) [blocksize_0] = 2 exponent (read 4 bits as unsigned integer)
  # 9) [blocksize_1] = 2 exponent (read 4 bits as unsigned integer)
  # 10) [framing_flag] = read one bit
  @sample_rate, bitrate = identification_packet[12, 12].unpack("Vx4V")
  @bitrate = bitrate / 1000

  comment_packet_id, comment_packet_body = [comment_packet[0..6], comment_packet[7..]]

  # Vorbis comment packet start with "\x03vorbis"
  return unless comment_packet_id == "\x03vorbis"

  parse_vorbis_comment(comment_packet_body)
end