-
Notifications
You must be signed in to change notification settings - Fork 197
/
tremelo.ino
53 lines (39 loc) · 1.23 KB
/
tremelo.ino
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
/*
pedalShieldUno/AudioDSP/tremelo
Alternate implementation of the pedalshield_uno_tremelo effect.
- creates a tremolo effect, modulating the volume with a sinewave.
- pressing the pushbutton_1 or 2 makes the modulation faster or slower.
For info and circuit diagrams see https://github.com/tardate/LittleArduinoProjects/tree/master/playground/pedalShieldUno/AudioDSP/tremelo
*/
#include <AudioDspDriver.h> // main AudioDSP controller class
#include "waveform.h"
AudioDspDriver dsp_driver;
int sample = 0;
int step = 0;
void setup() {
dsp_driver.init();
}
void loop() {
dsp_driver.process_controls();
}
/* transformer
* the input signal is 16 bit signed (values from -32768 to +32767, INT16_MIN to INT16_MAX)
* pb_level is 0-1024 with midpoint 512
*/
int16_t transformer(int16_t input, int pb_level) {
int adjustment = map(pb_level, 0, 1024, 9, 0);
step++;
if(step >= adjustment) {
step = 0;
sample++;
if(sample>1023) sample = 0;
}
int16_t volume = map(waveform[sample], 0, 0xFF, 0, INT16_MAX);
return map(input, INT16_MIN, INT16_MAX, -volume, volume);
}
/* Timer 1 interrupt service routine
* Perform audio input/processing/output here
*/
ISR(TIMER1_CAPT_vect) {
dsp_driver.transform(&transformer);
}