Class: Zappa::Format
- Inherits:
-
Object
- Object
- Zappa::Format
- Defined in:
- lib/zappa/wave/format.rb
Constant Summary collapse
- FMT_SIZE =
16
Instance Attribute Summary collapse
-
#audio_format ⇒ Object
Returns the value of attribute audio_format.
-
#bits_per_sample ⇒ Object
Returns the value of attribute bits_per_sample.
-
#block_align ⇒ Object
Returns the value of attribute block_align.
-
#byte_rate ⇒ Object
Returns the value of attribute byte_rate.
-
#channels ⇒ Object
Returns the value of attribute channels.
-
#chunk_size ⇒ Object
Returns the value of attribute chunk_size.
-
#name ⇒ Object
Returns the value of attribute name.
-
#sample_rate ⇒ Object
Returns the value of attribute sample_rate.
-
#unknown ⇒ Object
Returns the value of attribute unknown.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(file = nil) ⇒ Format
constructor
A new instance of Format.
- #pack ⇒ Object
- #unpack(data) ⇒ Object
Constructor Details
#initialize(file = nil) ⇒ Format
Returns a new instance of Format.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# 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 |
Instance Attribute Details
#audio_format ⇒ Object
Returns the value of attribute audio_format.
3 4 5 |
# File 'lib/zappa/wave/format.rb', line 3 def audio_format @audio_format end |
#bits_per_sample ⇒ Object
Returns the value of attribute bits_per_sample.
3 4 5 |
# File 'lib/zappa/wave/format.rb', line 3 def bits_per_sample @bits_per_sample end |
#block_align ⇒ Object
Returns the value of attribute block_align.
3 4 5 |
# File 'lib/zappa/wave/format.rb', line 3 def block_align @block_align end |
#byte_rate ⇒ Object
Returns the value of attribute byte_rate.
3 4 5 |
# File 'lib/zappa/wave/format.rb', line 3 def byte_rate @byte_rate end |
#channels ⇒ Object
Returns the value of attribute channels.
3 4 5 |
# File 'lib/zappa/wave/format.rb', line 3 def channels @channels end |
#chunk_size ⇒ Object
Returns the value of attribute chunk_size.
3 4 5 |
# File 'lib/zappa/wave/format.rb', line 3 def chunk_size @chunk_size end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/zappa/wave/format.rb', line 3 def name @name end |
#sample_rate ⇒ Object
Returns the value of attribute sample_rate.
3 4 5 |
# File 'lib/zappa/wave/format.rb', line 3 def sample_rate @sample_rate end |
#unknown ⇒ Object
Returns the value of attribute unknown.
3 4 5 |
# File 'lib/zappa/wave/format.rb', line 3 def unknown @unknown end |
Instance Method Details
#==(other) ⇒ Object
25 26 27 |
# File 'lib/zappa/wave/format.rb', line 25 def ==(other) pack == other.pack end |
#pack ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# 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) ⇒ Object
40 41 42 43 44 45 46 47 |
# 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 |