Erlang audio server

62 views
Skip to first unread message

David Michael

unread,
Sep 29, 2009, 1:15:53 PM9/29/09
to NYC:Erlang
Hi All,

I tried to post this to the general Erlang Programming list without
much success, so I thought I would try it here.

I am looking to write an audio server that can respond to messages
from Erlang processes. My intent is that this would be more like an
instrument, rather than a media server. The library I would like to
use for the audio engine is in C or C++.

What is the best way to do this?
Port, C node, or linked-in driver?

Thanks in advance
David

Mihai Balea

unread,
Sep 29, 2009, 2:03:21 PM9/29/09
to nyce...@googlegroups.com

If you intend to just control your audio server with erlang, then a
port would do it. If the audio server is to be run on a different
machine, then a C node.
Basically, if it doesn't require top performance, I'd stay away from
linked in drivers, since they can crash the entire VM.

Mihai

Will Schenk

unread,
Sep 29, 2009, 2:05:50 PM9/29/09
to nyce...@googlegroups.com
I've some a couple little port problems with ruby and it's been super simple.
--
Will Schenk
http://www.sublimeguile.com

David Michael

unread,
Sep 29, 2009, 2:18:58 PM9/29/09
to NYC:Erlang
In doing so, did you have to start the Ruby process first, or did it
not matter?

Will Schenk

unread,
Sep 29, 2009, 3:13:28 PM9/29/09
to nyce...@googlegroups.com
start() ->
spawn( fun() ->
% register( parser, self() ),
process_flag( trap_exit, true ),
Cmd = "ruby parser.rb",
Port = open_port({spawn, Cmd}, [{packet, 4}, nouse_stdio,
exit_status, binary]),
port_loop(Port)
end).

and the parser.rb was

require 'rubygems'
require 'JSON'
require 'erlectricity'
require 'tvtorrent'

receive do |f|
f.when([:parse, String, String, String]) do |mod, user, pass|
case mod
when "tvtorrent"
f.send!([:result, TvTorrent.new( user, pass ).new_fav_torrents.to_json])
when "sleep"
STDERR.puts "Sleeping for #{user} seconds"
sleep user.to_i
f.send!([:result, "Done sleeping"])
else
f.send!([:result, "Unknown module type #{mod}"])
end

f.receive_loop
end
end

David Michael

unread,
Sep 29, 2009, 4:53:08 PM9/29/09
to NYC:Erlang
Awesome.
I take it that Erlang is running the Ruby script dynamically then (no
'$ ./parser.rb' first)?

Will Schenk

unread,
Sep 29, 2009, 4:54:40 PM9/29/09
to nyce...@googlegroups.com
Correct. I can send you the whole mess if you want, it does handle
the script blowing up I believe. I haven't looked at it in a while,
so maybeI'm making it up.

David Michael

unread,
Sep 30, 2009, 9:49:10 AM9/30/09
to nyce...@googlegroups.com
Sure, I'd love to see the example if you can rip it out of the rest of
the codebase.
Sounds like a port is the right way to go for this since my audio
server need not run on another machine. Even if it did need to run on
another machine, it does not need to be addressable from anything
other than Erlang processes.

D

Will Schenk

unread,
Oct 1, 2009, 4:56:37 PM10/1/09
to nyce...@googlegroups.com
Attached is parser.erl and parser_pool.erl. After you start them up,
you would check out a parser from the parser_pool which would maintain
up to I think it's 4 separate os-level processes. Then release them
and they are usable by your friends.

Have fun.
parser.erl
parser_pool.erl
parser.rb
Reply all
Reply to author
Forward
0 new messages