Class: EasyAudio::Stream
- Inherits:
-
FFI::PortAudio::Stream
- Object
- FFI::PortAudio::Stream
- EasyAudio::Stream
- Includes:
- FFI::PortAudio
- Defined in:
- lib/easy_audio.rb
Overview
Represents a single audio input/output stream. See #initialize for usage examples.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#fn ⇒ Object
Returns the value of attribute fn.
-
#frame_size ⇒ Object
Returns the value of attribute frame_size.
-
#input_channels ⇒ Object
readonly
Returns the value of attribute input_channels.
-
#latency ⇒ Object
readonly
Returns the value of attribute latency.
-
#output_channels ⇒ Object
readonly
Returns the value of attribute output_channels.
-
#sample_rate ⇒ Object
Returns the value of attribute sample_rate.
Instance Method Summary collapse
-
#initialize(opts = {}) {|buffer| ... } ⇒ Stream
constructor
Creates a new stream for processing audio.
-
#start ⇒ Object
Starts processing the stream.
-
#stop ⇒ Object
Stops processing the stream.
Constructor Details
#initialize(opts = {}) {|buffer| ... } ⇒ Stream
Creates a new stream for processing audio. Call #start to start processing.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/easy_audio.rb', line 44 def initialize(opts = {}, &block) pa_start @fn = block @sample_rate = opts[:sample_rate] || 44100 @frame_size = opts[:frame_size] || 256 @input_channels = opts[:in_chans] || 1 @output_channels = opts[:out_chans] || 1 @latency = opts[:latency] || 0.01 input, output = nil, nil if opts[:in] || opts[:in_chans] device = API.Pa_GetDefaultInputDevice input = stream_for(device, @input_channels, @latency) end if opts[:out] || opts[:out_chans] || !input device = API.Pa_GetDefaultOutputDevice output = stream_for(device, @output_channels, @latency) end open(input, output, @sample_rate, @frame_size) end |
Instance Attribute Details
#fn ⇒ Object
Returns the value of attribute fn.
68 69 70 |
# File 'lib/easy_audio.rb', line 68 def fn @fn end |
#frame_size ⇒ Object
Returns the value of attribute frame_size.
68 69 70 |
# File 'lib/easy_audio.rb', line 68 def frame_size @frame_size end |
#input_channels ⇒ Object (readonly)
Returns the value of attribute input_channels.
69 70 71 |
# File 'lib/easy_audio.rb', line 69 def input_channels @input_channels end |
#latency ⇒ Object (readonly)
Returns the value of attribute latency.
69 70 71 |
# File 'lib/easy_audio.rb', line 69 def latency @latency end |
#output_channels ⇒ Object (readonly)
Returns the value of attribute output_channels.
69 70 71 |
# File 'lib/easy_audio.rb', line 69 def output_channels @output_channels end |
#sample_rate ⇒ Object
Returns the value of attribute sample_rate.
68 69 70 |
# File 'lib/easy_audio.rb', line 68 def sample_rate @sample_rate end |
Instance Method Details
#start ⇒ Object
Starts processing the stream.
|
# File 'lib/easy_audio.rb', line 17
|
#stop ⇒ Object
Stops processing the stream.
|
# File 'lib/easy_audio.rb', line 20
|