All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stefano Antonelli <santonelli@algosolutions.com>
To: alsa-devel@alsa-project.org
Subject: plughw behaviour not consistent with hw
Date: Wed, 31 Oct 2018 21:44:12 -0700	[thread overview]
Message-ID: <1541047452.26732.263.camel@algosolutions.com> (raw)

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

_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

             reply	other threads:[~2018-11-01  4:44 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-01  4:44 Stefano Antonelli [this message]
2018-11-06  7:52 ` plughw behaviour not consistent with hw Takashi Sakamoto

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1541047452.26732.263.camel@algosolutions.com \
    --to=santonelli@algosolutions.com \
    --cc=alsa-devel@alsa-project.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.