source: extensions/gsdl-video/trunk/installed/cmdline/lib/ruby/site_ruby/1.8/flv/audio_tag.rb@ 18425

Last change on this file since 18425 was 18425, checked in by davidb, 15 years ago

Video extension to Greenstone

File size: 3.0 KB
Line 
1# Copyright (c) 2005 Norman Timmler (inlet media e.K., Hamburg, Germany)
2# All rights reserved.
3#
4# Redistribution and use in source and binary forms, with or without
5# modification, are permitted provided that the following conditions
6# are met:
7# 1. Redistributions of source code must retain the above copyright
8# notice, this list of conditions and the following disclaimer.
9# 2. Redistributions in binary form must reproduce the above copyright
10# notice, this list of conditions and the following disclaimer in the
11# documentation and/or other materials provided with the distribution.
12# 3. The name of the author may not be used to endorse or promote products
13# derived from this software without specific prior written permission.
14#
15# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
26
27module FLV
28
29 class FLVAudioTag < FLVTag
30
31 UNCOMPRESSED = 0
32 ADPCM = 1
33 MP3 = 2
34 NELLYMOSER8KHZMONO = 5
35 NELLYMOSER = 6
36
37 MONO = 0
38 STEREO = 1
39
40 attr_reader :sound_format,
41 :sound_rate,
42 :sound_sample_size,
43 :sound_type
44
45 def after_initialize(new_object)
46 @tag_type = AUDIO
47 read_header
48 end
49
50 def name
51 'Audio Tag'
52 end
53
54 def read_header
55 data_stream = AMFStringBuffer.new(@data)
56 bit_sequence = data_stream.read__STRING(1).unpack('B8').to_s
57
58 @sound_format = bit2uint(bit_sequence[0,4])
59 @sound_rate = case bit2uint(bit_sequence[4,2])
60 when 0
61 5500
62 when 1
63 11000
64 when 2
65 22000
66 when 3
67 44000
68 end
69 @sound_sample_size = case bit2uint(bit_sequence[6,1])
70 when 0
71 8
72 when 1
73 16
74 end
75 @sound_type = bit2uint(bit_sequence[7,1])
76
77 # Nellymoser 8kHz mono special case
78 if @sound_format == NELLYMOSER8KHZMONO
79 @sound_rate = 8000
80 @sound_type = MONO
81 end
82 end
83
84 def inspect
85 out = super
86 out << "sound_format: #{['Uncompressed', 'ADPCM', 'MP3', nil, nil, 'Nellymoser 8KHz mono', 'Nellymoser'][@sound_format]}"
87 out << "sound_rate: #{@sound_rate}"
88 out << "sound_sample_size: #{@sound_sample_size}"
89 out << "sound_type: #{['Mono', 'Stereo'][@sound_type]}"
90 out
91 end
92 end
93end
Note: See TracBrowser for help on using the repository browser.