Class: WahWah::Flac::Block
- Inherits:
-
Object
- Object
- WahWah::Flac::Block
- Includes:
- LazyRead
- Defined in:
- lib/wahwah/flac/block.rb
Constant Summary collapse
- HEADER_SIZE =
4- HEADER_FORMAT =
'B*'- BLOCK_TYPE_INDEX =
%w(STREAMINFO PADDING APPLICATION SEEKTABLE VORBIS_COMMENT CUESHEET PICTURE)
Instance Attribute Summary collapse
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize ⇒ Block
constructor
A new instance of Block.
- #is_last? ⇒ Boolean
- #valid? ⇒ Boolean
Methods included from LazyRead
Constructor Details
#initialize ⇒ Block
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/wahwah/flac/block.rb', line 14 def initialize # Block header structure: # # Length(bit) Meaning # # 1 Last-metadata-block flag: # '1' if this block is the last metadata block before the audio blocks, '0' otherwise. # # 7 BLOCK_TYPE # 0 : STREAMINFO # 1 : PADDING # 2 : APPLICATION # 3 : SEEKTABLE # 4 : VORBIS_COMMENT # 5 : CUESHEET # 6 : PICTURE # 7-126 : reserved # 127 : invalid, to avoid confusion with a frame sync code # # 24 Length (in bytes) of metadata to follow # (does not include the size of the METADATA_BLOCK_HEADER) header_bits = @file_io.read(HEADER_SIZE).unpack(HEADER_FORMAT).first @last_flag = header_bits[0] @type = BLOCK_TYPE_INDEX[header_bits[1..7].to_i(2)] @size = header_bits[8..-1].to_i(2) end |
Instance Attribute Details
#type ⇒ Object (readonly)
Returns the value of attribute type.
12 13 14 |
# File 'lib/wahwah/flac/block.rb', line 12 def type @type end |
Instance Method Details
#is_last? ⇒ Boolean
46 47 48 |
# File 'lib/wahwah/flac/block.rb', line 46 def is_last? @last_flag.to_i == 1 end |
#valid? ⇒ Boolean
42 43 44 |
# File 'lib/wahwah/flac/block.rb', line 42 def valid? @size > 0 end |