Bela
Real-time, ultra-low-latency audio and sensor processing system for BeagleBone Black
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
Utilities.h
1 #pragma once
2 
29 static inline float map(float x, float in_min, float in_max, float out_min, float out_max);
30 
47 static inline float constrain(float x, float min_val, float max_val);
48 
54 static inline float min(float x, float y);
55 
61 static inline float max(float x, float y);
62 
65 // map()
66 //
67 // Scale an input value from one range to another. Works like its Wiring language equivalent.
68 // x is the value to scale; in_min and in_max are the input range; out_min and out_max
69 // are the output range.
70 
71 static inline float map(float x, float in_min, float in_max, float out_min, float out_max)
72 {
73  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
74 }
75 
76 // constrain()
77 //
78 // Clips an input value to be between two end points
79 // x is the value to constrain; min_val and max_val are the range
80 
81 static inline float constrain(float x, float min_val, float max_val)
82 {
83  if(x < min_val) return min_val;
84  if(x > max_val) return max_val;
85  return x;
86 }
87 
88 static inline float max(float x, float y){
89  return x > y ? x : y;
90 }
91 
92 static inline float min(float x, float y){
93  return x < y ? x : y;
94 }
95 
static float constrain(float x, float min_val, float max_val)
Constrain a number to stay within a given range.
Definition: Utilities.h:81
static float map(float x, float in_min, float in_max, float out_min, float out_max)
Linearly rescale a number from one range of values to another.
Definition: Utilities.h:71
static float min(float x, float y)
Returns the maximum of two numbers.
Definition: Utilities.h:92
static float max(float x, float y)
Returns the minimum of two numbers.
Definition: Utilities.h:88