RFC: Audio

I've noticed that the frequency of questions about doing audio stuff
with ruby is increasing. That's really neat. Too bad ruby's not ready
for it... yet.

There's a lot of thought that could go into a lot of areas in ruby
audio. I decided to take a pragmatic 'release-{early,often}' approach
and start at the core. I whipped up a simple sound class based on
NArray, and I requests your comments on it and its interface:

  http://hans.fugal.net/src/ruby-audio

My plans for this are simple: wrap libsndfile, libsamplerate, and
possibly portaudio. Combined with ladspar, midilib, and other ruby audio
libs that exist, this should get us well on the way.

I think a wiki, a la SciRuby (perhaps a subsection of SciRuby or
RubyGarden?), would be another great unifying step.

Ruby audio developers, unite! We may be few but we're non-zero.

About me: I'm a PhD student in Computer Science who finally gets to say
that music and audio stuff is on-topic, as my research area is Computer
Music.

contact me offline and i'll set you up with an account hans. please feel free
to use the sciruby site as you see fit. it's there as a community resource.

kind regards.

-a

···

On Sun, 13 Nov 2005, Hans Fugal wrote:

I've noticed that the frequency of questions about doing audio stuff
with ruby is increasing. That's really neat. Too bad ruby's not ready
for it... yet.

There's a lot of thought that could go into a lot of areas in ruby
audio. I decided to take a pragmatic 'release-{early,often}' approach
and start at the core. I whipped up a simple sound class based on
NArray, and I requests your comments on it and its interface:

http://hans.fugal.net/src/ruby-audio

My plans for this are simple: wrap libsndfile, libsamplerate, and
possibly portaudio. Combined with ladspar, midilib, and other ruby audio
libs that exist, this should get us well on the way.

I think a wiki, a la SciRuby (perhaps a subsection of SciRuby or
RubyGarden?), would be another great unifying step.

Ruby audio developers, unite! We may be few but we're non-zero.

About me: I'm a PhD student in Computer Science who finally gets to say
that music and audio stuff is on-topic, as my research area is Computer
Music.

--

ara [dot] t [dot] howard [at] gmail [dot] com
all happiness comes from the desire for others to be happy. all misery
comes from the desire for oneself to be happy.
-- bodhicaryavatara

===============================================================================

Python has had audio stuff for a while as part of the standard
distribution. Maybe you can draw inspiration from what they have?

        Hugh

···

On Sun, 13 Nov 2005, Hans Fugal wrote:

  http://hans.fugal.net/src/ruby-audio

My plans for this are simple: wrap libsndfile, libsamplerate, and
possibly portaudio. Combined with ladspar, midilib, and other ruby audio
libs that exist, this should get us well on the way.

In article <20051112220548.GB13404@gandalf.wlan>, hans@fugal.net says...

I've noticed that the frequency of questions about doing audio stuff
with ruby is increasing.

Ha! He said frequency.

My plans for this are simple: wrap libsndfile, libsamplerate, and
possibly portaudio. Combined with ladspar, midilib, and other ruby audio
libs that exist, this should get us well on the way.

Looks really good, and the NArray interface is simple. What do you
think about wrapping libmad?

I need to write a simple utility that monitors a streaming audio server
for silence, and pages me when it detects an outage. Seems like all I
need is libmad and some code to detect a bunch of zeros... perfect for a
simple ruby script, if the bindings were there. Ya?

Ah, but how does NArray deal with the constant resizing resulting from
an ongoing stream? Is there a copy each time?

···

--
Jay Levitt |
Wellesley, MA | I feel calm. I feel ready. I can only
Faster: jay at jay dot fm | conclude that's because I don't have a
http://www.jay.fm | full grasp of the situation. - Mark Adler

I recently explored the possibility of SWIGging the "aubio" library up
to Ruby, but the amount of learning curve was too much at the time. It
has pitch and tempo detection, and some other goodies like that. It has
Python support via SWIG packaged in with the dist.

Wanted to mention it in this thread in case someone with such skills
and motivation wanted to contribute Ruby support to aubio and/or aubio
support to Ruby.

> My plans for this are simple: wrap libsndfile, libsamplerate, and
> possibly portaudio. Combined with ladspar, midilib, and other ruby audio
> libs that exist, this should get us well on the way.

Looks really good, and the NArray interface is simple. What do you
think about wrapping libmad?

Possibly, after all the others.

I need to write a simple utility that monitors a streaming audio server
for silence, and pages me when it detects an outage. Seems like all I
need is libmad and some code to detect a bunch of zeros... perfect for a
simple ruby script, if the bindings were there. Ya?

Ah, but how does NArray deal with the constant resizing resulting from
an ongoing stream? Is there a copy each time?

I'm not sure how libmad's interface is, and I've never really done
streaming before, but to my understanding you would generally want to
decode a fixed amount each 'period', since that's how you're going to
feed it to the soundcard anyway. You could always do a 'big enough'
array and fill it partially if needed.

You could probably do this now if you use mpg123 and/or sox and output
to a raw format on stdout and read that into an NArray (or you can be a
tester for the Audio class - it works now, but the API is still subject
to change).

···

On Tue, 15 Nov 2005 at 04:58 -0500, Jay Levitt wrote:

I've seen aubio and it looks neat. If they've already SWIGged it for
python, it shouldn't be too hard to port to ruby.

BTW, I think the API is mostly not going to radically change anymore,
and I've got libsndfile working, if anyone needs it Right NowTM, it's
usable[1]. I'm going to do libsamplerate, and do some rubization of
those two libs, then make a release.

Jay: ecasound may indeed be just what you need. Interestingly, ecasound
has mp3 support by way of piping mpg123 into itself, if I understand
correctly.

1. `darcs get http://hans.fugal.net/src/ruby-audio`

In article <20051115141436.GC8693@gandalf.wlan>, hans@fugal.net says...

I'm not sure how libmad's interface is, and I've never really done
streaming before, but to my understanding you would generally want to
decode a fixed amount each 'period', since that's how you're going to
feed it to the soundcard anyway. You could always do a 'big enough'
array and fill it partially if needed.

Right, of course. I know that quite well as an end user, but as a
developer, I skipped right over it...

You could probably do this now if you use mpg123 and/or sox and output
to a raw format on stdout and read that into an NArray (or you can be a
tester for the Audio class - it works now, but the API is still subject
to change).

Looks like ecasound may be my friend, too... especially with ruby
bindings! I haven't even started playing yet, so we'll see.

···

--
Jay Levitt |
Wellesley, MA | I feel calm. I feel ready. I can only
Faster: jay at jay dot fm | conclude that's because I don't have a
http://www.jay.fm | full grasp of the situation. - Mark Adler