Class: Caf::Chunk::AudioDescription

Inherits:
Base
  • Object
show all
Defined in:
lib/caf/chunk/audio_description.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#chunk_size, #chunk_type

Instance Method Summary collapse

Methods inherited from Base

#check_type_and_size, implements

Constructor Details

#initialize(chunk_header) ⇒ AudioDescription

Returns a new instance of AudioDescription.



15
16
17
# File 'lib/caf/chunk/audio_description.rb', line 15

def initialize(chunk_header)
  super chunk_header
end

Instance Attribute Details

#bits_per_channelObject

Returns the value of attribute bits_per_channel.



12
13
14
# File 'lib/caf/chunk/audio_description.rb', line 12

def bits_per_channel
  @bits_per_channel
end

#bytes_per_packetObject

Returns the value of attribute bytes_per_packet.



12
13
14
# File 'lib/caf/chunk/audio_description.rb', line 12

def bytes_per_packet
  @bytes_per_packet
end

#channels_per_frameObject

Returns the value of attribute channels_per_frame.



12
13
14
# File 'lib/caf/chunk/audio_description.rb', line 12

def channels_per_frame
  @channels_per_frame
end

#format_flagsObject

Returns the value of attribute format_flags.



12
13
14
# File 'lib/caf/chunk/audio_description.rb', line 12

def format_flags
  @format_flags
end

#format_idObject

Returns the value of attribute format_id.



12
13
14
# File 'lib/caf/chunk/audio_description.rb', line 12

def format_id
  @format_id
end

#frames_per_packetObject

Returns the value of attribute frames_per_packet.



12
13
14
# File 'lib/caf/chunk/audio_description.rb', line 12

def frames_per_packet
  @frames_per_packet
end

#samplerateObject

Returns the value of attribute samplerate.



12
13
14
# File 'lib/caf/chunk/audio_description.rb', line 12

def samplerate
  @samplerate
end

Instance Method Details

#fields_sizeObject



36
37
38
# File 'lib/caf/chunk/audio_description.rb', line 36

def fields_size
  32
end

#read_data(file) ⇒ Object

Raises:



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/caf/chunk/audio_description.rb', line 40

def read_data(file)
  data = file.read(self.fields_size)
  raise(Caf::Error, "chunk data too short: #{self}") if file.eof?

  @samplerate        = Helper.read_double(data)
  @format_id          = Helper.read_chars(4, data, 8)
  @format_flags       = Helper.read_int(data, 12)
  @bytes_per_packet   = Helper.read_int(data, 16)
  @frames_per_packet  = Helper.read_int(data, 20)
  @channels_per_frame = Helper.read_int(data, 24)
  @bits_per_channel   = Helper.read_int(data, 28)

  self.validate

  data.size
end

#to_sObject



19
20
21
22
23
24
25
26
27
28
# File 'lib/caf/chunk/audio_description.rb', line 19

def to_s
  "#{chunk_type} (audio description chunk):\n"+
    " -samplerate:         #{samplerate}\n"+
    " -format ID:          #{format_id}\n"+
    " -format flags:       #{format_flags}\n"+
    " -bytes per packet:   #{bytes_per_packet}\n"+
    " -frames per packet:  #{frames_per_packet}\n"+
    " -channels per frame: #{channels_per_frame}\n"+
    " -bits per channel:   #{bits_per_channel}\n"
end

#validateObject

Raises:



30
31
32
33
34
# File 'lib/caf/chunk/audio_description.rb', line 30

def validate
  raise(Caf::Error, "invalid audio description chunk: sample rate cannot be 0") if samplerate == 0
  raise(Caf::Error, "invalid audio description chunk: format ID cannot be 0") if format_id == 0
  raise(Caf::Error, "invalid audio description chunk: channels per frame cannot be 0") if channels_per_frame == 0
end