Sha256: 0f013b971820c82c8ef88fec3d99e9fe992c53e25c01755fdf5e9d93a90ea36c

Contents?: true

Size: 810 Bytes

Versions: 9

Compression:

Stored size: 810 Bytes

Contents

require "thread"
require "coreaudio"

Thread.abort_on_exception = true

inbuf = CoreAudio.default_input_device.input_buffer(1024)
outbuf = CoreAudio.default_output_device.output_buffer(1024)

queue = Queue.new
output_th = Thread.start do
  filter = NArray.float(2, 1024)
  filter.shape[1].times do |i|
    filter[true, i] = (i % 256 - 128) / 128.0
  end

  while w = queue.pop
    outbuf << w * filter
  end
end

input_th = Thread.start do
  loop do
    wav = inbuf.read(1024)
    queue.push(wav)
  end
end

inbuf.start
outbuf.start
$stdout.print "loopback..."
$stdout.flush
sleep 10;
queue.push(nil)
inbuf.stop
outbuf.stop
$stdout.puts "done."
input_th.kill.join
output_th.kill.join

puts "#{inbuf.dropped_frame} frame dropped at input buffer."
puts "#{outbuf.dropped_frame} frame dropped at output buffer."

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
coreaudio-0.0.12 examples/ring_modulator.rb
coreaudio-0.0.11 examples/ring_modulator.rb
coreaudio-0.0.10 examples/ring_modulator.rb
coreaudio-0.0.9 examples/ring_modulator.rb
coreaudio-0.0.8 examples/ring_modulator.rb
coreaudio-0.0.7 examples/ring_modulator.rb
coreaudio-0.0.6 examples/ring_modulator.rb
coreaudio-0.0.5 examples/ring_modulator.rb
coreaudio-0.0.4 examples/ring_modulator.rb