-
Notifications
You must be signed in to change notification settings - Fork 16
/
ModuleDelay.cpp
41 lines (33 loc) · 912 Bytes
/
ModuleDelay.cpp
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
#include "Arduino.h"
#include "ModuleDelay.h"
#include "defines.h"
#include "GlobalRingBuffer.h"
ModuleDelay::ModuleDelay()
{
buffer_index = 0;
delay_output = 0;
audio_input = NULL;
mix_input = NULL;
feedback_input = NULL;
length_input = NULL;
}
uint16_t ModuleDelay::compute()
{
uint32_t audio = this->readInput(audio_input);
uint32_t wet_mix = this->readInput(mix_input);
uint32_t feedback = this->readInput(feedback_input);
uint16_t buffer_length = this->readInput(length_input);
uint32_t dry_mix = 4095 - wet_mix;
buffer_index++;
if(buffer_index >= buffer_length) buffer_index = 0;
delay_output = RING_BUFFER[buffer_index];
RING_BUFFER[buffer_index] = ((audio * (4095 - feedback)) >> 12) + ((delay_output * feedback) >> 12);
if(wet_mix == 0)
{
return(audio);
}
else
{
return(((delay_output * wet_mix) >> 12) + ((audio * dry_mix) >> 12));
}
}