Class: Deftones::Context::PortAudioOutputStream
- Inherits:
-
Object
- Object
- Deftones::Context::PortAudioOutputStream
- Defined in:
- lib/deftones/context.rb
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(context:) ⇒ PortAudioOutputStream
constructor
A new instance of PortAudioOutputStream.
- #open_stream ⇒ Object private
- #process(_input, output, frame_count, _time_info, status_flags, _user_data) ⇒ Object private
- #silence_for(frame_count) ⇒ Object private
- #start ⇒ Object
- #stop ⇒ Object
- #time ⇒ Object
Constructor Details
#initialize(context:) ⇒ PortAudioOutputStream
Returns a new instance of PortAudioOutputStream.
223 224 225 226 227 |
# File 'lib/deftones/context.rb', line 223 def initialize(context:) @context = context @stream = nil @silence_cache = {} end |
Instance Method Details
#close ⇒ Object
243 244 245 246 247 248 249 250 251 252 |
# File 'lib/deftones/context.rb', line 243 def close return self unless @stream stream = @stream @stream = nil stream.close self ensure Deftones::PortAudioSupport.release end |
#open_stream ⇒ Object (private)
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 |
# File 'lib/deftones/context.rb', line 262 def open_stream Deftones::PortAudioSupport.acquire! @stream = PortAudio::Stream.new( output: Deftones::PortAudioSupport.output_parameters( @context.channels, device_id: @context.output_device_id, label: @context.output_device_label, sample_rate: @context.sample_rate ), sample_rate: @context.sample_rate.to_f, frames_per_buffer: @context.buffer_size, &method(:process) ) rescue StandardError Deftones::PortAudioSupport.release raise end |
#process(_input, output, frame_count, _time_info, status_flags, _user_data) ⇒ Object (private)
280 281 282 283 284 285 286 287 |
# File 'lib/deftones/context.rb', line 280 def process(_input, output, frame_count, _time_info, status_flags, _user_data) @context.send(:record_stream_status_flags, status_flags) output.write_array_of_float(@context.send(:pull_realtime_samples, frame_count)) :continue rescue StandardError => error output.write_array_of_float(silence_for(frame_count)) unless output.null? @context.send(:handle_stream_error, error) end |
#silence_for(frame_count) ⇒ Object (private)
289 290 291 |
# File 'lib/deftones/context.rb', line 289 def silence_for(frame_count) @silence_cache[frame_count] ||= Array.new(frame_count * @context.channels, 0.0).freeze end |
#start ⇒ Object
229 230 231 232 233 |
# File 'lib/deftones/context.rb', line 229 def start open_stream unless @stream @stream.start self end |
#stop ⇒ Object
235 236 237 238 239 240 241 |
# File 'lib/deftones/context.rb', line 235 def stop return self unless @stream return self if @stream.stopped? @stream.stop self end |
#time ⇒ Object
254 255 256 257 258 |
# File 'lib/deftones/context.rb', line 254 def time return 0.0 unless @stream @stream.time end |