Re: [LAD] Prototyping algorithms and ideas

From: Fons Adriaensen <fons@email-addr-hidden>
Date: Thu Jan 31 2008 - 02:21:07 EET

Hi Yann,

> Here is a quick solution using Faust :
>
> ...
> A fully functional jack application can be easily generated using the
> faust2jack command or by pasting the above code in the online faust
> compiler (http://faust.grame.fr). The performances on my Vaio laptop (Intel
> Core 2 CPU T7400 @ 2.16GHz) is approximately of 2%.

Many thanks for this. I'm very happy you point me back
to Faust, as despite the comments below I am really
impressed by what it achieves. Enough to organise a
demo yesterday afternoon for two of the researchers
I work with. They are not programmers, but both will
start learning to use Faust.

Here are my comments, some of them posted before.

1. The auto-connection issue. If I would install (or
some day, update) Faust at home or at my normal working
place, build the examples to test the installation, and
run 'osc', this would send a continuous, maximum level,
1kHz signal to a power amp feeding an HF speaker that
doesn't much like signals of this frequency, and even
less at a power level at least 20 dB above its maximum
continuous rating. It would be destroyed instantly, and
I would be happy to escape without permanent hearing
damage. Please don't assume you can safely connect to
the first N physical ports. At least make it an option,
and one that needs explicit user action to be enabled.
The code attached below solves this.

2. It's not possible to run a more than one instance
of a JACK client since all instances have the same
name, there is no -name option, and they don't use
the API that automatically generates unique names.
This also is solved by the code attached below.

3. All the recursive filters I tested will generate
denormals if the input is stopped or disconnected.
On Intel systems this can easily push the CPU load
up to crash levels. Solving this requires changes
to all the Faust sources defining these filters.
BTW, some other systems, e.g. SC3, have the same
problem.

4. The fdelay() functions are not usable for the
application I posted. All of them have significant
HF loss if the delay is not integer, and as a result,
will generate amplitude and maybe also phase modulation
if the delay value is not static. Strangely, fdelay4()
is not any better than fdelay2(), and fdelay3() is even
worse.

5. There may be quality issues with some of the libs.
The 'bandfilter' for example behaves very strangely.

Alternative main() for jack-gtk.

The code below solves two problems.

1. Auto-connection of ports requires a one-time user
action. Ports will be connected only if the environment
variables FAUST2JACK_INPUTS and FAUST2JACK_OUTPUTS are
defined, e.g. in ~/.bash_profile. They should be defined
as e.g.

export FAUST2JACK_INPUTS=system:capture_%d
export FAUST2JACK_OUTPUTS=system:playback_%d

Both are used as format strings in snprintf().

2. Use jack_client_open() instead of jack_client_new().
This will automatically generate a unique client name
in case there is a conflict. Creation of the UI is
delayed until the JACK connection is established, so
the correct name will also be shown in the window title.

Ciao,

--------------------------------------------------------------

int main(int argc, char *argv[] )
{
        //gtk_init (&argc, &argv);
        
        UI* interface;
        jack_client_t* client;
        char buf [256];
        char rcfilename[256];
        jack_status_t jackstat;
        char *home;
        char *pname;
        char *jname;

        jname = basename (argv [0]);
        client = jack_client_open (jname, (jack_options_t) 0, &jackstat);
        if (client == 0) {
            fprintf (stderr, "Can't connect to JACK, is the server running ?\n");
            exit (1);
        }
        if (jackstat & JackNameNotUnique) {
            jname = jack_get_client_name (client);
        }

        jack_set_process_callback(client, process, 0);
        jack_set_sample_rate_callback(client, srate, 0);
        jack_on_shutdown(client, jack_shutdown, 0);
        
        gNumInChans = DSP.getNumInputs();
        gNumOutChans = DSP.getNumOutputs();
        
        for (int i = 0; i < gNumInChans; i++) {
            snprintf(buf, 256, "in_%d", i);
            input_ports[i] = jack_port_register(client, buf, JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0);
        }
        for (int i = 0; i < gNumOutChans; i++) {
            snprintf(buf, 256, "out_%d", i);
            output_ports[i] = jack_port_register(client, buf, JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0);
        }
        
        interface = new GTKUI (jname, &argc, &argv);
        DSP.init(jack_get_sample_rate(client));
        DSP.buildUserInterface(interface);

        home = getenv ("HOME");
        if (home == 0) home = ".";
        snprintf(rcfilename, 256, "%s/.%src", home, jname);
        interface->recallState(rcfilename);

        if (jack_activate(client)) {
            fprintf(stderr, "Can't activate JACK client\n");
            return 1;
        }
        
        pname = getenv("FAUST2JACK_INPUTS");
        if (pname && *pname) {
            for (int i = 0; i < gNumInChans; i++) {
                snprintf(buf, 256, pname, i + 1);
                jack_connect(client, buf, jack_port_name(input_ports[i]));
            }
        }
        
        pname = getenv("FAUST2JACK_OUTPUTS");
        if (pname && *pname) {
            for (int i = 0; i < gNumOutChans; i++) {
                snprintf(buf, 256, pname, i + 1);
                jack_connect(client, jack_port_name(output_ports[i]), buf);
            }
        }
        
        interface->run();
        jack_deactivate(client);
        
        for (int i = 0; i < gNumInChans; i++) {
            jack_port_unregister(client, input_ports[i]);
        }
        for (int i = 0; i < gNumOutChans; i++) {
            jack_port_unregister(client, output_ports[i]);
        }
        
        jack_client_close(client);
        interface->saveState(rcfilename);
                
          return 0;
}

--------------------------------------------------------------

-- 
FA
Laboratorio di Acustica ed Elettroacustica
Parma, Italia
Lascia la spina, cogli la rosa.
_______________________________________________
Linux-audio-dev mailing list
Linux-audio-dev@email-addr-hidden
http://lists.linuxaudio.org/mailman/listinfo/linux-audio-dev
Received on Thu Jan 31 16:15:02 2008

This archive was generated by hypermail 2.1.8 : Thu Jan 31 2008 - 16:15:02 EET