All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mads Kiilerich <mads@kiilerich.com>
To: Stefan Schoenleitner <dev.c0debabe@gmail.com>
Cc: alsa-devel <alsa-devel@alsa-project.org>
Subject: Re: need help with io plugin programming: how to add delay ?
Date: Wed, 23 Dec 2009 17:39:16 +0100	[thread overview]
Message-ID: <4B3247B4.4000506@kiilerich.com> (raw)
In-Reply-To: <4B31FC67.2090201@gmail.com>

Stefan Schoenleitner wrote, On 12/23/2009 12:08 AM:
> However, the result is not satisfying at all as the delay between the received chunks varies and sometimes even takes a whole 15ms (!) longer (i.e. 35ms delay instead of 20ms).
>    
...
> As the calculation of the sleep time uses an *absolute* point of time
> as reference (which is takes before starting to poll() and recv() from the socket), all delay after the time measurement and before the actual sleep does not influence the precision, right ?
> For this reason I have no idea where the high delay variations are coming from.
> I mean how should it work with an alsa plugin if not even this simple simulation code works
> in a timely and precise manner ?
>
> * What am I doing wrong ?
>
> I thought of adding buffering so that the socket read operations do not have a strict timing schedule.
> However, as I said earlier, if the time for socket polling or recv varies, it does not influence the precision as an absolute point of time is used as timeout and the (absolute) start time measurement is done *before* all the socket operations.
> Thus I think that for this reason adding buffering would not make much difference here, right ?
>    

AFAIK ALSA gurantees no deadlines, so I think you will have to add a 
"sufficiently large" buffer somewhere - and make sure to handle 
over/underruns somehow anyway.

> Just before starting to write yet another implementation
> (the fourth one,

I did the same exercise. It _is_ really hard to get started writing 
sound applications and figure out which abstraction level and 
implementation to use and how to use it correctly.

I ended up coding for the pulseaudio API. My case was for 
http://bitbucket.org/kiilerix/tcpcam/ . The result isn't pretty, but it 
could have been worse. The result isn't very stable or understood in all 
details, but it is good enough for my case. This case is different than 
yours, but I had problems similar to yours when I tried to code for the 
ALSA api. My numbers also happens to be exactly the same as in your case.

> this time with jack)

Jack to some extent builds on top of ALSA, so jack can't do it any 
better than ALSA. But jack might use ALSA the right way and thus give 
you someting close to what you want. AFAIK.

> It is connected over UART at 460800 baud and requires exactly 160 16bit PCM samples
> with 8kHz sampling rate each 20ms for speech compression.
>    

It is my experience that it matters that two different oscillators never 
have exactly the same frequency, so over time you will get an over- or 
under-run.

/Mads

  reply	other threads:[~2009-12-23 16:39 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-12-22 19:55 need help with io plugin programming: how to add delay ? Stefan Schoenleitner
2009-12-22 23:08 ` Stefan Schoenleitner
2009-12-23  2:14   ` Alex Austin
2009-12-23  8:15     ` Stefan Schoenleitner
2009-12-23  9:28       ` Alex Austin
2009-12-23 11:17         ` Stefan Schoenleitner
2009-12-23 16:39           ` Mads Kiilerich [this message]
2009-12-23 17:08             ` Stefan Schoenleitner
2009-12-23 17:40               ` Mark Brown
2009-12-23 18:24                 ` Stefan Schoenleitner
2009-12-23 17:09             ` Mark Brown
2009-12-23  8:55     ` Stefan Schoenleitner

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=4B3247B4.4000506@kiilerich.com \
    --to=mads@kiilerich.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=dev.c0debabe@gmail.com \
    /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.