Created
November 26, 2015 08:04
-
-
Save nagachika/e18675b9a2c1d2f2ae00 to your computer and use it in GitHub Desktop.
play waveform transported via TCP with coreaudio.gem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "coreaudio" | |
require "socket" | |
serv = TCPServer.new(9999) | |
sock = serv.accept | |
puts "accepted." | |
dev = CoreAudio.default_output_device | |
buf = dev.output_buffer(4096) | |
puts "output to device: #{dev.inspect}" | |
buf.start | |
puts "output start." | |
begin | |
while (l = sock.readpartial(4096*2)) | |
buf << NArray.to_na(l, NArray::SINT) | |
end | |
rescue EOFError | |
end | |
buf.stop | |
sock.close | |
serv.close |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment