-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdelay.cpp
More file actions
52 lines (42 loc) · 1.08 KB
/
delay.cpp
File metadata and controls
52 lines (42 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
50
51
52
#include <cstddef>
#ifndef UNIT_TEST
#include "daisy_seed.h"
#include "daisysp.h"
using namespace daisy;
using namespace daisysp;
Oscillator osc;
DaisySeed hw;
#endif
#define BUFFER_LEN 44100 * 2 /* 2 seconds */
#define FEEDBACK 0.3
static int delay_samples = 22000;
static float buffer[BUFFER_LEN] = {};
static int buffer_pos = 0;
#ifndef UNIT_TEST
void AudioCallback(AudioHandle::InputBuffer in, AudioHandle::OutputBuffer out,
size_t size) {
for (size_t i = 0; i < size; i++) {
auto sample = in[0][i] / 2.0;
auto delayed_signal = buffer[buffer_pos];
buffer[buffer_pos] = sample + (delayed_signal * FEEDBACK);
buffer_pos = (buffer_pos + 1) % (delay_samples - 1);
out[0][i] = sample + delayed_signal;
}
}
#endif
#ifndef UNIT_TEST
int main() {
hw.Configure();
hw.Init();
hw.SetAudioBlockSize(4);
AdcChannelConfig adcConfig;
adcConfig.InitSingle(hw.GetPin(21));
hw.adc.Init(&adcConfig, 1);
hw.adc.Start();
hw.StartAudio(AudioCallback);
for (;;) {
delay_samples = (int)(hw.adc.GetFloat(0) * BUFFER_LEN);
System::Delay(1);
}
}
#endif