Class: Muse::WavHeader
- Inherits:
-
Object
- Object
- Muse::WavHeader
- Defined in:
- lib/muse/wav.rb
Constant Summary collapse
- SAMPLE_RATE =
44100
Instance Attribute Summary collapse
-
#data_chunk ⇒ Object
readonly
Returns the value of attribute data_chunk.
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#format_chunk ⇒ Object
readonly
Returns the value of attribute format_chunk.
-
#riff_chunk ⇒ Object
readonly
Returns the value of attribute riff_chunk.
-
#sample_rate ⇒ Object
readonly
Returns the value of attribute sample_rate.
-
#wav ⇒ Object
readonly
Returns the value of attribute wav.
Instance Method Summary collapse
-
#initialize(filename, stream_size) ⇒ WavHeader
constructor
A new instance of WavHeader.
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_chunk ⇒ Object (readonly)
Returns the value of attribute data_chunk.
58 59 60 |
# File 'lib/muse/wav.rb', line 58 def data_chunk @data_chunk end |
#file ⇒ Object (readonly)
Returns the value of attribute file.
58 59 60 |
# File 'lib/muse/wav.rb', line 58 def file @file end |
#format_chunk ⇒ Object (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_chunk ⇒ Object (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_rate ⇒ Object (readonly)
Returns the value of attribute sample_rate.
58 59 60 |
# File 'lib/muse/wav.rb', line 58 def sample_rate @sample_rate end |
#wav ⇒ Object (readonly)
Returns the value of attribute wav.
58 59 60 |
# File 'lib/muse/wav.rb', line 58 def wav @wav end |