Class: AudioPlayback::Sound

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/audio-playback/sound.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(audio_file, options = {}) ⇒ Sound

Returns a new instance of Sound.

Parameters:

Options Hash (options):

  • logger (IO)


23
24
25
26
27
# File 'lib/audio-playback/sound.rb', line 23

def initialize(audio_file, options = {})
  @audio_file = audio_file
  populate(options)
  report(options[:logger]) if options[:logger]
end

Instance Attribute Details

#audio_fileObject (readonly)

Returns the value of attribute audio_file.



7
8
9
# File 'lib/audio-playback/sound.rb', line 7

def audio_file
  @audio_file
end

#dataObject (readonly)

Returns the value of attribute data.



7
8
9
# File 'lib/audio-playback/sound.rb', line 7

def data
  @data
end

#sizeObject (readonly)

Returns the value of attribute size.



7
8
9
# File 'lib/audio-playback/sound.rb', line 7

def size
  @size
end

Class Method Details

.load(file_or_path, options = {}) ⇒ Sound

Load a sound from the given file path

Parameters:

  • file_or_path (::File, String)
  • options (Hash) (defaults to: {})

Options Hash (options):

  • logger (IO)

Returns:



15
16
17
18
# File 'lib/audio-playback/sound.rb', line 15

def self.load(file_or_path, options = {})
  file = AudioPlayback::File.new(file_or_path)
  new(file, options)
end

Instance Method Details

#report(logger) ⇒ Boolean

Log a report about the sound

Parameters:

  • logger (IO)

Returns:

  • (Boolean)


32
33
34
35
36
37
38
# File 'lib/audio-playback/sound.rb', line 32

def report(logger)
  logger.puts("Sound report for #{@audio_file.path}")
  logger.puts("  Sample rate: #{@audio_file.sample_rate}")
  logger.puts("  Channels: #{@audio_file.num_channels}")
  logger.puts("  File size: #{@audio_file.size}")
  true
end