Re: [Jack-Devel] jack_frames_to_time() bug

PrevNext  Index
DateTue, 03 Jan 2012 10:30:18 +0100
From Stéphane Letz <[hidden] at grame dot fr>
ToFons Adriaensen <[hidden] at linuxaudio dot org>
CcJack Developers <[hidden] at lists dot jackaudio dot org>
In-Reply-ToFons Adriaensen [Jack-Devel] jack_frames_to_time() bug
Follow-UpFons Adriaensen Re: [Jack-Devel] jack_frames_to_time() bug
I suggest that you prepare a clean patch with all you proposed "timing related changes" (for jack1 for instance)

Thanks.

Stephane 

Le 3 janv. 2012 à 02:40, Fons Adriaensen a écrit :

> After a lot of frustration and hair-pulling trying to find a bug in
> my code it turns out I was looking for the wrong thing. 
> 
> jack_frames_to_time() returns a completely bogus result if
> the argument is before the start of the current period. 
> 
> The code is:
> 
>  return time.current_wakeup +
>            (long) rint (((double) ((long long) (frames - time.frames)) *
>                        ((long long) (time.next_wakeup - time.current_wakeup)) / ectl->buffer_size) );
> 
> and it's easy to see how it fails. Assume (frames - time.frames) is 
> supposed to be -1. Since both values are unsigned it will be 2^32-1
> and casting it to long long doesn't change that.
> 
> A correct implementation could be:
> 
>  return time.current_wakeup + 
>            (long) rint (((double) frames - (double)(time.frames)) *
>                         (time.next_wakeup - time.current_wakeup) / ectl->buffer_size);
> 
> 
> Ciao,                                        
> 
> -- 
> FA
> 
> Vor uns liegt ein weites Tal, die Sonne scheint - ein Glitzerstrahl.
> 
> 
> Jack-Devel mailing list
> [hidden]
> http://lists.jackaudio.org/listinfo.cgi/jack-devel-jackaudio.org
PrevNext  Index

1325583004.32062_0.ltw:2,a <38008B4E-E54F-4809-8098-885570DBF553 at grame dot fr>