Class: Zappa::RiffHeader

Inherits:
Object
  • Object
show all
Defined in:
lib/zappa/wave/riff_header.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_idObject (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_sizeObject

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

#formatObject (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

#packObject



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