class FLV::FLVAudioTag

Constants

ADPCM
MONO
MP3
NELLYMOSER
NELLYMOSER8KHZMONO
STEREO
UNCOMPRESSED

Attributes

sound_format[R]
sound_rate[R]
sound_sample_size[R]
sound_type[R]

Public Instance Methods

after_initialize(new_object) click to toggle source
# File lib/flv/audio_tag.rb, line 45
def after_initialize(new_object)
  @tag_type = AUDIO
  read_header
end
inspect() click to toggle source
Calls superclass method
# File lib/flv/audio_tag.rb, line 84
def inspect
  out = super
  out << "sound_format: #{['Uncompressed', 'ADPCM', 'MP3', nil, nil, 'Nellymoser 8KHz mono', 'Nellymoser'][@sound_format]}"
  out << "sound_rate: #{@sound_rate}"
  out << "sound_sample_size: #{@sound_sample_size}"
  out << "sound_type: #{['Mono', 'Stereo'][@sound_type]}"
  out
end
name() click to toggle source
# File lib/flv/audio_tag.rb, line 50
def name
  'Audio Tag'
end
read_header() click to toggle source
# File lib/flv/audio_tag.rb, line 54
def read_header
  data_stream = AMFStringBuffer.new(@data)
  bit_sequence = data_stream.read__STRING(1).unpack('B8').to_s
  
  @sound_format = bit2uint(bit_sequence[0,4])
  @sound_rate = case bit2uint(bit_sequence[4,2])
  when 0
    5500
  when 1
    11000
  when 2
    22000
  when 3
    44000
  end
  @sound_sample_size = case bit2uint(bit_sequence[6,1])
  when 0
    8
  when 1
    16
  end
  @sound_type = bit2uint(bit_sequence[7,1])

  # Nellymoser 8kHz mono special case

  if @sound_format == NELLYMOSER8KHZMONO
    @sound_rate = 8000
    @sound_type = MONO
  end
end