Class: FLV::Audio
- Inherits:
-
String
- Object
- String
- FLV::Audio
- 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
-
#channel ⇒ Object
returns :mono or :stereo.
- #codec_id ⇒ Object
-
#format ⇒ Object
Returns the format (see Audio::FORMATS for list).
- #is?(what) ⇒ Boolean
-
#rate ⇒ Object
Returns the sampling rate (in Hz).
-
#sample_size ⇒ Object
Returns the sample size (in bits).
Methods included from Body
Instance Method Details
#channel ⇒ Object
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_id ⇒ Object
37 38 39 |
# File 'lib/flvedit/flv/audio.rb', line 37 def codec_id read_bits(0..3) end |
#format ⇒ Object
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
64 65 66 |
# File 'lib/flvedit/flv/audio.rb', line 64 def is?(what) format.to_s.downcase == what.to_s.downcase || super end |
#rate ⇒ Object
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_size ⇒ Object
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 |