Class: AudioPlayback::Playback::Action
- Inherits:
-
Object
- Object
- AudioPlayback::Playback::Action
- Extended by:
- Forwardable
- Defined in:
- lib/audio-playback/playback.rb
Overview
Action of playing back an audio file
Instance Attribute Summary collapse
-
#buffer_size ⇒ Object
readonly
Returns the value of attribute buffer_size.
-
#channels ⇒ Object
readonly
Returns the value of attribute channels.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#num_channels ⇒ Object
readonly
Returns the value of attribute num_channels.
-
#output ⇒ Object
readonly
Returns the value of attribute output.
-
#sounds ⇒ Object
readonly
Returns the value of attribute sounds.
-
#stream ⇒ Object
readonly
Returns the value of attribute stream.
Instance Method Summary collapse
-
#block ⇒ Stream
Block process until playback finishes.
-
#channels_requested? ⇒ Boolean
Has a different channel configuration than the default been requested?.
-
#data_size ⇒ Fixnum
Total size of the playback’s sound frames in bytes.
-
#initialize(sounds, output, options = {}) ⇒ Action
constructor
A new instance of Action.
-
#report(logger) ⇒ Boolean
Log a report about playback.
-
#sample_rate ⇒ Fixnum
Sample rate of the playback sound.
-
#size ⇒ Fixnum
Size of the playback sound.
-
#start ⇒ Playback
(also: #play)
Start playback.
Constructor Details
#initialize(sounds, output, options = {}) ⇒ Action
Returns a new instance of Action.
34 35 36 37 38 39 40 41 |
# File 'lib/audio-playback/playback.rb', line 34 def initialize(sounds, output, = {}) @sounds = Array(sounds) @buffer_size = [:buffer_size] || DEFAULT[:buffer_size] @output = output @stream = [:stream] || Device::Stream.new(@output, ) populate() report([:logger]) if [:logger] end |
Instance Attribute Details
#buffer_size ⇒ Object (readonly)
Returns the value of attribute buffer_size.
23 24 25 |
# File 'lib/audio-playback/playback.rb', line 23 def buffer_size @buffer_size end |
#channels ⇒ Object (readonly)
Returns the value of attribute channels.
23 24 25 |
# File 'lib/audio-playback/playback.rb', line 23 def channels @channels end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
23 24 25 |
# File 'lib/audio-playback/playback.rb', line 23 def data @data end |
#num_channels ⇒ Object (readonly)
Returns the value of attribute num_channels.
23 24 25 |
# File 'lib/audio-playback/playback.rb', line 23 def num_channels @num_channels end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
23 24 25 |
# File 'lib/audio-playback/playback.rb', line 23 def output @output end |
#sounds ⇒ Object (readonly)
Returns the value of attribute sounds.
23 24 25 |
# File 'lib/audio-playback/playback.rb', line 23 def sounds @sounds end |
#stream ⇒ Object (readonly)
Returns the value of attribute stream.
23 24 25 |
# File 'lib/audio-playback/playback.rb', line 23 def stream @stream end |
Instance Method Details
#block ⇒ Stream
Block process until playback finishes
65 66 67 |
# File 'lib/audio-playback/playback.rb', line 65 def block @stream.block end |
#channels_requested? ⇒ Boolean
Has a different channel configuration than the default been requested?
91 92 93 |
# File 'lib/audio-playback/playback.rb', line 91 def channels_requested? !@channels.nil? end |
#data_size ⇒ Fixnum
Total size of the playback’s sound frames in bytes
84 85 86 87 |
# File 'lib/audio-playback/playback.rb', line 84 def data_size frames = (size * @num_channels) + METADATA.count frames * FRAME_SIZE.size end |
#report(logger) ⇒ Boolean
Log a report about playback
72 73 74 75 76 77 78 79 80 |
# File 'lib/audio-playback/playback.rb', line 72 def report(logger) paths = @sounds.map(&:audio_file).map(&:path) logger.puts("Playback report for #{paths}") logger.puts(" Number of channels: #{@num_channels}") logger.puts(" Direct audio to channels #{@channels.to_s}") unless @channels.nil? logger.puts(" Buffer size: #{@buffer_size}") logger.puts(" Latency: #{@output.latency}") true end |
#sample_rate ⇒ Fixnum
Sample rate of the playback sound
45 46 47 |
# File 'lib/audio-playback/playback.rb', line 45 def sample_rate @sounds.last.sample_rate end |
#size ⇒ Fixnum
Size of the playback sound
51 52 53 |
# File 'lib/audio-playback/playback.rb', line 51 def size @sounds.map(&:size).max end |
#start ⇒ Playback Also known as: play
Start playback
57 58 59 60 |
# File 'lib/audio-playback/playback.rb', line 57 def start @stream.play(self) self end |