[PD] Pd + asterisk?
russell at russellbryant.net
Wed Dec 19 18:53:39 CET 2007
Christian Gröger wrote:
> thanks for this, I just tried it, it works (kind of)...
Thank _you_ for trying it out!
>> 1) Install my branch of Asterisk that contains app_jack.
>> $ svn co http://svn.digium.com/svn/asterisk/team/russell/jack asterisk-jack
>> $ cd asterisk-jack
>> $ ./configure && make
>> $ sudo make install
>> The jack interface is in apps/app_jack.c in case anyone cares.
> There was the first problem, app_jack somehow didn't build without any
> errors, configure said jack...h was there, but there was no app_jack.so
> build. I had to do a 'make menuconfig' and disable+reenable app_jack.
Hm, that's odd. The build system should automatically include it if jack was
found on the system. I'll have to play around with it to see if it happens to
>> 3) Make sure jackd is running. For the sake of efficiency, specify 8 kHz,
>> because for most codecs used for phone calls, that's all you get. Also, specify
>> 160 frames per period. For 8 kHz audio, this comes out to 20 ms periods, which
>> is generally the packet size used for Voice over IP.
>> $ sudo jackd -d dummy -r 8000 -p 160
> I used 128 frames, this sounded a bit better. But I think it would be
> much better if app_jack would adapt to the running jack. I sometimes use
> jack for connecting to a firewire-soundcard and with 8KHz it's
> impossible to have good sound out of your speakers ;)
The short answer is that I have all intentions to make app_jack work
transparently with any period size and sample rate used by jack itself.
Longer response ...
In theory, any period size should work just fine. I just happened to choose 160
because I was thinking that it would be more efficient, since that was the
period size of packets coming through Asterisk. However, due to the way audio
is passed between Asterisk and jack, it really shouldn't matter at all. All of
the raw audio goes through ringbuffers that have no concept of a period. I will
play around with different period sizes to see if I can cause a problem to occur.
Also, I have all intentions to support more than 8 kHz mode for jack. :) The
trick is, with 8 kHz, app_jack doesn't have to resample anything. With any
other sample rate, it does. I have code that attempts to handle resampling the
audio in both directions using libresample. However, it currently makes the
audio sound absolutely terrible. I'll get it fixed, though ...
>> 4) Make a call to the extension created in Asterisk in step 2. You should see
>> the two new jack ports become available. In theory, they are available for
>> connection to any application that can use Jack. The only thing I have done so
>> far is to use the "patchage" application to connect the ports directly together
>> to verify that the audio is flowing correctly.
> I tried Pd and had some strange problems (I don't know where they come
> from) No problem if you connect adc~ from Asterisk to dac~ on Asterisk,
> I hear myself with a rather extreme echo. But I can't hear a simple osc~
> on the phone, neither can I hear myself on my PC-speakers when I talk
> into the phone.
Would you mind sharing the Pd patch that you were using to test this out?
The extreme echo is a good sign, I think. I assume you mean you just heard your
own voice coming back to you, with some delay. Anything beyond that is probably
acoustic echo with whatever phone you're using. :)
The reason that connecting Asterisk to itself works but not with anything else
could have something to do with the way I did sample value normalization in
Asterisk. Asterisk uses a 16 bit integer representation per sample. However, I
had to convert it to float for jack.
I wasn't sure of the right way to do it, so I simply scaled the values based on
the maximum values of the type ...
(f_buf is a buffer of floats, s_buf is a buffer of int16_t's)
for (i = 0; i < f->samples; i++)
f_buf[i] = s_buf[i] * (FLT_MAX / SHRT_MAX);
>> Now, to figure out how to hook up arbitrary jack ports to Pd ... if anyone has
>> any pointers, it would be much appreciated. I'm still very new to Pd. :)
> You could do this in Asterisk with a System(jack_connect ...) ;)
> Do you think it would be possible to tell app_jack to connect to
> jack-server running as Pid x? Jack sometimes screws up your system when
> it runs as root, or other software does, because it has to run as root
> too. I configured my Asterisk to run as myself, but that's quite complex.
The System() option is certainly amusing. Hey, if it works, why not. I think
what I want to do eventually is be able to send a message that you could receive
in a Pd patch that a new pair of jack ports has become available. But, that's
not as important to me right now as getting the audio flow working properly.
I don't know about adding an argument that says connect to PID X. However,
there appears to be an option in the jack C API which allows you to specify a
server name to connect to. That may do what is needed to connect to jackd
running as a different user.
Thanks for the suggestions.
> Anyway, it's cool you coded all this, thanks.
Thanks for the kind words, and for the testing! Hopefully I can get it working
well and make it easy to use. I will work on incorporating your suggestions.
More information about the Pd-list