[alsa-devel] start threshold in alsa plugin

Stefan Schoenleitner dev.c0debabe at gmail.com
Thu Apr 1 10:35:54 CEST 2010


in my io-plugin code I would like to know the start threshold value.

AFAIK the start threshold is set to a default value that depends on the
  configured buffer size SND_PCM_IOPLUG_HW_BUFFER_BYTES.
In my case the buffer size is 160*2*1 .. 160*2*2 bytes which is 1..2
periods as one period has 160 samples and each sample has 16 bit (2 bytes).

* How exactly is the default threshold value derived from the buffer size ?

I also tried to get the start threshold value from the PCM:

    if (snd_pcm_sw_params_malloc(&sw_params)<0)
        return -1;

    if ((err=snd_pcm_sw_params_current(plug_info->io.pcm, sw_params))<0)
        printf("Unable to determine current swparams: %s\n",
        return -err;

    if (snd_pcm_sw_params_get_start_threshold(sw_params, &param)<0)
        return -1;

    DBG("start threshold: %lu", param);

Unfortunately the call to snd_pcm_sw_params_current() fails (i/o error).

* Do you know why that call fails ?
* Is this the right way to get the start threshold value from a pcm ?

I'm calling the above code at the end of the plugin entry function
SND_PCM_PLUGIN_DEFINE_FUNC() after all hw constraints (including the
buffer size) have been set.

Maybe the plugin entry function is just not the right place to retrieve
the sw configuration from the PCM as it is too early and the sw config
of the pcm has not yet been set up ?

* Should I use a callback like sw_params to retrieve the default config ?


More information about the Alsa-devel mailing list