21#ifndef PQ_PHASE_UTILS_H_
22#define PQ_PHASE_UTILS_H_
24#if (defined(ARDUINO) && ARDUINO >= 100) || defined(EPOXY_DUINO)
30#include "pq_globals.h"
32#include "pq_fixed32_math.h"
41inline q0_32u_t amplifyFixed32(q0_32u_t x, q0_32u_t amplitude) {
43 int32_t centered = (int32_t)(x ^ HALF_FIXED_32_MAX);
46 centered = ((int64_t)centered * amplitude) >> 32;
49 return (q0_32u_t)(centered ^ HALF_FIXED_32_MAX);
53inline float amplifyFloat(
float x, q0_32u_t amplitude) {
54 return fixed32ToFloat(amplitude) * (x - 0.5f) + 0.5f;
58inline q0_32u_t floatToPhase32(
float x) {
return floatToFixed32(x); }
61inline q0_32u_t fixed32Divide(q0_32u_t x, q0_32u_t y) {
return divide_32div32(x, y); }
64inline q0_32u_t fixed32Multiply(q0_32u_t x, q0_32u_t y) {
return multiply_32x32_rshift32(x,y) ;}
67inline float timeToPhase(
float period,
float time) {
return period == 0 ? 0 : time / period; }
70inline float frequencyAndTimeToPhase(
float frequency,
float time) {
return time * frequency; }
73inline float invert(
float x) {
return (x == 0) ? FLT_MAX : 1.0f / x; }
76inline float periodToFrequency(
float period) {
return invert(period); }
79inline float frequencyToPeriod(
float frequency) {
return invert(frequency); }
85q0_32u_t phase32AddPhase(q0_32u_t phase32,
float phase);
88q0_32u_t phase32AddTime(q0_32u_t phase32,
float period,
float time);
91bool phase32UpdateFixed32(q0_32u_t& phase32,
float frequency,
float deltaTimeSecondsTimesFixed32Max,
bool forward =
true);
94bool phase32Update(q0_32u_t& phase32,
float period,
float sampleRate,
bool forward =
true);