Audacity Bug Summary
••• Introduction •••
••• Keywords •••
    Audacity 3.0.3 development began 19th April 2021

Audacity Bugzilla



Bug 449 - Click Track tempo is (slightly) inaccurate
Click Track tempo is (slightly) inaccurate
Status: RESOLVED FIXED
Product: Audacity
Classification: Unclassified
Component: Nyquist
1.3.14 alpha
PC All
: P4 Repeatable
Assigned To: Default Assignee for New Bugs
http://forum.audacityteam.org/viewtop...
: nyquist, patch
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2011-09-03 15:56 UTC by Steve Daulton
Modified: 2018-08-20 11:51 UTC (History)
5 users (show)

See Also:
Steps To Reproduce:
Project rate at 44100. Generate a click track at 130 BPM and 130 bars duration (all other settings at default). The track length should be exactly 4 minutes but is 14 ms too long.
Release Note:
First Git SHA:
Group: ---
Workaround:
Closed: 2018-08-20 00:00:00


Attachments
Steve Daulton's patch to improve length accuracy (7.32 KB, patch)
2011-09-03 21:19 UTC, Gale Andrews
Details | Diff
updated clicktrack.ny file (9.66 KB, text/plain)
2011-09-04 11:16 UTC, Steve Daulton
Details
Updated Click Track plug-in (9.93 KB, application/octet-stream)
2011-12-11 09:06 UTC, Steve Daulton
Details
updated clicktrack.ny (10.04 KB, application/octet-stream)
2011-12-23 08:26 UTC, Steve Daulton
Details
patch file against svn revision 11382 (868 bytes, patch)
2011-12-23 08:43 UTC, Steve Daulton
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Steve Daulton 2011-09-03 15:56:14 UTC
The length of each measure may be inaccurate depending on the track sample rate and the BPM setting.

Revised version posted to the forum (see link).
The changes have turned out to be quite extensive so this will need testing before being committed.
Comment 1 Gale Andrews 2011-09-03 21:19:07 UTC
Created attachment 200 [details]
Steve Daulton's patch to improve length accuracy 

