All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stefan Schoenleitner <dev.c0debabe@gmail.com>
To: Mads Kiilerich <mads@kiilerich.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 18:08:06 +0100	[thread overview]
Message-ID: <4B324E76.7040003@gmail.com> (raw)
In-Reply-To: <4B3247B4.4000506@kiilerich.com>

Hi,

Mads Kiilerich wrote:   
> 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.

I already thought that this would help.
So the alsa plugin would then fill some large buffer in my daemon
application and instead of receiving the data from a socket I would
have it available in some application buffer already.
Thus I could just read the frames from the application
buffer each 20ms and send them over UART to the DSP.

However, right now I found out that there seems to be no way
to execute *anything* each 20ms +/- 1ms.

So far I tried

	* nanosleep()
	* pthread_cond_timed_wait()
	* usleep()

I'm looking forward to try

	* HPET
	* RTC
	* setitimer()
	* alsa timers ?
	* anything else ?

I don't understand why all the function I have tried
so far have microsecond or even nanosecond precision and in the
end I'm off not for some nano- or microseconds, but for a full 15ms !
This is really bad :(


>> 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.

Indeed.


> 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.

As you said it's a different 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.

I looked at some code already.
Generally speaking it looks good, but it also uses 32 bit floating
point format for example (while I would need 8Khz 16bit LE).
It seems a little bit of a detour if I use:

ALSA --> jack io plugin --> jackd --> jack-client --> resample and change format --> my application

instead of

ALSA --> my plugin --> my application


As I said above, right now the problem is not even fully alsa related.
It is how I can execute something (e.g. my uart send code) each 20ms +/- 1ms.


>> 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.

Yes, I will have to deal with this as well :(
However, from time to time an overflow/underrun should be ok as long it
is generally working I guess.

Thanks for your inspiring words,
stefan

  reply	other threads:[~2009-12-23 17:08 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
2009-12-23 17:08             ` Stefan Schoenleitner [this message]
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=4B324E76.7040003@gmail.com \
    --to=dev.c0debabe@gmail.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=mads@kiilerich.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.