Class: FLV::Audio

Inherits:
String
  • Object
show all
Includes:
Body
Defined in:
lib/flvedit/flv/audio.rb

Overview

The body of an audio tag. The data is quite complex stuff. We make no attempt to understand it all or to be able to modify any of it. We simply consider it a complex string and read the interesting bits to give more info.

Constant Summary collapse

FORMATS =
Hash.new{|h, key| "Unknown audio format: #{key}"}.merge!(
  0  => :"Linear PCM, platform endian"  ,
  1  => :ADPCM                          ,
  2  => :MP3                            ,
  3  => :"Linear PCM, little endian"    ,
  4  => :"Nellymoser 16-kHz mono"       ,
  5  => :"Nellymoser 8-kHz mono"        ,
  6  => :Nellymoser                     ,
  7  => :"G.711 A-law logarithmic PCM"  ,
  8  => :"G.711 mu-law logarithmic PCM" ,
  10 => :AAC                            ,
  11 => :Speex                          ,
  14 => :"MP3 8-kHz"                    ,
  15 => :"Device-specific sound"
).freeze
EXCEPTIONS =
Hash.new({}).merge(
  :"Nellymoser 8-kHz mono"  => {:channel => :mono,  :rate => 8000},
  :"Nellymoser 16-kHz mono" => {:channel => :mono,  :rate => 16000},
  :AAC                      => {:channel => :stereo,:rate => 44000},
  :"MP3 8-kHz"              => {:rate => 8000}
).freeze
CHANNELS =
{
  0 => :mono,
  1 => :stereo
}.freeze

Instance Method Summary collapse

Methods included from Body

included

Instance Method Details

#channelObject

returns :mono or :stereo



47
48
49
50
# File 'lib/flvedit/flv/audio.rb', line 47

def channel
  EXCEPTIONS[format][:channel] ||
    CHANNELS[read_bits(7)]
end

#codec_idObject



37
38
39
# File 'lib/flvedit/flv/audio.rb', line 37

def codec_id
  read_bits(0..3)
end

#formatObject

Returns the format (see Audio::FORMATS for list)



42
43
44
# File 'lib/flvedit/flv/audio.rb', line 42

def format
  FORMATS[codec_id]
end

#is?(what) ⇒ Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/flvedit/flv/audio.rb', line 64

def is?(what)
  format.to_s.downcase == what.to_s.downcase || super
end

#rateObject

Returns the sampling rate (in Hz)



53
54
55
56
# File 'lib/flvedit/flv/audio.rb', line 53

def rate
  EXCEPTIONS[format][:rate] ||
    5500 << read_bits(4..5)
end

#sample_sizeObject

Returns the sample size (in bits)



59
60
61
62
# File 'lib/flvedit/flv/audio.rb', line 59

def sample_size
  EXCEPTIONS[format][:sample_size] ||
    8 << read_bits(6)
end