class Zappa::Format

Constants

FMT_SIZE

Attributes

audio_format[RW]
bits_per_sample[RW]
block_align[RW]
byte_rate[RW]
channels[RW]
chunk_size[RW]
name[RW]
sample_rate[RW]
unknown[RW]

Public Class Methods

new(file = nil) click to toggle source
# File lib/zappa/wave/format.rb, line 8
def initialize(file = nil)
  if file.nil?
    @chunk_id        = 'fmt '
    @chunk_size      = FMT_SIZE
    @audio_format    = 1
    @channels        = 2
    @sample_rate     = 44_100
    @byte_rate       = 176_400
    @block_align     = 4
    @bits_per_sample = 16
  else
    @chunk_id = file.read(4)
    @chunk_size = file.read(4).unpack('V').first
    unpack(file.read(@chunk_size))
  end
end

Public Instance Methods

==(other) click to toggle source
# File lib/zappa/wave/format.rb, line 25
def ==(other)
  pack == other.pack
end
pack() click to toggle source
# File lib/zappa/wave/format.rb, line 29
def pack
  fmt = @chunk_id
  fmt += [@chunk_size].pack('V')
  fmt += [@audio_format].pack('v')
  fmt += [@channels].pack('v')
  fmt += [@sample_rate].pack('V')
  fmt += [@byte_rate].pack('V')
  fmt += [@block_align].pack('v')
  fmt + [@bits_per_sample].pack('v')
end
unpack(data) click to toggle source
# File lib/zappa/wave/format.rb, line 40
def unpack(data)
  @audio_format    = data.byteslice(0..1).unpack('v').first
  @channels        = data.byteslice(2..3).unpack('v').first
  @sample_rate     = data.byteslice(4..7).unpack('V').first
  @byte_rate       = data.byteslice(8..11).unpack('V').first
  @block_align     = data.byteslice(12..13).unpack('v').first
  @bits_per_sample = data.byteslice(14..15).unpack('v').first
end