[LAD] Can someone add 2 features to Kluppe?

Robin Gareus robin at gareus.org
Tue Jul 20 13:08:45 UTC 2010


On 07/20/2010 02:46 PM, Patrick Shirkey wrote:
> On 07/20/2010 09:51 PM, Paul Davis wrote:
>> On Tue, Jul 20, 2010 at 7:48 AM, Patrick Shirkey
>> <pshirkey at boosthardware.com>  wrote:
>>
>>   
>>>> 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.
>>>>
>>>>
>>>>        
>>> The problem is how to set a counter that doesn't block the rest of
>>> the app
>>> while it is in process.
>>>      
>> i believe that robin's suggestion is the correct one. you don't want
>> to attempt audio timing using the system clock unless you have a
>> DLL/PLL that relates audio time to system time (and you don't).
>> decisions about what to do as time progresses need to be made in the
>> process() callback tree, not in the GUI or some other thread.
>> so just countdown some number of samples, and then resume playing, as
>> robin suggested. it won't block anything, anywhere.
>>    
> 
> I don't have any problem with counting down using the audio clock but
> how do I translate that into seconds/milliseconds set in the ui?

see my other email.
You must be tired tonight :) Just multiply it by the sample-rate..

> At the moment the timer counts in seconds using this function
> 
> void *timer_thread(void *arg) {
>     int how_long = *((int*) arg);
>     sleep(how_long);
>     pthread_mutex_unlock(&timer_lock);
>     return NULL;
> }
> 
> While it is counting I set the volume for the per track playback buffer
> to zero. I also need to stop the playhead from moving but that is a
> seperate issue.
> 
> Ideally the timer should count in milliseconds which I guess is handled
> by changing the call to sleep to select instead?
> 
> ex.
> 
> void *timer_thread(void *arg) {
>     int how_long = *((int*) arg);
>     pause.tv_sec  = how_long;
>     pause.tv_usec = 0;
>     (void) select(0, 0, 0, 0, &pause);
>     pthread_mutex_unlock(&timer_lock);
>     return NULL;
> }

Either that, or use usleep(microseconds).

> I'm not sure how to do that with audio samples instead. Happy to make it
> work that way though if it is the best approach.

it is.

best,
robin

-- 
Robin Gareus                           mail: robin at gareus.org
site: http://gareus.org/               chat: xmpp:rgareus at ik.nu
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



More information about the Linux-audio-dev mailing list