-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrem.cpp
More file actions
49 lines (39 loc) · 1.08 KB
/
Copy pathtrem.cpp
File metadata and controls
49 lines (39 loc) · 1.08 KB
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
#include <hls_stream.h>
#include <ap_int.h>
#include "trem.h"
static float dep = 1.0;
static short counter_limit = 4000;
static short control = 1;
static short mod = 0;
static float offset = 1 - dep;
float tremolo_calculation(float xin) {
float yout;
float m;
//Generating the triangle signal, limiting to the depth (pos and neg)
//Trying to maintain less than 10hz
m = (float)mod*(float)dep/(float)counter_limit;
yout = (m + offset)*xin;
mod = mod+control;
if (mod > counter_limit) {
control = -1;
}
else if(!mod) {
control = 1;
}
return yout;
}
void trem(
hls::stream<float> &in, //source of input samples
hls::stream<float> &out //source of output samples
) {
#pragma HLS INTERFACE axis register both port=out
#pragma HLS INTERFACE axis register both port=in
#pragma HLS INTERFACE ap_ctrl_none port=return
#pragma HLS DATAFLOW
float trem_out = 0;
float trem_in;
in >> trem_in; //Converting input stream to signed notation
trem_out = tremolo_calculation(trem_in);
/*Send the output value to the codec*/
out << trem_out;
}