-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreverse.cpp
More file actions
62 lines (51 loc) · 1.4 KB
/
reverse.cpp
File metadata and controls
62 lines (51 loc) · 1.4 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
53
54
55
56
57
58
59
60
61
62
#include <cstddef>
#include "libjazz/value.hpp"
#ifndef UNIT_TEST
#include "daisy_seed.h"
#include "daisysp.h"
#include "hid/logger.h"
using namespace daisy;
using namespace daisysp;
DaisySeed hw;
#endif
#define BUFFER_LEN 44100 * 2 /* 2 seconds */
static int delay_samples = 22000;
static float feedback = 0.3;
static float buffer[BUFFER_LEN] = {};
static int read_pos = BUFFER_LEN;
static int write_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] * 0.9;
read_pos = read_pos - 1;
if (read_pos == -1) {
read_pos = delay_samples - 1;
}
auto delayed_signal = buffer[read_pos];
buffer[write_pos] = sample + (delayed_signal * feedback);
write_pos = (write_pos + 1) % (delay_samples);
out[0][i] = sample + delayed_signal;
}
}
#endif
#ifndef UNIT_TEST
int main() {
hw.Configure();
hw.Init();
hw.SetAudioBlockSize(4);
AdcChannelConfig adcConfig[2];
adcConfig[0].InitSingle(hw.GetPin(21)); /* delay amount */
adcConfig[1].InitSingle(hw.GetPin(20)); /* feedback */
hw.adc.Init(adcConfig, 2);
hw.adc.Start();
hw.StartAudio(AudioCallback);
hw.PrintLine("again");
for (;;) {
delay_samples = (int)(hw.adc.GetFloat(0) * BUFFER_LEN);
auto new_feedback = hw.adc.GetFloat(1);
feedback = new_feedback;
}
}
#endif