-
Notifications
You must be signed in to change notification settings - Fork 1
/
wrMix.c
141 lines (117 loc) · 2.46 KB
/
wrMix.c
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#include <wrMix.h>
#include <stdlib.h>
#include <wrMath.h>
#include <wrTrig.h>
// INIT FUNCTIONS
int8_t mix_tanh_init(mix_tanh_t* mix, uint16_t size)
{
int8_t err = 0;
mix->bus = 0;
mix->hpf = dc_init();
mix->b_size = size;
mix->bus_v = NULL;
mix->bus_v = malloc(sizeof(float)*size);
if( mix->bus_v == NULL ){ err = 1; }
for( uint16_t i=0; i<size; i++ ){
mix->bus_v[i] = 0.0;
}
return err;
}
int8_t mix_peaks_init(mix_peaks_t* mix, uint16_t size, uint16_t chans)
{
int8_t err = 0;
mix->bus = 0;
mix->b_size = size;
mix->scale = NULL;
mix->scale = malloc(sizeof(float)*chans);
if( mix->scale == NULL ){ err = 1; }
for(uint16_t i=0; i<chans; i++){
mix->scale[i] = 1 / (float)(i+1);
}
mix->bus_v = NULL;
mix->bus_v = malloc(sizeof(float)*size);
if(mix->bus_v == NULL) { err = 2; }
for( uint16_t i=0; i<size; i++ ){
mix->bus_v[i] = 0.0;
}
return err;
}
//////////
// TANH //
//////////
void mix_tanh_add(mix_tanh_t* mix, float input)
{
mix->bus += input;
}
float mix_tanh_step(mix_tanh_t* mix)
{
float tmp = dc_step( mix->hpf, mix->bus );
mix->bus = 0;
return tanh_fast(tmp);
}
///////////
// PEAKS //
///////////
void mix_peaks_add(mix_peaks_t* mix, float input, uint16_t ix)
{
float tmp = input * mix->scale[ix];
// float tmp = input;
if(tmp > mix->bus){
mix->bus = tmp;
}
}
float mix_peaks_step(mix_peaks_t* mix)
{
float tmp = mix->bus;
mix->bus = -1.0; // reset bus
return tmp;
}
////////////
// TANH_V //
////////////
void mix_tanh_add_v(mix_tanh_t* mix, float* input)
{
float* bus2 = mix->bus_v;
for(uint16_t i=0; i<(mix->b_size); i++){
*bus2++ += *input++;
}
}
void mix_tanh_v(mix_tanh_t* mix, float* output)
{
float* bus2 = mix->bus_v;
for(uint16_t i=0; i<(mix->b_size); i++){
output[i] = mix->bus_v[i];
}
tanh_fast_v( dc_step_v( mix->hpf
, output
, mix->b_size)
, mix->b_size
);
for(uint16_t i=0; i<(mix->b_size); i++){
*bus2++ = 0; // zero mix bus
}
}
/////////////
// PEAKS_V //
/////////////
void mix_peaks_add_v(mix_peaks_t* mix, float* input, uint16_t ix)
{
float tmp;
float* bus2 = mix->bus_v;
for(uint16_t i=0; i<(mix->b_size); i++){
tmp = (*input++) * mix->scale[ix];
if(tmp > *bus2){
*bus2 = tmp;
}
bus2++;
}
}
void mix_peaks_v(mix_peaks_t* mix, float* output)
{
float* bus2 = mix->bus_v;
float* out2 = output;
for(uint16_t i=0; i<(mix->b_size); i++){
*out2++ = *bus2;
*bus2++ = -1.0;
}
}