493: Undecipherable

-Blog-

-Projects-

-Urlaub-

-About me-

-RSS-

Degrading calls: connecting Asterisk through JACK with Puredata

Dennis Guse

Sometimes it is necessary to get access to the audio of a VoIP telephony connection (more precisely SIP/RTP). My reason for this is quite simple: for laboratory studies on subjective quality of telephony, I need be able to introduce degradations like noise and speaker echo.

This is a short howto (for Ubuntu 14.04) to let Asterisk run in proxy mode (directmedia=no), route the audio via JACK to Puredata and back. In Puredata then audio can be modified as needed.

1. Install software:

sudo apt-get install asterisk qjackctl puredata

2. Setup realtime for group audio (optional)

If you need realtime for JACK, then enable it.

3. Configure Asterisk

Configure one extension (phone number) that: 1. answers the call 2. enables JACK for the caller to callee channel, 3. then dials the callee, 4. and on answering enables JACK for the callee to caller channel using a post dial macro.

The i(...) and o(...) tell asterisk to connect directly to the defined JACK ports - thus PD should already be running.

extensions = {
    default = {

    ["_XX"] = function(c, e)
        app.answer()
        channel.JACK_HOOK("manipulate,i(pure_data_0:input0),o(pure_data_0:output0)"):set("on")
        app.dial("SIP/" .. e, nil, "M(jack)")
    end;
    };
    ["macro-jack"] = {
    ["s"] = function(c, e)
        channel.JACK_HOOK("manipulate,i(pure_data_0:input1),o(pure_data_0:output1)"):set("on")
    end;
    };
}

Reload the configuration:

asterisk -rx "core reload"
asterisk -rx "module reload pbx_lua.so"

ATTENTION: If JACK is not running and the asterisk JACK application is thus failing to connect, it fail silently by just emitting a warning and audio is passed on directly.

4. Start JACK and Puredata

All applications connecting to a JACK server running as user X need also to run as X. As Asterisk is running as user asterisk simply start JACK and Puredata as user asterisk.

JACK

Start JACK either directly or using qjackctl as user asterisk. If you need realtime, enable it properly.

sudo -u asterisk "jackd --no-realtime -d dummy"

Dummy is used as backend as I do not need local sound output from JACK - if you want it use Alsa instead.

Puredata

Start Puredata as user asterisk and connect to JACK.

sudo -u asterisk bash pd -jack YourPatchFileHereOrNot

Then just enable DSP or do automatically.

Puredata version before 0.46 Overwriting the HOME-variable is necessary for Puredata version less than version 0.46, which will be included in Ubuntu 15.04. Otherwise the UI is not loaded as reading the config-files fails and the UI process stops.

sudo -u asterisk bash
> HOME=/tmp
> pd -jack YourPatchFileHereOrNot

Have fun.

Known issues:

  1. Asterisk Version prior 13 are limited to 8000Hz for interaction with JACK - see here.
  2. If JACK is not running Asterisk just ignores it and the call continues without.
  3. Due to the large numbers of buffers involved a relatively high delay is to be expected - a guess is ~80-100ms.