Beat Per Minute labels

Share your Audacity/Nyquist plug-ins here, or test drive the latest plug-ins submitted by Audacity users.

After testing a plug-in from this forum, please post feedback for the plug-in author.
steve
Site Admin
Posts: 47940
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu
Contact:

Beat Per Minute labels

Post by steve » Fri Sep 02, 2011 5:30 pm

How do I turn on the Bars and Beats grid?
How do I Snap an audio clip to a particular beat?
I saw a Sonar video where they had little grid bars they could grab and move to the start of each note that corrected any sloppy timing.
My song is 140 bpm but I can only snap to whole second...
Audacity does not have any kind of "timing grid" and the "Time Line" only shows hh:mm:ss and not bars:beats (though there is a feature request for this).

Currently, the closest thing to these features in Audacity is to create "Regular Interval Labels", then audio clips can "snap" to the label positions.

Unfortunately, "Regular Interval Labels" is not a very convenient tool for this job. First you have to convert BPM to "seconds". Then if you want bars and beats, you need to create two sets of labels - one for the bars and one for the beats. Also there is no provision for "swing", or tempo changes.

To address these shortcomings, here's a plug-in that will create labels based on BPM settings.
I think that it is well featured and hopefully it will be obvious how to use it without instructions or help screens.

Note, this is a "Generate" type plug-in and when installed will appear in the Generate menu.
Most plug-ins that create labels are "Analyze" type, but for this plug-in I thought that users may want to create their "timing track" right at the start of a project before any audio tracks have been created. "Generate" plug-ins are the only type that can run without an audio track already existing.
Also, by making this a Generate plug-in, the start point of the labels can be set by clicking on an existing track (with or without a selected region), whereas Analyze plug-ins are not available unless there is a selected region. (see here for additional comments on this "feature" http://forum.audacityteam.org/viewtopic ... 52#p155498 )

Before anyone asks, no it does not extract the BPM from an existing audio track. BPM detection is another project and not currently good enough to provide accurate timing data for making BPM labels. This may come in a future version, but that's still a long way off.

Any other comments, questions, suggestions or other feedback are very welcome.

This plug-in requires a recent version of Audacity 1.3.x
See here for installation instructions. http://manual.audacityteam.org/o/man/ef ... st_effects
bmp-labels.ny
*** OBSOLETE ***
(3.66 KiB) Downloaded 746 times
Download latest version
Last edited by steve on Tue Oct 13, 2015 9:45 am, edited 4 times in total.
Reason: Updated link to installation instructions
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

Frankelstner
Posts: 9
Joined: Wed Aug 31, 2011 10:38 pm
Operating System: Please select

Re: Beat Per Minute labels

Post by Frankelstner » Sat Sep 03, 2011 5:45 am

The basic features seem to work correctly (which is all I personally need). I'm sure you've noticed the typo already ("Peats"). The default value for the number of bars ought to be 16, as that's the value used for click track as well. Speed up/down might need some documentation, as I don't think I'll still know what it does in a few weeks. And I suppose you can remove the randomized beats altogether (I simply can't think of any situation when this would come in handy). Nevertheless, this is a very useful plug-in which I can see myself using quite a bit in the future.

However when comparing the labels and a click track at 130 bpm I noticed that they are slightly different. At first I thought your plug-in was wrong, but after a closer I look I realized it's the click track itself. It basically gets worse after every measure whereas the beats within the measures are correct (they are off just as well as the entire measure, but they don't add anything to the problem).

Image

I could fix this by replacing

Code: Select all

(dotimes (x (- measures 1))
  (setf result (seq result measure)))
with:

Code: Select all

(dotimes (x (- measures 1))
  (setf result (sim result(at (* (+ x 1) sig beatlen) (cue measure)))))
So instead of sticking all measures together I added the current result and a measure at the next position and made that the new result. Maybe there are better ways to do this though.

Of course these are just minor differences (there are no differences at all on 120 bpm), but still, 16 ms difference after 5 minutes for four beats per measure is quite formidable in my opinion.

steve
Site Admin
Posts: 47940
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu
Contact:

Re: Beat Per Minute labels

Post by steve » Sat Sep 03, 2011 7:41 pm

Frankelstner wrote: I'm sure you've noticed the typo already ("Peats").
Thanks - fixed that.

I've also noticed that there's a division by zero error if the number of bars is set to 1, so I'll need to fix that also.
Frankelstner wrote:The default value for the number of bars ought to be 16, as that's the value used for click track as well.
Or we could change the default in Click Track to 8 ;)
In most cases I'd expect that the user would set this value to suit there needs and using the default would be pretty rare.
Frankelstner wrote: Speed up/down might need some documentation,
If I was going to explain that I'd just say that it makes the tempo speed up or slow down by the specified number of beats per minute - which is pretty well what the control says.
I suppose it's not obvious that the speed changes from bar to bar rather than from beat to beat (so the tempo within any one bar is constant). I don't think that it justifies a built-in help screen but I'll add a text file with some documentation. The "Swing" and "Randomize" settings may also be worth a note.
Frankelstner wrote:At first I thought your plug-in was wrong,
:o
Frankelstner wrote:It basically gets worse after every measure
The problem is line numbers 272 - 273.

