[Jack-Devel] jack_frames_to_time() bug

PrevNext  Index
DateTue, 03 Jan 2012 01:40:33 +0000
From Fons Adriaensen <[hidden] at linuxaudio dot org>
ToJack Developers <[hidden] at lists dot jackaudio dot org>
Follow-UpStéphane Letz Re: [Jack-Devel] jack_frames_to_time() bug
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.
PrevNext  Index

1325555162.25352_0.ltw:2,a <20120103014033.GA15564 at linuxaudio dot org>