Class: Muse::WavHeader

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

Constant Summary collapse

SAMPLE_RATE =
44100

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename, stream_size) ⇒ WavHeader

Returns a new instance of WavHeader.



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/muse/wav.rb', line 60

def initialize(filename, stream_size)
  @sample_rate = SAMPLE_RATE
  @file = File.open(filename, "wb")

  @riff_chunk = RiffChunk.new
  @riff_chunk.chunk_id = "RIFF".unpack("N").first
  @riff_chunk.format = "WAVE".unpack("N").first

  @format_chunk = FormatChunk.new
  @format_chunk.chunk_id = "fmt ".unpack("N").first
  @format_chunk.chunk_size = 16
  @format_chunk.audio_format = 1
  @format_chunk.num_channels = 2
  @format_chunk.bits_per_sample = 16
  @format_chunk.sample_rate =  @sample_rate
  @format_chunk.byte_rate = @format_chunk.sample_rate * @format_chunk.num_channels * @format_chunk.bits_per_sample/2
  @format_chunk.block_align = @format_chunk.num_channels * @format_chunk.bits_per_sample/2
  
  @data_chunk = DataChunk.new
  @data_chunk.chunk_id = "data".unpack("N").first
  @data_chunk.chunk_size = stream_size * @format_chunk.num_channels * @format_chunk.bits_per_sample/8
  @riff_chunk.chunk_size = 36 + @data_chunk.chunk_size
  
  @wav = WavFormat.new
  @wav.riff_chunk = @riff_chunk
  @wav.format_chunk = @format_chunk
  @wav.data_chunk = @data_chunk
  @wav.write(@file)
  @file.close
end

Instance Attribute Details

#data_chunkObject (readonly)

Returns the value of attribute data_chunk.



58
59
60
# File 'lib/muse/wav.rb', line 58

def data_chunk
  @data_chunk
end

#fileObject (readonly)

Returns the value of attribute file.



58
59
60
# File 'lib/muse/wav.rb', line 58

def file
  @file
end

#format_chunkObject (readonly)

Returns the value of attribute format_chunk.



58
59
60
# File 'lib/muse/wav.rb', line 58

def format_chunk
  @format_chunk
end

#riff_chunkObject (readonly)

Returns the value of attribute riff_chunk.



58
59
60
# File 'lib/muse/wav.rb', line 58

def riff_chunk
  @riff_chunk
end

#sample_rateObject (readonly)

Returns the value of attribute sample_rate.



58
59
60
# File 'lib/muse/wav.rb', line 58

def sample_rate
  @sample_rate
end

#wavObject (readonly)

Returns the value of attribute wav.



58
59
60
# File 'lib/muse/wav.rb', line 58

def wav
  @wav
end