Code: Select all

(setf measure (sim measure
                   (stretch-abs (* sig beatlen) (const 0.0))))
(stretch-abs) performs a linear time transformation to make 1 second of silence (created at the control sample rate) stretch (approximately) to the length of the bar, but depending on the precise bar length and sample rate, the final (stretched) length may not be exact.

A more accurate method would be to use (s-rest [duration]) to generate silence of the required length, so those lines would become:

Code: Select all

(setf measure (sim measure (s-rest (* sig beatlen))))
Because s-rest is generated at the current sound sample rate it will be accurate to within 1 sample (per bar).
This gives an accuracy at 130 bpm, 1 beat per bar, of about 2 ms over a 5 minute track at 48 kHz.

I think the worst case scenario should be if the tempo were such that the bar length fell in the middle between 2 samples. This would give an error of 0.011337868 ms per bar at a sample rate of 44100 Hz.
Frankelstner wrote:16 ms difference after 5 minutes for four beats per measure is quite formidable in my opinion.
I'd say that it was pretty tiny (about 0.0023%), but for some tempos it can be worse (129 bpm with 1 beat per bar at 48kHz sample rate gives an error of over 0.12 seconds) and its better if it's right.
Frankelstner wrote:I could fix this by replacing....with

Code: Select all

  (setf result (sim result(at (* (+ x 1) sig beatlen) (cue measure)))))
Something like this is probably the neatest solution as it avoids cumulative errors altogether. Looking back to lines 272 - 273 we see that these lines are now redundant as we are not using the length of the measure to set the start position of the next measure.
The only drawback to this is that we then loose the trailing silence at the end of the track, so we could add that on at the end by replacing:

Code: Select all

(setf result (if (= offset 0) result
(sim (s-rest offset) (at-abs offset (cue result)))))

; return [click track] result
result
with

Code: Select all

(seq (s-rest offset)(cue result)(s-rest(- beatlen ticklen)))
as this returns the final click track the last couple of lines are not required.

David's code is probably not the best example of code formatting - he did not tend to use line indentations because he was blind. While trying to unravel his code I've added some indentations which will hopefully make it a little easier to follow. I've also restructured his error checking code so that it's no longer checking double negatives. The only other change that I've made is to remove "0 0" from the start of two (pwl) functions as t=0 l=0 is implicit with (pwl).

The only change that I made to your code was to use (1+ x) rather than (+ x 1).

I've attached a revised version, renamed as clicktrack2.ny. The changes have turned out to be somewhat more extensive than I originally intended so it would be helpful if it could be tested by as many people as possible - particularly the error checking aspects. This effect will be listed as "Click Track 2..." so that it can be installed alongside the original version.
Attachments
clicktrack2.ny
(9.74 KiB) Downloaded 278 times
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

steve
Site Admin
Posts: 47940
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu
Contact:

Re: Beat Per Minute labels

Post by steve » Sat Sep 03, 2011 8:15 pm

And here's the fixed version of bpm-labels.ny
bmp-labels.ny
*** OBSOLETE ***
(3.63 KiB) Downloaded 279 times
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

Gale Andrews
Quality Assurance
Posts: 26087
Joined: Fri Jul 27, 2007 12:02 am
Operating System: Windows 10
Contact:

Re: clicktrack2.ny

Post by Gale Andrews » Sun Sep 04, 2011 2:20 am

steve wrote: I've attached a revised version, renamed as clicktrack2.ny. The changes have turned out to be somewhat more extensive than I originally intended so it would be helpful if it could be tested by as many people as possible - particularly the error checking aspects. This effect will be listed as "Click Track 2..." so that it can be installed alongside the original version.
Thanks, Steve.

I had a casual test. It seems much more accurate in length generation than the old Click Track. I did not find any cases that were too long, but some were one or two samples too short unless 8000 Hz was used.

I noticed it errored on double positives but not single positives.

I guess we should take the opportunity as per current conventions to trim the licence in the ;info line to "Released under GPL v2." and add the following to the comments:

Code: Select all

;; Released under terms of the GNU General Public License version 2:
;; http://www.gnu.org/licenses/old-licenses/gpl-2.0.html .
Would this be an opportunity to allow fractional BPM in the Tempo field, given people are asking for the built-in Change Speed and Change Tempo to support this? If not, perhaps the Help should state this is not supported?

