Luppp's internals use a single(!) floating point, which mixes a bar number, and a "percent" of that bar.<br>Found it quite nice to work with, to get the bar you just:<br>int bar = (int) floatBeatPercent;<br>while to get the percent you:<br>
float percent = floatBeatPercent - ((int)floatBeatPercent);<br><br>In C you mention "bar" as int, and "beat" as float, I presume you want to use the decimal part of the float to show "progress" trough that beat? Thinking about very slow BPM's.. that could become important.<br>
<br>-Harry<br><br><div class="gmail_quote">On Tue, Feb 7, 2012 at 12:28 AM, David Robillard <span dir="ltr"><<a href="mailto:d@drobilla.net">d@drobilla.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi all, seeking opinions:<br>
<br>
I have to choose a way to represent beat-based tempo time in 64 bits.<br>
Uses are many, but the main one is event time stamps for plugins.<br>
<br>
Requirements:<br>
 * No odd data sizes (for performance / programmer ease)<br>
 * High precision (ideally close to sample accurate for most tempos)<br>
 * Fits in the same space as two uint32_t's<br>
<br>
Questions:<br>
 * Is "bar" needed?<br>
 * Use floating point?  Rounding errors an issue?<br>
<br>
Options:<br>
<br>
/* A (moderate range, ultra precise) */<br>
struct {<br>
    uint16_t bar;<br>
    uint16_t beat;<br>
    uint32_t tick;<br>
};<br>
<br>
/* B (high range, moderate precision) */<br>
struct {<br>
    uint32_t bar;<br>
    uint16_t beat;<br>
    uint16_t tick;<br>
};<br>
<br>
/* C (high range, good precision?) */<br>
struct {<br>
    uint32_t bar<br>
    float    beat;<br>
};<br>
<br>
/* D (high range/precision, but no bar) */<br>
double beat;<br>
<br>
I havn't run the math on precision yet, but I am leaning towards C.  I<br>
actually hadn't considered mixing int and float before writing this<br>
email, but it seems the best trade-off, and working with float is<br>
certainly more pleasant than fixed point.<br>
<br>
Thoughts?<br>
<br>
-dr<br>
<br>
<br>
_______________________________________________<br>
Linux-audio-dev mailing list<br>
<a href="mailto:Linux-audio-dev@lists.linuxaudio.org">Linux-audio-dev@lists.linuxaudio.org</a><br>
<a href="http://lists.linuxaudio.org/listinfo/linux-audio-dev" target="_blank">http://lists.linuxaudio.org/listinfo/linux-audio-dev</a><br>
</blockquote></div><br>