forked from PaulStoffregen/Audio
-
Notifications
You must be signed in to change notification settings - Fork 3
/
effect_reverb.h
118 lines (97 loc) · 3.29 KB
/
effect_reverb.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
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
/* Reverb for Teensy
*
* Author: Joao Rossi Filho
*
* Soon I'll make a commit with nice comments and discription
*
* Copyright (c) 2016 Joao Rossi FIlho
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef effect_reverb_
#define effect_reverb_
#include <AudioStream.h> // github.com/PaulStoffregen/cores/blob/master/teensy4/AudioStream.h
#define APF1_BUF_LEN 600
#define APF2_BUF_LEN 1300
#define APF3_BUF_LEN 500
#define LPF1_BUF_LEN 1400
#define LPF2_BUF_LEN 1700
#define LPF3_BUF_LEN 1800
#define LPF4_BUF_LEN 2000
#define APF1_DLY_LEN 586
#define APF2_DLY_LEN 1239
#define APF3_DLY_LEN 485
#define LPF1_DLY_LEN 1398
#define LPF2_DLY_LEN 1637
#define LPF3_DLY_LEN 1774
#define LPF4_DLY_LEN 1947
#define LPF1_DLY_SEC 0.03171
#define LPF2_DLY_SEC 0.03711
#define LPF3_DLY_SEC 0.04023
#define LPF4_DLY_SEC 0.04414
class AudioEffectReverb : public AudioStream
{
public:
AudioEffectReverb(void) : AudioStream(1, inputQueueArray) {
init_comb_filters();
clear_buffers();
reverbTime(5.0);
}
virtual void update(void);
void reverbTime(float);
private:
struct comb_apf {
int32_t g;
int32_t *buffer;
uint32_t buf_len;
uint32_t delay, rd_idx, wr_idx;
};
struct comb_lpf {
int32_t g1, g2, z1;
int32_t *buffer;
uint32_t buf_len;
uint32_t delay, rd_idx, wr_idx;
};
void init_comb_filters(void);
void clear_buffers(void);
static void _do_comb_apf(struct comb_apf *apf, int32_t *in_buf, int32_t *out_buf);
static void _do_comb_lpf(struct comb_lpf *lpf, int32_t *in_buf, int32_t *out_buf);
audio_block_t *inputQueueArray[1];
struct comb_apf apf[3];
struct comb_lpf lpf[4];
float reverb_time_sec;
float g_flt_apf[3];
int32_t g_q31_apf[3];
float g1_flt_lpf[4];
int32_t g1_q31_lpf[4];
float g2_flt_lpf;
int32_t g2_q31_lpf;
int32_t apf1_buf[APF1_BUF_LEN];
int32_t apf2_buf[APF2_BUF_LEN];
int32_t apf3_buf[APF3_BUF_LEN];
int32_t lpf1_buf[LPF1_BUF_LEN];
int32_t lpf2_buf[LPF2_BUF_LEN];
int32_t lpf3_buf[LPF3_BUF_LEN];
int32_t lpf4_buf[LPF4_BUF_LEN];
int32_t q31_buf[AUDIO_BLOCK_SAMPLES];
int32_t sum_buf[AUDIO_BLOCK_SAMPLES];
int32_t aux_buf[AUDIO_BLOCK_SAMPLES];
};
#endif