Re: [LAD] Can someone add 2 features to Kluppe?

From: Robin Gareus <robin@email-addr-hidden>
Date: Tue Jul 20 2010 - 11:54:40 EEST

On 07/20/2010 09:17 AM, Patrick Shirkey wrote:
> On 07/20/2010 09:45 AM, Robin Gareus wrote:
>> On 07/20/2010 01:06 AM, Louigi Verona wrote:
>>
>>>
>>> Hey guys!
>>>
>>> Some time ago I have asked someone to look into Kluppe and add a
>>> couple of
>>> features.
>>> My request was not ignored and Patrick Shirkey was kind enough to
>>> volunteer
>>> to try to help.
>>>
>>> However, he came upon a difficulty and that is - *how do you set up an
>>> asynchronous timer in C?*
>>>
>> It depends what you need that timer for.
>>
>>
>
> The timer is needed to countdown the period between stopping and
> restarting the loop. The methods I have tried all halt the playback on a
> single frame and the ui also becomes unresponsive while the timer is in
> process.

That sounds like it needs to be be quite accurate, or not?

> All I would like to do is pass a zero byte to the audio signal handling
> code while the timer is in progress. The rest of the interface should
> stay active.

A simple approach might be to just set a counter and have the
audio-process count it down (in audio-samples). Once it reaches zero:
play again.

>> In gtk there's a g_timeout_add(). easy to use.
>>
> Will check that one. Might do the trick.

Don't forget to read the note:
http://library.gnome.org/devel/glib/unstable/glib-The-Main-Event-Loop.html#g-timeout-add

It's not very accurate but Example code is easy to come by.

>> To writing your own:
>> `apropos pthread` and more specifically `man pthread_create`.
>>
>>
> Otherwise will look into this.
>
>> usleep() sleeps at least, and select() sleeps at most a certain period
>> of time. http://freej.dyne.org/codedoc/fps_8cpp_source.html line 132ff
>> has examples of both.
>>
>
> Tried both of these options and they cause the app to pause with an
> annoying buzz while the timer is in effect.

In that case you should get x-runs. Otherwise it may well be that you
simply don't zero the audio-output. It's hard to tell what's going on
w/o seeing the source.

As for the GUI being unresponsive: The key part is to use usleep() in a
separate thread.

Here are two simple examples using pthread to do so:
 http://rg42.org/_media/wiki/async-timer.c # use a byte to indicate
 http://rg42.org/_media/wiki/async-timer2.c # use a MUTEX

You may want to elaborate on the usleep() call (fi. check for EINTR -
see the freeJ source).

>> For [more] accurate timing: RTC or HPET. Example code comes
>> with the kernel:
>> linux-2.6/Documentation/rtc.txt
>> linux-2.6/Documentation/hpet.txt
>>
>> There's a couple of other options fi. if you want to sync
>> hardware-devices using IRQs.. and the jack_process_callback is also very
>> good timer :)
>>
>>
>
> Not required for this task.
>
>
>
>>> It stopped right there. I was wondering if anyone could help us with
>>> that
>>> matter?
>>>
>>>
>>> Cheers!
>>>
>>>

ciao
robin

-- 
Robin Gareus                           mail: robin@email-addr-hidden
site: http://gareus.org/               chat: xmpp:rgareus@email-addr-hidden
blog: http://rg42.org/                 lab : http://citu.fr/
Public Key at http://pgp.mit.edu/
Fingerprint : 7107 840B 4DC9 C948 076D 6359 7955 24F1 4F95 2B42
_______________________________________________
Linux-audio-dev mailing list
Linux-audio-dev@email-addr-hidden
http://lists.linuxaudio.org/listinfo/linux-audio-dev
Received on Tue Jul 20 12:15:04 2010

This archive was generated by hypermail 2.1.8 : Tue Jul 20 2010 - 12:15:04 EEST