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.
-
#truncate ⇒ Object
readonly
Returns the value of attribute truncate.
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 ⇒ Integer
Total size of the playback’s sound frames in bytes.
-
#initialize(sounds, output, options = {}) ⇒ Action
constructor
A new instance of Action.
-
#looping? ⇒ Boolean
Is audio looping ?.
-
#report(logger) ⇒ Boolean
Log a report about playback.
-
#sample_rate ⇒ Integer
Sample rate of the playback sound.
-
#start ⇒ Playback
(also: #play)
Start playback.
-
#truncate? ⇒ Boolean
Should playback be truncated? eg :start 3 seconds, :duration 1 second.
Constructor Details
#initialize(sounds, output, options = {}) ⇒ Action
Returns a new instance of Action.
52 53 54 55 56 57 58 59 |
# File 'lib/audio-playback/playback.rb', line 52 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.
29 30 31 |
# File 'lib/audio-playback/playback.rb', line 29 def buffer_size @buffer_size end |
#channels ⇒ Object (readonly)
Returns the value of attribute channels.
29 30 31 |
# File 'lib/audio-playback/playback.rb', line 29 def channels @channels end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
29 30 31 |
# File 'lib/audio-playback/playback.rb', line 29 def data @data end |
#num_channels ⇒ Object (readonly)
Returns the value of attribute num_channels.
29 30 31 |
# File 'lib/audio-playback/playback.rb', line 29 def num_channels @num_channels end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
29 30 31 |
# File 'lib/audio-playback/playback.rb', line 29 def output @output end |
#sounds ⇒ Object (readonly)
Returns the value of attribute sounds.
29 30 31 |
# File 'lib/audio-playback/playback.rb', line 29 def sounds @sounds end |
#stream ⇒ Object (readonly)
Returns the value of attribute stream.
29 30 31 |
# File 'lib/audio-playback/playback.rb', line 29 def stream @stream end |
#truncate ⇒ Object (readonly)
Returns the value of attribute truncate.
29 30 31 |
# File 'lib/audio-playback/playback.rb', line 29 def truncate @truncate end |
Instance Method Details
#block ⇒ Stream
Block process until playback finishes
77 78 79 |
# File 'lib/audio-playback/playback.rb', line 77 def block @stream.block end |
#channels_requested? ⇒ Boolean
Has a different channel configuration than the default been requested?
110 111 112 |
# File 'lib/audio-playback/playback.rb', line 110 def channels_requested? !@channels.nil? end |
#data_size ⇒ Integer
Total size of the playback’s sound frames in bytes
103 104 105 106 |
# File 'lib/audio-playback/playback.rb', line 103 def data_size frames = size * @num_channels frames * FRAME_SIZE.size end |
#looping? ⇒ Boolean
Is audio looping ?
116 117 118 |
# File 'lib/audio-playback/playback.rb', line 116 def looping? @is_looping end |
#report(logger) ⇒ Boolean
Log a report about playback
91 92 93 94 95 96 97 98 99 |
# File 'lib/audio-playback/playback.rb', line 91 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 ⇒ Integer
Sample rate of the playback sound
63 64 65 |
# File 'lib/audio-playback/playback.rb', line 63 def sample_rate @sounds.last.sample_rate end |
#start ⇒ Playback Also known as: play
Start playback
69 70 71 72 |
# File 'lib/audio-playback/playback.rb', line 69 def start @stream.play(self) self end |
#truncate? ⇒ Boolean
Should playback be truncated?
eg :start 3 seconds, :duration 1 second
84 85 86 |
# File 'lib/audio-playback/playback.rb', line 84 def truncate? !@truncate.nil? && !@truncate.values.empty? end |