Class: RubyAudio::SoundInfo
- Inherits:
-
CSoundInfo
- Object
- CSoundInfo
- RubyAudio::SoundInfo
- Defined in:
- lib/ruby-audio/sound_info.rb
Overview
Class SoundInfo
provides information about open sound files’ format, length, samplerate, channels, and other things.
Example:
snd = RubyAudio::Sound.open("snd.wav")
puts snd.info.channels #=> 2
puts snd.info.samplerate #=> 48000
snd.close
In addition it can be used to specify the format of new sound files:
info = RubyAudio::SoundInfo.new :channels => 1, :samplerate => 48000, :format => RubyAudio::FORMAT_WAV|RubyAudio::FORMAT_PCM_16
snd = RubyAudio::Sound.open("new.wav", 'w', info)
Instance Method Summary collapse
-
#clone ⇒ Object
Returns a new
SoundInfo
object that has the same channel count, sample rate, and format. -
#initialize(options = {}) ⇒ SoundInfo
constructor
Creates a new SoundInfo object and populates it using the given data.
-
#length ⇒ Object
Returns the length of the audio file in seconds.
-
#main_format ⇒ Object
Returns the main format constant as a string.
-
#sub_format ⇒ Object
Returns the sub format constant as a string.
Methods inherited from CSoundInfo
#channels, #channels=, #format, #format=, #frames, #samplerate, #samplerate=, #sections, #seekable, #valid?
Constructor Details
#initialize(options = {}) ⇒ SoundInfo
Creates a new SoundInfo object and populates it using the given data
Example:
info = RubyAudio::SoundInfo.new :channels => 1, :samplerate => 48000, :format => RubyAudio::FORMAT_WAV|RubyAudio::FORMAT_PCM_16
20 21 22 23 24 25 |
# File 'lib/ruby-audio/sound_info.rb', line 20 def initialize ={} # Populate from options if given unless .empty? .each {|key,value| send("#{key}=", value)} end end |
Instance Method Details
#clone ⇒ Object
34 35 36 |
# File 'lib/ruby-audio/sound_info.rb', line 34 def clone SoundInfo.new(:channels => channels, :samplerate => samplerate, :format => format) end |
#length ⇒ Object
Returns the length of the audio file in seconds
63 64 65 |
# File 'lib/ruby-audio/sound_info.rb', line 63 def length frames / samplerate.to_f end |
#main_format ⇒ Object
Returns the main format constant as a string
Example:
info = RubyAudio::SoundInfo.new :channels => 1, :samplerate => 48000, :format => RubyAudio::FORMAT_WAV|RubyAudio::FORMAT_PCM_16
info.main_format
#=> "FORMAT_WAV"
46 47 48 49 |
# File 'lib/ruby-audio/sound_info.rb', line 46 def main_format calculate_format if @main_format.nil? @main_format end |
#sub_format ⇒ Object
Returns the sub format constant as a string
Example:
info = RubyAudio::SoundInfo.new :channels => 1, :samplerate => 48000, :format => RubyAudio::FORMAT_WAV|RubyAudio::FORMAT_PCM_16
info.sub_format
#=> "FORMAT_PCM_16"
57 58 59 60 |
# File 'lib/ruby-audio/sound_info.rb', line 57 def sub_format calculate_format if @sub_format.nil? @sub_format end |