-
Notifications
You must be signed in to change notification settings - Fork 0
/
Looper.cpp
214 lines (171 loc) · 5.91 KB
/
Looper.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
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#include "daisy.h"
#include "daisysp.h"
#include "../../lib/daisy_dpt.h"
#include "looper.h"
#include "my_looper.h"
/*
Hello, friend. Here is a minimal, normal DPT template w/ a few notes / examples.
We hope you enjoy your time with DPT and Daisy Patch SM!
~ j.m.
*/
#define kBuffSize 48000 * 60 // 60 seconds at 48kHz
using namespace daisy;
using namespace daisysp_custom;
using namespace daisysp;
using namespace dpt;
DPT patch;
MyLooper looper_l;
MyLooper looper_r;
float DSY_SDRAM_BSS buffer_l[kBuffSize];
float DSY_SDRAM_BSS buffer_r[kBuffSize];
float cv6_state = 0.0f;
void dac7554callback(void *data) {
/*
Update CV 3-6 here, like this (voltages -7.0 to 7.0)
patch.WriteCvOutExp(
1.0,
2.0,
3.0,
4.0,
false);
);
or for raw values,
patch.WriteCvOutExp(
0,
1023,
2047
4095,
true);
);
*/
}
void AudioCallback(AudioHandle::InputBuffer in,
AudioHandle::OutputBuffer out,
size_t size)
{
patch.ProcessAllControls();
float in_level = patch.controls[CV_1].Value();
float loop_level = patch.controls[CV_2].Value();
static bool last_state = false;
if(!last_state && patch.controls[CV_3].Value() >= 0.5) {
looper_l.TrigRecord();
looper_r.TrigRecord();
} else if (last_state && patch.controls[CV_3].Value() < 0.5) {
looper_l.TrigRecord();
looper_r.TrigRecord();
}
last_state = patch.controls[CV_3].Value() >= 0.5;
if (patch.controls[CV_4].Value() > 0.5) {
looper_l.Clear();
looper_r.Clear();
}
if (looper_l.length_setting) {
patch.WriteCvOut(3, -5.0, false);
} else if (looper_l.length_set) {
patch.WriteCvOut(3, 5.0, false);
} else {
patch.WriteCvOut(3, 0.0, false);
}
patch.WriteCvOut(CV_OUT_1, last_state ? -5.0 : 10.0, false);
//patch.WriteCvOut(2, last_state ? -5.0 : 10.0, false);
patch.WriteCvOut(CV_OUT_2, cv6_state, false);
//float speed_knob = patch.controls[CV_8].Value();
//looper_l.SetSpeed(speed_knob);
//looper_r.SetSpeed(speed_knob);
// Process audio
for(size_t i = 0; i < size; i++)
{
// store the inputs * the input gain factor
float in_l = IN_L[i] * in_level;
float in_r = IN_R[i] * in_level;
// store signal = loop signal * loop gain + in * in_gain
float sig_l = looper_l.Process(in_l) * loop_level + in_l;
float sig_r = looper_r.Process(in_r) * loop_level + in_r;
// send that signal to the outputs
OUT_L[i] = sig_l;
OUT_R[i] = sig_r;
}
/*
CV 1 - 8 accessed
patch.controls[CV_1].Value()
Gate ins acccessed
patch.gate_in_1.State();
patch.gate_in_2.State();
Send data to gate outs
dsy_gpio_write(&patch.gate_out_1, 1);
dsy_gpio_write(&patch.gate_out_2, 2);
Send data to CV 1 and 2 (0 is both, currently it seems 1 is CV2, 2 is CV1)
patch.WriteCvOut(0, 5.0, false);
patch.WriteCvOut(0, [0 - 4095], true); // last argument is 'raw', send raw 12-bit data
*/
/*for (size_t i = 0; i < size; i++)
{
out[0][i] = in[0][i];
out[1][i] = in[1][i];
}*/
}
int main(void)
{
patch.Init();
// Set up callback for TIM5
patch.StartAudio(AudioCallback);
patch.InitTimer(dac7554callback, nullptr);
// Init the loopers
looper_l.Init(buffer_l, kBuffSize);
looper_r.Init(buffer_r, kBuffSize);
looper_l.SetMode(daisysp_custom::Looper::Mode::FRIPPERTRONICS);
looper_r.SetMode(daisysp_custom::Looper::Mode::FRIPPERTRONICS);
patch.midi.StartReceive();
// Start the audio callback
patch.StartAudio(AudioCallback);
//static unsigned long last_clock = daisy::System::GetUs();
//static unsigned long us_between_ticks = 2033;
while(1)
{
/*
MIDI processing here
patch.midi.Listen()
first then you can call
patch.midi.HasEvents()
and
auto event = patch.midi.PopEvent();
and sort that out from there
if(event.type == MidiMessageType::NoteOn) {
...
};
*/
patch.midi.Listen();
static bool indicator = false;
while(patch.midi.HasEvents()) {
cv6_state = 5.0f;
//patch.WriteCvOut(CV_6, 1.0, false);
auto event = patch.midi.PopEvent();
if (event.type==MidiMessageType::SystemRealTime) {
indicator = !indicator;
dsy_gpio_write(&patch.gate_out_2, indicator);
if (event.srt_type==SystemRealTimeType::TimingClock) {
if (patch.controls[CV_7].Value()>=0.5) {
looper_l.ReceiveTick();
looper_r.ReceiveTick();
}
} else if(event.srt_type==SystemRealTimeType::Start) {
//patch.WriteCvOut(CV_6, 5.0, false);
looper_l.LoopStart();
looper_r.LoopStart();
} else if (event.srt_type==SystemRealTimeType::Stop) {
looper_l.SetPlaying();
looper_r.SetPlaying();
} else if (event.srt_type==SystemRealTimeType::Continue) {
looper_l.SetDubbing();
looper_r.SetDubbing();
}
} else if(event.type == MidiMessageType::NoteOn) {
dsy_gpio_write(&patch.gate_out_1, 1);
} else if(event.type == MidiMessageType::NoteOff) {
dsy_gpio_write(&patch.gate_out_1, 0);
}
}
//dsy_gpio_write(&patch.gate_out_2, 0);
cv6_state = -5.0f;
}
}