Mozzi  version 2016-12-11-17:03
sound synthesis library for Arduino
mozzi_utils.cpp
1 #include "mozzi_utils.h"
2 
8 long trailingZeros(const unsigned long v) {
9  // find the number of trailing zeros in v, from http://graphics.stanford.edu/~seander/bithacks.html#ZerosOnRightFloatCast
10  // there are faster methods on the bit twiddling site, but this is short
11  float f = (float)(v & -v); // cast the least significant bit in v to a float
12  return (*(uint32_t *)&f >> 23) - 0x7f;
13 }
14 
15 
19  unsigned int BPMtoMillis(float bpm){
20  float seconds_per_beat = 60.f/bpm;
21  return (unsigned int) (seconds_per_beat*1000);
22  }
long trailingZeros(const unsigned long v)
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.
Definition: mozzi_utils.cpp:8