Class: Zappa::RiffHeader
- Inherits:
-
Object
- Object
- Zappa::RiffHeader
- Defined in:
- lib/zappa/wave/riff_header.rb
Instance Attribute Summary collapse
-
#chunk_id ⇒ Object
readonly
Returns the value of attribute chunk_id.
-
#chunk_size ⇒ Object
Returns the value of attribute chunk_size.
-
#format ⇒ Object
readonly
Returns the value of attribute format.
Instance Method Summary collapse
-
#initialize(file = nil) ⇒ RiffHeader
constructor
A new instance of RiffHeader.
- #pack ⇒ Object
- #unpack(file) ⇒ Object
Constructor Details
#initialize(file = nil) ⇒ RiffHeader
6 7 8 9 10 11 12 13 14 |
# File 'lib/zappa/wave/riff_header.rb', line 6 def initialize(file = nil) if file.nil? @chunk_id = 'RIFF' @chunk_size = 40 @format = 'WAVE' else unpack(file) end end |
Instance Attribute Details
#chunk_id ⇒ Object (readonly)
Returns the value of attribute chunk_id.
3 4 5 |
# File 'lib/zappa/wave/riff_header.rb', line 3 def chunk_id @chunk_id end |
#chunk_size ⇒ Object
Returns the value of attribute chunk_size.
4 5 6 |
# File 'lib/zappa/wave/riff_header.rb', line 4 def chunk_size @chunk_size end |
#format ⇒ Object (readonly)
Returns the value of attribute format.
3 4 5 |
# File 'lib/zappa/wave/riff_header.rb', line 3 def format @format end |
Instance Method Details
#pack ⇒ Object
16 17 18 |
# File 'lib/zappa/wave/riff_header.rb', line 16 def pack @chunk_id + [@chunk_size].pack('V') + @format end |
#unpack(file) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/zappa/wave/riff_header.rb', line 20 def unpack(file) @chunk_id = file.read(4) @chunk_size = file.read(4).unpack('V').first @format = file.read(4) fail 'ID is not RIFF' unless @chunk_id == 'RIFF' fail 'Format is not WAVE' unless @format == 'WAVE' end |