Added as a patch in case any developers want to study it more quickly
Comment 2 Steve Daulton 2011-09-04 08:30:45 UTC
(In reply to comment #1)
I've updated the link to point to the new topic on the forum about this issue.

I'm taking this opportunity to do a general tidy of the code and fix a couple of other minor issues. I'll post the new revised version here when complete.
Comment 3 Steve Daulton 2011-09-04 11:16:34 UTC
Created attachment 201 [details]
updated clicktrack.ny file
Comment 4 Steve Daulton 2011-09-04 11:19:22 UTC
Comment on attachment 201 [details]
updated clicktrack.ny file

.ny plug-in
Comment 5 Steve Daulton 2011-09-04 11:21:10 UTC
Attached the updated clicktrack.ny file.

The name of the plug-in has been (temporarily) changed to "Click Track 2..." to allow it to be installed alongside the original version.
Comment 6 Steve Daulton 2011-12-11 09:06:35 UTC
Created attachment 210 [details]
Updated Click Track plug-in

Updated patch with correct file name, correct plug-in name and code spacing corrected.
Comment 7 Martyn Shaw 2011-12-20 17:48:32 UTC
Since I reviewed the operation of the patch a few weeks ago, and there have been some testers on the forum, I committed this new file.
Comment 8 Gale Andrews 2011-12-21 17:24:05 UTC
Thanks, Steve. Only tested on Win 7. I presume we are not aiming for (what may be perceived as) total accuracy? For example in 1.3.14 Beta, Generate > Click Track at 120 BPM, 1 beat per measure, 120 measures produces 1 min, 0 secs and 1200 samples. In 1.3.15 alpha with the committed patch it is much more accurate - 0 min, 59 secs and 44099 samples. This seems to cause bug 459 or similar to fire as the length of the track is wrongly reported as 59.000 secs in Selection Toolbar.
Comment 9 Steve Daulton 2011-12-21 21:18:11 UTC
(In reply to comment #8)
> I presume we are not aiming for (what may
> be perceived as) total accuracy? For example in 1.3.14 Beta, Generate > Click
> Track at 120 BPM, 1 beat per measure, 120 measures produces 1 min, 0 secs and
> 1200 samples. In 1.3.15 alpha with the committed patch it is much more accurate
> - 0 min, 59 secs and 44099 samples.

The onset of each tick is accurate, but there was another bug in the original click-track that I missed. The function "click" uses pwl to add 5ms fade-in and fade-out to the click. However, by default pwl is calculated at a low sample rate [the control rate], so as in bug 441 the shaped click is a fraction shorter than it should be.

It can be fixed by calculating the 5 ms fade at the sample rate. That is to change line 228 from:
(mult (pwl 0.005 amp 0.995 amp 1)
to:
(mult (control-srate-abs *sound-srate* (pwl 0.005 amp 0.995 amp 1))

Should I create a patch for this or just post an updated clicktrack.ny file?


> This seems to cause bug 459 or similar to
> fire as the length of the track is wrongly reported as 59.000 secs in Selection
> Toolbar.

Confirmed. 
At 44.1 kHz, when extending a selection from 2645977 samples to 2645978 samples, if hh:mm:ss + milliseconds are selected, the End (or Length) displayed on the Selection Toolbar rolls over from 59.999 to 59.000
Comment 10 Steve Daulton 2011-12-21 21:27:44 UTC
(In reply to comment #9)
> Confirmed. 
> At 44.1 kHz, when extending a selection from 2645977 samples to 2645978
> samples, if hh:mm:ss + milliseconds are selected, the End (or Length) displayed
> on the Selection Toolbar rolls over from 59.999 to 59.000

To be clear, this is unrelated to clicktrack.ny (bug 449). The same thing happens with an empty track.
Comment 11 Gale Andrews 2011-12-22 11:03:49 UTC
(In reply to comment #9)
> To be clear, this is unrelated to clicktrack.ny (bug 449). The same thing
> happens with an empty track.
Absolutely. "Fixing" 449 won't fix 459. 

> Should I create a patch for this or just post an updated clicktrack.ny file?
I guess a patch would be better, if you think this is worth fixing. On that assumption I've reopened the bug.
Comment 12 Steve Daulton 2011-12-23 08:26:06 UTC
Created attachment 219 [details]
updated clicktrack.ny

Fixes incorrect length of clicks.
Click track should now be accurate to within 1 sample for all settings.

also set value for "len" so that the progress bar now works.

Tested on Linux, Windows and Mac.
Comment 13 Steve Daulton 2011-12-23 08:43:54 UTC
Created attachment 220 [details]
patch file against svn revision 11382
Comment 14 Martyn Shaw 2011-12-23 09:42:51 UTC
(In reply to comment #13)
Committed most recent patch.
Martyn
Comment 15 Gale Andrews 2011-12-24 03:06:52 UTC
441000 Hz, 120 BPM, 1 beat per measure, 120 measures produces 1 min, 0 secs 00000
samples. Steps to repro (130 BPM, 4 beats per measure, 130 measures) produces 4 min 0 secs 00001 samples (but at 200 Hz, 8000 Hz or 392000 Hz is accurate). Width of click or offset doesn't affect accuracy. 

So please move it to RESOLVED - FIXED if you are happy, Steve.
Comment 16 Steve Daulton 2011-12-24 07:20:37 UTC
(In reply to comment #15)
> 130 BPM, 4 beats per measure, 130 measures) produces 4
> min 0 secs 00001 samples

I would expect some combinations of tempo, beats per bar and sample rate to give a small rounding error, but I think the discrepancy is now negligible so I've marked this as fixed.
Comment 17 Steve Daulton 2011-12-24 08:31:48 UTC
(In reply to comment #16)

The remaining "error" is because the final beat duration is calculated to the closest sample, rather than calculating the final bar length to the closest sample. This could be "corrected" by:

making "mtime" global 
and changing line 295 from:

(s-rest(- beatlen ticklen)))) ;trailing silence

to

(s-rest(- (+ mtime (* sig beatlen))(/ (snd-length clicktrack ny:all) *sound-srate*))))) ;trailing silence

but it would look a bit odd if one bar was created and the final beat duration was 1 sample shorter than every other beat.

The choice is to either have the final beat length duration to the closest sample, or the final bar length (hence the overall click track duration) to the closest sample. Either way I don't think the discrepancy should ever be more than 1 sample.

The first option (as per the current version) is neater and the code more transparent so I'd go with the current version, but if anyone disagrees, I can change it.
Comment 18 Gale Andrews 2011-12-24 12:04:23 UTC
(In reply to comment #17)
I think it's OK now and arguable either way. The only case I could possibly see for calculating the final bar length to the closest sample would be if someone was using click track sequences for loops and repeating them. Would a code comment about this be appropriate?
Comment 19 Steve Daulton 2011-12-24 14:09:28 UTC
(In reply to comment #18)
> Would a code comment about this be appropriate?

Considering how long it took for anyone to notice that the old version was inaccurate and how much more accurate the current version is, I'm happy to leave it as it is.