Class: FLV::FLVAudioTag

Inherits:
FLVTag
  • Object
show all
Defined in:
lib/flv/audio_tag.rb

Constant Summary collapse

UNCOMPRESSED =
0
ADPCM =
1
MP3 =
2
NELLYMOSER8KHZMONO =
5
NELLYMOSER =
6
MONO =
0
STEREO =
1

Constants inherited from FLVTag

FLV::FLVTag::AUDIO, FLV::FLVTag::META, FLV::FLVTag::UNDEFINED, FLV::FLVTag::VIDEO

Instance Attribute Summary collapse

Attributes inherited from FLVTag

#byte_offset, #tag_type, #timestamp

Instance Method Summary collapse

Methods inherited from FLVTag

#data, #data_size, #info, #initialize, #serialize, #size, type2name

Constructor Details

This class inherits a constructor from FLV::FLVTag

Instance Attribute Details

#sound_formatObject (readonly)

Returns the value of attribute sound_format.



40
41
42
# File 'lib/flv/audio_tag.rb', line 40

def sound_format
  @sound_format
end

#sound_rateObject (readonly)

Returns the value of attribute sound_rate.



40
41
42
# File 'lib/flv/audio_tag.rb', line 40

def sound_rate
  @sound_rate
end

#sound_sample_sizeObject (readonly)

Returns the value of attribute sound_sample_size.



40
41
42
# File 'lib/flv/audio_tag.rb', line 40

def sound_sample_size
  @sound_sample_size
end

#sound_typeObject (readonly)

Returns the value of attribute sound_type.



40
41
42
# File 'lib/flv/audio_tag.rb', line 40

def sound_type
  @sound_type
end

Instance Method Details

#after_initialize(new_object) ⇒ Object



45
46
47
48
# File 'lib/flv/audio_tag.rb', line 45

def after_initialize(new_object)
  @tag_type = AUDIO
  read_header
end

#inspectObject



84
85
86
87
88
89
90
91
# 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

#nameObject



50
51
52
# File 'lib/flv/audio_tag.rb', line 50

def name
  'Audio Tag'
end

#read_headerObject



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# 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