Class: WavFile::Format

Inherits:
Object
  • Object
show all
Defined in:
lib/wav-file/wav-file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(chunk) ⇒ Format

Returns a new instance of Format.



24
25
26
27
28
29
30
31
32
33
# File 'lib/wav-file/wav-file.rb', line 24

def initialize(chunk)
  return if chunk.class != Chunk
  return if chunk.name != 'fmt '
  @id = chunk.data.slice(0,2).unpack('c')[0]
  @channel = chunk.data.slice(2,2).unpack('c')[0]
  @hz = chunk.data.slice(4,4).unpack('V').join.to_i
  @bytePerSec = chunk.data.slice(8,4).unpack('V').join.to_i
  @blockSize = chunk.data.slice(12,2).unpack('c')[0]
  @bitPerSample = chunk.data.slice(14,2).unpack('c')[0]
end

Instance Attribute Details

#bitPerSampleObject

Returns the value of attribute bitPerSample.



22
23
24
# File 'lib/wav-file/wav-file.rb', line 22

def bitPerSample
  @bitPerSample
end

#blockSizeObject

Returns the value of attribute blockSize.



22
23
24
# File 'lib/wav-file/wav-file.rb', line 22

def blockSize
  @blockSize
end

#bytePerSecObject

Returns the value of attribute bytePerSec.



22
23
24
# File 'lib/wav-file/wav-file.rb', line 22

def bytePerSec
  @bytePerSec
end

#channelObject

Returns the value of attribute channel.



22
23
24
# File 'lib/wav-file/wav-file.rb', line 22

def channel
  @channel
end

#hzObject

Returns the value of attribute hz.



22
23
24
# File 'lib/wav-file/wav-file.rb', line 22

def hz
  @hz
end

#idObject

Returns the value of attribute id.



22
23
24
# File 'lib/wav-file/wav-file.rb', line 22

def id
  @id
end

Instance Method Details

#==(target) ⇒ Object



55
56
57
58
59
60
61
62
# File 'lib/wav-file/wav-file.rb', line 55

def ==(target)
  @id == target.id && 
    @channel == target.channel &&
    @hz == target.hz &&
    @bytePerSec == target.bytePerSec &&
    @bitPerSample == target.bitPerSample &&
    @blockSize == target.blockSize
end

#to_binObject



46
47
48
49
50
51
52
53
# File 'lib/wav-file/wav-file.rb', line 46

def to_bin
  [@id].pack('v')+
    [@channel].pack('v') +
    [@hz].pack('V') +
    [@bytePerSec].pack('V') +
    [@blockSize].pack('v') +
    [@bitPerSample].pack('v')
end

#to_sObject



35
36
37
38
39
40
41
42
43
44
# File 'lib/wav-file/wav-file.rb', line 35

def to_s
  <<EOS
Format ID:      #{@id}
Channels:       #{@channel}
Sampling Ratio: #{@hz} (Hz)
Byte per Sec:   #{@bytePerSec}
Bit per Sample: #{@bitPerSample} 
Block Size:     #{blockSize}
EOS
end