I often find Renoise guesses double the speed of samples I load when I enable Beat Sync.

It often reports 8 when 16 would be more appropriate, or 32 when 64 would be a better fit.

This little bit of lua seems to do a better job to me:

```
-- round value to nearest integer
function round(x)
return math.floor(0.5 + x)
end
-- samples length in seconds
function sample_length(sample)
local frames = sample.sample_buffer.number_of_frames
local rate = sample.sample_buffer.sample_rate
return frames / rate
end
-- Guesses the number of lines in a loop at the given bpm
function guess_length_in_lines(sample)
local rns = renoise.song()
local length = sample_length(sample)
-- calculate song's beats per second
local bps = rns.transport.bpm / 60
-- calculate samples length in beats at current bpm
local beats_at_bpm = length * bps
-- closest power of two finds us 1, 2, 4, 8, 16, 32 beats etc.
local beats_in_loop = 2 ^ round(math.log(beats_at_bpm) / math.log(2))
-- return a nice round number of lines
return beats_in_loop * rns.transport.lpb
end
```

I know this kind of guessing can be a little arbitrary but is Renoise finding a floor when it could be rounding?