[alsa-devel] plughw behaviour not consistent with hw

Stefano Antonelli santonelli at algosolutions.com
Thu Nov 1 05:44:12 CET 2018


Hello list,

I'm working on an application that requires a period time of 10ms.  The
hardware at the other end of the bus is a ulaw codec running at 8kHz.
 The application runs at 16kHz S16_LE and I was hoping to use the
plughw device to do sample rate conversion and ulaw encode/decode.
 This way the application doesn't need to change to accommodate this
ulaw codec.  However, it's not working and I don't know how to go about
debugging.  I'm hoping I can get some pointers here.

The problem is best illustrated by this output, first using plughw:
alsa_read: 10
alsa_read: 20
alsa_read: 0
alsa_read: 20
alsa_read: 0
alsa_read: 20
alsa_read: 0
alsa_read: 20
alsa_read: 0
alsa_read: 20

It would appear that plughw gives the correct period time on the first
call, but then subsequently buffers 2 periods before returning.  
Using hw with matching sample rate, sample format, and number of
samples:
alsa_read: 10
alsa_read: 10
alsa_read: 10
alsa_read: 10
alsa_read: 10
alsa_r
ead: 10
alsa_read: 10
alsa_read: 10
alsa_read: 10
alsa_read: 10

This code snippet generated the above output:

for (i = 0; i < 10; ++i) {
        gettimeofday(&time1, NULL);
	err = snd_pcm_readi (capture_handle, buf, NSMP); 
        if (err != NSMP) {
                printf ("read from audio interface failed "
                        " (%s)\n", snd_strerror (err));
                exit (1);
        }
        gettimeofday(&time2, NULL);
        printf("alsa_read: %d\n", getTimeDiff(time1, time2));
}

I have tried using the patch from here (without the environment
variable switch):

http://mailman.alsa-project.org/pipermail/alsa-devel/2008-October/01170
3.html

to print out the configuration of plughw's plugin chain, but it
generates no output.  I've verified the md5sum of the library after
compilation and it matches the one I compiled.  And I ran ldconfig
after replacing libasound.so.  So I don't know what's going on there.
 I definitely call snd_pcm_hw_params() when setting up the capture
device.  This is using alsa-lib-1.0.25.

Does anyone know why plughw might be acting the way it is and how I can
get it to deliver 10ms periods?  Equally appreciated would be any tips
on how to debug this problem.

Thanks,
Stef



More information about the Alsa-devel mailing list