PS I notice crossfadeout.ny and crossfadein.ny are not licensed at all (nor clipfix.ny, but I don't know if I can contact Ben to ask him about that). So should we add the above GPL comment to those two crossfades?



Gale
________________________________________FOR INSTANT HELP: (Click on Link below)
* * * * * Tips * * * * * Tutorials * * * * * Quick Start Guide * * * * * Audacity Manual

steve
Site Admin
Posts: 47940
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu
Contact:

Re: Beat Per Minute labels

Post by steve » Sun Sep 04, 2011 12:25 pm

Gale Andrews wrote:So should we add the above GPL comment to those two crossfades?
As both of these are basically just one line of code I'd guess that when written it wasn't considered worth the space.
I suppose that strictly speaking they should carry a GPL comment. Even if we replace these effects I'd expect that we'd keep an archive copy on the wiki, so if you're able to get hold of Ben then that would be best. I don't know where these effects came from initially, but as they are bundled with Audacity I would have thought that there must have been at least an implied agreement that they were GPL.
Gale Andrews wrote: I guess we should take the opportunity as per current conventions to trim the licence in the ;info line to "Released under GPL v2." and add the following to the comments:
Yes.
Gale Andrews wrote:Would this be an opportunity to allow fractional BPM in the Tempo field, given people are asking for the built-in Change Speed and Change Tempo to support this?
I don't see any problem with that.

We've drifted some way off the original topic so I've started a new topic about Click Track here: http://forum.audacityteam.org/viewtopic ... 93#p155793
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

Gale Andrews
Quality Assurance
Posts: 26087
Joined: Fri Jul 27, 2007 12:02 am
Operating System: Windows 10
Contact:

Re: Plug-in licensing

Post by Gale Andrews » Sun Sep 04, 2011 11:29 pm

steve wrote:
Gale Andrews wrote:So should we add the above GPL comment to those two crossfades?
As both of these are basically just one line of code I'd guess that when written it wasn't considered worth the space.
I suppose that strictly speaking they should carry a GPL comment. Even if we replace these effects I'd expect that we'd keep an archive copy on the wiki, so if you're able to get hold of Ben then that would be best. I don't know where these effects came from initially, but as they are bundled with Audacity I would have thought that there must have been at least an implied agreement that they were GPL.
Sure, but I think someone could question if most plug-ins are GPL and a few aren't, what the licence of the unlicensed plug-ins actually is. The two crossfades were added by Dominic originally, so I assume he wrote them, but I don't know. I'll ask him if we can include the two comment lines to make the plug-ins GPL.

Clip Fix definitely isn't GPL, but Ben agreed to have it included in Audacity and let anyone modify or distribute it, without wanting to tie the licence down or make the terms explicit in the plug-in. That isn't ideal, but I've reached him today and he is now very happy to make the plug-in GPL so that anyone can openly work on improving it. I pointed him to the main discussion thread we had on improving it:
http://forum.audacityteam.org/viewtopic.php?f=39&t=4377



Gale
________________________________________FOR INSTANT HELP: (Click on Link below)
* * * * * Tips * * * * * Tutorials * * * * * Quick Start Guide * * * * * Audacity Manual

Frankelstner
Posts: 9
Joined: Wed Aug 31, 2011 10:38 pm
Operating System: Please select

Re: Beat Per Minute labels

Post by Frankelstner » Mon Sep 05, 2011 1:17 am

Back to BPM labels.

The only bug I could spot is the following. When setting "Bars (only)" at Label Text it will not put anything in the labels (similar to selecting "none"). This worked correctly in your first version though, sneaky bugs.

It has also come to my mind that an option to put markers/labels at bars only might come in handy. This way one can combine a click track and BPM labels to select bars easily without too many markers and still get to the individual beats just by looking at the click track. Additionally it could be useful to be able to define an offset as right now the labels always start at the origin.

steve
Site Admin
Posts: 47940
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu
Contact:

Re: Beat Per Minute labels

Post by steve » Mon Sep 05, 2011 7:10 am

Frankelstner wrote:The only bug I could spot is the following. When setting "Bars (only)" at Label Text it will not put anything in the labels (similar to selecting "none"). This worked correctly in your first version though, sneaky bugs.
Thanks for testing, I'll check that out tonight.
Frankelstner wrote:It has also come to my mind that an option to put markers/labels at bars only might come in handy.
Same as "Beats per bar = 1" ?
Frankelstner wrote:Additionally it could be useful to be able to define an offset as right now the labels always start at the origin.
Labels always start at the Cursor position, or the start of the selection, or at time=0 if there none selected. This was one of the main reasons for making it a Generator plug-in (see first topic post for explanation).
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

Frankelstner
Posts: 9
Joined: Wed Aug 31, 2011 10:38 pm
Operating System: Please select

Re: Beat Per Minute labels

Post by Frankelstner » Mon Sep 05, 2011 8:04 am

steve wrote:Same as "Beats per bar = 1" ?
Almost, however when setting beats per bar to 1 I need to set the BPM to 1/4 for a song with actually 4 beats per bar. It's possible, but not as convenient.
steve wrote:Labels always start at the Cursor position, or the start of the selection, or at time=0 if there none selected. This was one of the main reasons for making it a Generator plug-in (see first topic post for explanation).
You are right. I think in my initial tests I started with no tracks at all and set a marker at a certain time, then created labels and saw them appear at 0. But with an existing track it will work just fine. I do believe however that there shouldn't be an offset option for the click track plug-in then. I like to see both plug-ins being kind of symmetrical when it comes to these things. Everything tidied up. :)

Post Reply