Class: Pdfrb::Model::Type::Sound

Inherits:
Cos::Stream show all
Defined in:
lib/pdfrb/model/type/sound.rb

Overview

Sound stream (s13.3). Sound effect annotation payload. /R = sampling rate, /C = channels, /B = bits/sample, /E = encoding (Raw, Signed, MuLaw, ALaw).

Instance Attribute Summary

Attributes inherited from Cos::Stream

#stream

Attributes inherited from Object

#document, #gen, #oid, #value

Instance Method Summary collapse

Methods inherited from Cos::Stream

#decoded_stream, #encoded_stream=, #initialize

Methods inherited from Cos::Dictionary

#[], #[]=, arlington_available?, arlington_default, arlington_key_to_symbol, arlington_loaded_for?, arlington_mark_loaded, arlington_object, arlington_one_type_to_ruby, arlington_required?, arlington_types_to_ruby, arlington_version, define_field, define_field_from_arlington, #delete, #each, each_field, #each_raw, #empty?, field, #initialize, #key?, #keys, lookup_type, own_fields, #pdf_type, register_type, type_map, #validate

Methods inherited from Object

#==, define_type, #deref, #indirect?, #initialize, #must_be_indirect?, #pdf_type, pdf_type

Constructor Details

This class inherits a constructor from Pdfrb::Model::Cos::Stream

Instance Method Details

#a_law_encoding?Boolean

Returns:

  • (Boolean)


19
# File 'lib/pdfrb/model/type/sound.rb', line 19

def a_law_encoding?; encoding == :ALaw; end

#audio_dataObject



32
33
34
# File 'lib/pdfrb/model/type/sound.rb', line 32

def audio_data
  decoded_stream&.force_encoding(Encoding::BINARY)
end

#bits_per_sampleObject



13
# File 'lib/pdfrb/model/type/sound.rb', line 13

def bits_per_sample; self[:B] || 8; end

#channelsObject



12
# File 'lib/pdfrb/model/type/sound.rb', line 12

def channels; self[:C] || 1; end

#duration_secondsObject



25
26
27
28
29
30
# File 'lib/pdfrb/model/type/sound.rb', line 25

def duration_seconds
  return nil unless sampling_rate&.positive?

  bytes = stream ? stream.bytesize : 0
  bytes.to_f / (sample_bytes * sampling_rate)
end

#encodingObject



14
# File 'lib/pdfrb/model/type/sound.rb', line 14

def encoding; self[:E]&.to_sym || :Raw; end

#mu_law_encoding?Boolean

Returns:

  • (Boolean)


18
# File 'lib/pdfrb/model/type/sound.rb', line 18

def mu_law_encoding?; encoding == :MuLaw; end

#raw_encoding?Boolean

Returns:

  • (Boolean)


16
# File 'lib/pdfrb/model/type/sound.rb', line 16

def raw_encoding?; encoding == :Raw; end

#sample_bytesObject



21
22
23
# File 'lib/pdfrb/model/type/sound.rb', line 21

def sample_bytes
  (channels * bits_per_sample) / 8.0
end

#sampling_rateObject



11
# File 'lib/pdfrb/model/type/sound.rb', line 11

def sampling_rate; self[:R]; end

#signed_encoding?Boolean

Returns:

  • (Boolean)


17
# File 'lib/pdfrb/model/type/sound.rb', line 17

def signed_encoding?; encoding == :Signed; end

#typeObject



10
# File 'lib/pdfrb/model/type/sound.rb', line 10

def type; self[:Type]; end