Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
executable file
·
22 lines (19 loc) · 899 Bytes

File metadata and controls

executable file
·
22 lines (19 loc) · 899 Bytes
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include "mozzi_utils.h"
/** @ingroup util
Given a power of 2, work out the number to shift right by to do a divide by the number, or shift left to multiply.
@param a power of 2, or any other number for that matter
@return the number of trailing zeros on the right hand end
*/
long trailingZeros(const unsigned long v) {
// find the number of trailing zeros in v, from http://graphics.stanford.edu/~seander/bithacks.html#ZerosOnRightFloatCast
// there are faster methods on the bit twiddling site, but this is short
float f = (float)(v & -v); // cast the least significant bit in v to a float
return (*(uint32_t *)&f >> 23) - 0x7f;
}
/** Convert BPM to milliseconds, which can be used to set the delay between beats for Metronome.
@param bpm beats per minute
*/
unsigned int BPMtoMillis(float bpm){
float seconds_per_beat = 60.f/bpm;
return (unsigned int) (seconds_per_beat*1000);
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.