-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.h
87 lines (73 loc) · 1.91 KB
/
utils.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/**
* @file utils.h
* @brief Audio utilities
*
*/
#ifndef __UTILS_H
#define __UTILS_H
#include <iostream>
#include <string>
static const float PI = 3.1415927f;
// mono panning using a sin/cos taper to avoid the 6db drop at the centre
inline void panmono(float *__restrict left,
float *__restrict right,
float *__restrict in,
float pan,float amp,int n){
float ampl = cosf(pan*PI*0.5f);
float ampr = sinf(pan*PI*0.5f);
for(int i=0;i<n;i++){
*left++ = *in * ampl;
*right++ = *in++ * ampr;
}
}
// stereo panning (balance) using a linear taper
inline void panstereo(float *__restrict leftout,
float *__restrict rightout,
float *__restrict leftin,
float *__restrict rightin,
float pan,float amp,int n){
if(pan<0.5f){
pan *= 2.0f;
for(int i=0;i<n;i++){
*leftout++ = *leftin++ * amp;
*rightout++ = *rightin++ * pan * amp;
}
} else {
pan = (1.0f-pan)*2.0f;
for(int i=0;i<n;i++){
*leftout++ = *leftin++ * pan * amp;
*rightout++ = *rightin++ * amp;
}
}
}
inline void addbuffers(float *__restrict dest,
float *__restrict v, int n, float gain){
for(int i=0;i<n;i++){
*dest++ += gain**v++;
}
}
class PeakMonitor {
private:
char *name;
float cur;
int iv;
public:
int maxiv;
PeakMonitor(std::string n){
name=strdup(n.c_str());
cur=0;iv=0;maxiv=10;}
PeakMonitor(std::string n,int i){
name=strdup(n.c_str());
cur=0;iv=0;maxiv=i;}
void in(float *v,int n){
for(int i=0;i<n;i++){
float q = fabs(*v++);
if(q>cur)
cur = q;
else
cur = q*0.01f + cur*0.99f;
}
}
float get(){return cur;}
};
#endif /* __UTILS_H */