74/* NOTE: previous version of the above is super-nifty, but pulls in software float code on AVR (the platform where it makes a difference), leading to bloat and a compile time warning.
75 * Sine the only use-case I could find works on a compile-time constant (template-parameter), I added a constexpr function in mozzi_utils.h, instead. I renamed it, too,
76 * so, we'll learn about any use-case outside of this scope. If there are no reports of breakage, the following can probably be removed for good.
77long trailingZeros(unsigned long v) {
78 // find the number of trailing zeros in v, from http://graphics.stanford.edu/~seander/bithacks.html#ZerosOnRightFloatCast
79 // there are faster methods on the bit twiddling site, but this is short
80 float f = (float)(v & -v); // cast the least significant bit in v to a float
81 return (*(uint32_t *)&f >> 23) - 0x7f;
82}
83
84Here's an alternate, trivial version:
85uint8_t trailingZeros(uint16_t v) {
86 uint8_t ret = 0;
87 while ((v % 2) == 0) {
88 v = v >> 1;
89 ++ret;
90 }
91 return ret;
92} */
93
94
95/** Convert BPM to milliseconds, which can be used to set the delay between beats for Metronome.
96@param bpm beats per minute
97*/
98constexpr uint16_t BPMtoMillis(float bpm){
99//float seconds_per_beat = 60.f/bpm;
100return (uint16_t) (((float) 60.f/bpm)*1000);
101 }
102
103#endif/* UTILS_H_ */
Generated automatically using Doxygen. If info on this page is outdated, incomplete, or wrong, please open an issue at https://github.com/sensorium/Mozzi/issues