Alsa lisp in alsa-lib


Alsa lisp in Alsa-lib


Table of Contents

  • 1 What is Alsa lisp?
  • 2 Difference between lisp and alsa lisp.
  • 3 Sample code
  • 4 Why not make a alisp-mode for emacs?

1 What is Alsa lisp?

Alsa lisp is a lisp interpreter provided by alsa-lib package, it can be used as a script language to configure alsa. Alsalisp is not installed default by alsa-lib, so you need to compile alsalisp from source code.

It provide a simple example to make a tiny lisp interpreter from scratch. Of course we can make our own script language by wrapper alsa-lib functions with some script language like Gnu's guile.

2 Difference between lisp and alsa lisp.

Alsa lisp just implemented basic syntax of lisp with some simple intrinsic function. But it does not support macro syntax, that's too complicated.
Beside the simple syntax, alsa lisp implemented its own special intrinsic function to invoke alsa-lib native functions. Those alsa related intrinsic function include:

static const struct intrinsic snd_intrinsics[] = {
        { "Acall", F_acall },
        { "Aerror", F_aerror },
        { "Ahandle", F_ahandle },
        { "Aresult", F_ahandle },
        { "Asnderr", F_snderr },
        { "Asyserr", F_syserr }
    };

Function Acall can be used to invoke alsa-lib native function with identical symbol like parameters , Alsa lisp implemented those symbol-like variables named "acall_table", which include:

static const struct acall_table acall_table[] = {
    { "card_get_index", &FA_int_str, (void *)snd_card_get_index, NULL },
    { "card_get_longname", &FA_int_int_strp, (void *)snd_card_get_longname, NULL },
    { "card_get_name", &FA_int_int_strp, (void *)snd_card_get_name, NULL },
    { "card_next", &FA_int_intp, (void *)&snd_card_next, NULL },
    { "ctl_card_info", &FA_card_info, NULL, "ctl" },
    { "ctl_close", &FA_int_p, (void *)&snd_ctl_close, "ctl" },
    { "ctl_open", &FA_int_pp_strp_int, (void *)&snd_ctl_open, "ctl" },
    { "hctl_close", &FA_int_p, (void *)&snd_hctl_close, "hctl" },
    { "hctl_ctl", &FA_p_p, (void *)&snd_hctl_ctl, "hctl" },
    { "hctl_elem_info", &FA_hctl_elem_info, (void *)&snd_hctl_elem_info, "hctl_elem" },
    { "hctl_elem_next", &FA_p_p, (void *)&snd_hctl_elem_next, "hctl_elem" },
    { "hctl_elem_prev", &FA_p_p, (void *)&snd_hctl_elem_prev, "hctl_elem" },
    { "hctl_elem_read", &FA_hctl_elem_read, (void *)&snd_hctl_elem_read, "hctl_elem" },
    { "hctl_elem_write", &FA_hctl_elem_write, (void *)&snd_hctl_elem_write, "hctl_elem" },
    { "hctl_find_elem", &FA_hctl_find_elem, (void *)&snd_hctl_find_elem, "hctl" },
    { "hctl_first_elem", &FA_p_p, (void *)&snd_hctl_first_elem, "hctl" },
    { "hctl_free", &FA_int_p, (void *)&snd_hctl_free, "hctl" },
    { "hctl_last_elem", &FA_p_p, (void *)&snd_hctl_last_elem, "hctl" },
    { "hctl_load", &FA_int_p, (void *)&snd_hctl_load, "hctl" },
    { "hctl_open", &FA_int_pp_strp_int, (void *)&snd_hctl_open, "hctl" },
    { "hctl_open_ctl", &FA_int_pp_p, (void *)&snd_hctl_open_ctl, "hctl" },
    { "pcm_info", &FA_pcm_info, NULL, "pcm" },
    { "pcm_name", &FA_str_p, (void *)&snd_pcm_name, "pcm" },
};

Following section gives some sample code of special alsa-related intrinsic function.

3 Sample code

A repository in GitHub have some sample. Following snippet list all sound cards.

(setq card (Acall 'card_next -1))
(setq card (Aresult card))
(while (>= card 0)
  (progn
    (princ "found card: " card "\n")
    (princ "  name    : " (Aresult (Acall 'card_get_name card)) "\n")
    (princ "  longname: " (Aresult (Acall 'card_get_longname card)) "\n")
    (setq card (Acall 'card_next card))
    (setq card (Aresult card))
  )
)
(unsetq card)

4 Why not make a alisp-mode for emacs?

That's so simple, just derived lisp-mode, add some syntax keyword highlight.

Comments

Popular posts from this blog

Bluedroid stack in android

How to setup a NAT server?

Network programming in elisp