-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathamy_connector.c
More file actions
554 lines (507 loc) · 19.3 KB
/
Copy pathamy_connector.c
File metadata and controls
554 lines (507 loc) · 19.3 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
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
// amy_connector.c
// all the stuff that connects Tulip to AMY
// like MIDI queue -> python
// like external CV
// like t-sequencer?
// like alles / wifi stuff?
#include "polyfills.h"
#include "py/mphal.h"
#include "py/runtime.h"
#include "py/builtin.h"
#include "amy_connector.h"
#include <stdio.h>
#include <string.h>
#ifdef ESP_PLATFORM
#include "esp_system.h"
#include "esp_attr.h"
#ifdef GAMMA9001
#include "esp_partition.h"
#endif
#endif
#ifdef AMYBOARD
// For amyboard_set_midi_out(): re-point the MIDI UART's TX line at runtime.
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/uart.h"
#include "driver/gpio.h"
#endif
uint8_t * external_map;
#ifdef AMY_IS_EXTERNAL
uint8_t * sysex_buffer;
uint16_t sysex_len = 0;
#endif
#ifdef __EMSCRIPTEN__
void midi_out(uint8_t * bytes, uint16_t len) {
EM_ASM(
if(midiOutputDevice != null) {
midiOutputDevice.send(HEAPU8.subarray($0, $0 + $1));
}, bytes, len
);
}
#endif
// A queue to store the AMY midi messages coming IN
uint8_t last_midi[MIDI_QUEUE_DEPTH][MAX_MIDI_BYTES_PER_MESSAGE];
uint8_t last_midi_len[MIDI_QUEUE_DEPTH];
extern mp_obj_t midi_callback;
extern mp_obj_t amy_overload_callback;
int16_t midi_queue_head = 0;
int16_t midi_queue_tail = 0;
// AMY calls this from its render task when the CPU overload failsafe trips
// (it has already reset the synth and played its bleep). Hand off to Python
// with the load as a percent -- a small int, so no cross-task heap allocation.
void tulip_amy_overload_hook(float load) {
if (amy_overload_callback != NULL)
mp_sched_schedule(amy_overload_callback, MP_OBJ_NEW_SMALL_INT((mp_int_t)(load * 100.0f)));
}
#ifdef ESP_PLATFORM
#include "driver/i2c.h"
// Maps synth number -> CV channel (0 = not mapped, 1 = CV1, 2 = CV2)
// Set from Python via amyboard.set_cv_out(channel, synth)
#define MAX_CV_SYNTHS 32
uint8_t cv_synth_map[MAX_CV_SYNTHS];
// Look up which synth owns this osc, return synth number or -1
static int synth_for_osc(uint16_t osc) {
extern uint8_t *osc_to_voice;
if (osc_to_voice == NULL) return -1;
uint8_t voice = osc_to_voice[osc];
if (voice == 255) return -1; // AMY_UNSET for uint8
uint16_t voices[MAX_VOICES_PER_INSTRUMENT];
for (int s = 0; s < MAX_CV_SYNTHS; s++) {
if (cv_synth_map[s] == 0) continue; // skip unmapped synths
int nv = instrument_get_num_voices(s, voices);
for (int v = 0; v < nv; v++) {
if (voices[v] == voice) return s;
}
}
return -1;
}
// AMY render hook: route osc audio to CV DAC if its synth is mapped
uint8_t external_cv_render(uint16_t osc, SAMPLE * buf, uint16_t len) {
// First check old per-osc map for backward compat
if(external_map[osc]>0) {
uint8_t cv_channel = external_map[osc] - 1;
#ifdef AMYBOARD
// AMYboard GP8413 DAC at address 88, channels 0x02/0x04
// Sample range [-1,1] -> volts [-10,+10] -> DAC [0x0000, 0x7FFF]
float volts = S2F(buf[0]) * 10.0f;
uint16_t value_int = (uint16_t)(((volts + 10.0f) / 20.0f) * 0x8000);
if (value_int > 0x7FFF) value_int = 0x7FFF;
uint8_t reg = (cv_channel == 0) ? 0x02 : 0x04;
uint8_t bytes[3] = { reg, value_int & 0xFF, (value_int >> 8) & 0xFF };
i2c_master_write_to_device(I2C_NUM_0, 88, bytes, 3, pdMS_TO_TICKS(10));
#else
// Tulip CC DAC (different address/format)
float volts = S2F(buf[0])*2.5f + 2.5f;
uint16_t value_int = (uint16_t)((volts/10.0) * 65535.0);
uint8_t bytes[3];
bytes[2] = (value_int & 0xff00) >> 8;
bytes[1] = (value_int & 0x00ff);
uint8_t ch = 0x02;
uint8_t addr = 89;
if(cv_channel == 1) ch = 0x04;
if(cv_channel == 2) addr = 88;
if(cv_channel == 3) {ch = 0x04; addr=88; }
bytes[0] = ch;
i2c_master_write_to_device(I2C_NUM_0, addr, bytes, 3, pdMS_TO_TICKS(10));
#endif
return 1;
}
// Check synth-based CV map
int s = synth_for_osc(osc);
if (s >= 0 && s < MAX_CV_SYNTHS && cv_synth_map[s] > 0) {
uint8_t cv_channel = cv_synth_map[s] - 1;
#ifdef AMYBOARD
float volts = S2F(buf[0]) * 10.0f;
uint16_t value_int = (uint16_t)(((volts + 10.0f) / 20.0f) * 0x8000);
if (value_int > 0x7FFF) value_int = 0x7FFF;
uint8_t reg = (cv_channel == 0) ? 0x02 : 0x04;
uint8_t bytes[3] = { reg, value_int & 0xFF, (value_int >> 8) & 0xFF };
i2c_master_write_to_device(I2C_NUM_0, 88, bytes, 3, pdMS_TO_TICKS(10));
#endif
return 1;
}
return 0;
}
#ifdef TULIP_USER_C_DSP
// AMY's render hook has one slot; on ESP it serves both CV output and user
// C oscillators. CV wins (returns 1 = handled, osc doesn't reach the mix);
// otherwise fall through to a bound user osc, if any.
static uint8_t tulip_render_hook_chain(uint16_t osc, SAMPLE *buf, uint16_t len) {
if (external_cv_render(osc, buf, len)) return 1;
extern uint8_t tulip_user_render_hook(uint16_t osc, SAMPLE *buf, uint16_t len);
return tulip_user_render_hook(osc, buf, len);
}
#endif
#endif
// defined in amy/src/midi_mappings.c — processes ic (MIDI CC mapping) commands
// On web, AMY runs in a separate wasm worker so midi_msg_handler is not linkable
#ifndef __EMSCRIPTEN__
extern void midi_msg_handler(uint8_t * bytes, uint16_t len, uint8_t is_sysex, uint32_t time);
#endif
// I am called when AMY receives MIDI in, whether it has been processed (played in a instrument) or not
// In tulip i just fill up the last_midi queue so that MIDI input is accessible to Python
// I also process sysex if given, and dispatch CC mappings via midi_msg_handler
void tulip_midi_input_hook(uint8_t * data, uint16_t len, uint8_t is_sysex) {
// Process ic (MIDI CC mapping) commands before queuing to Python
#ifndef __EMSCRIPTEN__
uint32_t time;
AMY_UNSET(time);
midi_msg_handler(data, len, is_sysex, time);
#endif
if(is_sysex) {
// f0 and f7 are stripped on some platforms
if(data[0]!=0xf0) {
uint16_t c = 0;
sysex_buffer[c++] = 0xf0;
for(uint16_t i = 0; i< len; i++) {
sysex_buffer[c++] = data[i];
}
sysex_buffer[c++] = 0xf7;
sysex_len = c;
} else {
for(uint16_t i = 0; i< len; i++) {
sysex_buffer[i] = data[i];
}
sysex_len = len;
}
if(midi_callback!=NULL) mp_sched_schedule(midi_callback, mp_const_true);
} else {
for(uint32_t i = 0; i < (uint32_t)len; i++) {
if(i < MAX_MIDI_BYTES_PER_MESSAGE) {
//fprintf(stderr, "%02x ", data[i]);
last_midi[midi_queue_tail][i] = data[i];
}
}
last_midi_len[midi_queue_tail] = (uint16_t)len;
midi_queue_tail = (midi_queue_tail + 1) % MIDI_QUEUE_DEPTH;
if (midi_queue_tail == midi_queue_head) {
// Queue wrap, drop oldest item.
midi_queue_head = (midi_queue_head + 1) % MIDI_QUEUE_DEPTH;
//fprintf(stderr, "dropped midi message\n");
}
// We tell Python that a MIDI message has been received
if(midi_callback!=NULL) mp_sched_schedule(midi_callback, mp_const_false);
}
}
void midi_local(uint8_t * bytes, uint16_t len) {
#ifndef AMY_IS_EXTERNAL
convert_midi_bytes_to_messages(bytes, len, 0);
#endif
#ifdef __EMSCRIPTEN__
for(uint16_t i=0;i<len;i++) {
EM_ASM(
if(typeof amy_process_single_midi_byte === 'function') {
amy_process_single_midi_byte($0, 1);
}, bytes[i]);
}
#endif
}
extern bool midi_has_out;
extern void send_usb_midi_out(uint8_t * data, uint16_t len);
void tulip_send_midi_out(uint8_t* buf, uint16_t len) {
// check if we have USB HOST midi: Tulip, or the AMYBOARD_USB_HOST variant
// — not stock AMYBOARD (USB gadget) or TDECK
#ifdef ESP_PLATFORM
#ifndef TDECK
#if !defined(AMYBOARD) || defined(AMYBOARD_USB_HOST)
if(midi_has_out) {
send_usb_midi_out(buf, len);
}
#endif
#endif
#endif
#ifndef AMY_IS_EXTERNAL
// Also send out via AMY
amy_external_midi_output(buf, len);
#endif
}
#ifndef AMY_IS_EXTERNAL
#if (defined AMYBOARD) || (defined TULIP)
#include "tulip_helpers.h"
// map the mp_obj_t to a file handle
static mp_obj_t *g_files[MAX_OPEN_FILES]; // index 1..MAX_OPEN_FILES-1 used
static uint32_t alloc_handle(mp_obj_t f) {
for (uint32_t i = 1; i < MAX_OPEN_FILES; i++) {
if (g_files[i] == NULL) {
g_files[i] = f;
return i;
}
}
return HANDLE_INVALID; // table full
}
static mp_obj_t lookup_handle(uint32_t h) {
if (h == 0 || h >= MAX_OPEN_FILES) return NULL;
return g_files[h];
}
static void free_handle(uint32_t h) {
if (h == 0 || h >= MAX_OPEN_FILES) return;
g_files[h] = NULL;
}
uint32_t mp_fopen_hook(char * filename, const char * mode) {
mp_obj_t f = tulip_fopen(filename, mode);
if (!f) {
return HANDLE_INVALID;
}
uint32_t h = alloc_handle(f);
if (h == HANDLE_INVALID) {
tulip_fclose(f);
return HANDLE_INVALID;
}
return h;
}
uint32_t mp_fwrite_hook(uint32_t fptr, uint8_t * bytes, uint32_t len) {
mp_obj_t f = lookup_handle(fptr);
if (!f) {
return 0;
}
uint32_t w = tulip_fwrite(f, bytes, len);
return w;
}
#define MAX_MP_FREAD_SIZE 64
uint32_t mp_fread_hook(uint32_t fptr, uint8_t * bytes, uint32_t len) {
mp_obj_t f = lookup_handle(fptr);
if (!f) {
return 0;
}
uint32_t total = 0;
while (total < len) {
uint32_t chunk = len - total;
if (chunk > MAX_MP_FREAD_SIZE) {
chunk = MAX_MP_FREAD_SIZE;
}
uint32_t r = tulip_fread(f, bytes + total, chunk);
total += r;
if (r < chunk) {
break;
}
}
return total;
}
void mp_fseek_hook(uint32_t fptr, uint32_t pos) {
mp_obj_t f = lookup_handle(fptr);
if (!f) {
return;
}
(void)tulip_fseek(f, pos);
}
void mp_fclose_hook(uint32_t fptr) {
mp_obj_t f = lookup_handle(fptr);
if (f) {
tulip_fclose(f);
free_handle(fptr);
}
}
STATIC mp_obj_t tulip_environment_transfer_done(size_t n_args, const mp_obj_t *args) {
mp_obj_t mod = mp_import_name(MP_QSTR_amyboard, mp_const_none, MP_OBJ_NEW_SMALL_INT(0));
mp_obj_t fn = mp_load_attr(mod, MP_QSTR_environment_transfer_done);
return mp_call_function_0(fn);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(tulip_environment_transfer_done_obj, 0, 1, tulip_environment_transfer_done);
void mp_exec_hook(const char *code) {
#if defined(AMYBOARD)
nlr_buf_t nlr;
if (nlr_push(&nlr) == 0) {
mp_obj_t code_str = mp_obj_new_str(code, strlen(code));
mp_call_function_1(MP_OBJ_FROM_PTR(&mp_builtin_exec_obj), code_str);
nlr_pop();
} else {
fprintf(stderr, "mp_exec_hook: exec raised, ignoring\n");
mp_obj_print_exception(&mp_plat_print, MP_OBJ_FROM_PTR(nlr.ret_val));
}
#else
(void)code;
#endif
}
void mp_update_file_hook(const char *filename) {
#if defined(AMYBOARD)
// Call amyboard.update_sketch_knobs(filename) synchronously. This runs
// from the C-side zA handler, so any unhandled Python exception would
// NLR-longjmp out of the sysex parser mid-message and the subsequent zD
// would never be processed (Pull would hang). Wrap the call in an NLR
// buffer so exceptions get swallowed and the parser can continue.
nlr_buf_t nlr;
if (nlr_push(&nlr) == 0) {
mp_obj_t mod = mp_import_name(MP_QSTR_amyboard, mp_const_none, MP_OBJ_NEW_SMALL_INT(0));
mp_obj_t fn = mp_load_attr(mod, MP_QSTR_update_sketch_knobs);
mp_obj_t path = mp_obj_new_str(filename, strlen(filename));
mp_call_function_1(fn, path);
nlr_pop();
} else {
// Python raised — swallow so the sysex parser can continue to zD.
fprintf(stderr, "mp_update_file_hook: update_sketch_knobs raised, ignoring\n");
mp_obj_print_exception(&mp_plat_print, MP_OBJ_FROM_PTR(nlr.ret_val));
}
#else
(void)filename;
#endif
}
void mp_file_transfer_done_hook(const char *filename) {
#if defined(AMYBOARD)
if (filename == NULL || filename[0] == '\0') {
return;
}
const char *leaf = filename;
const char *slash = strrchr(filename, '/');
if (slash != NULL && slash[1] != '\0') {
leaf = slash + 1;
}
if (strcmp(leaf, "sketch.py") == 0) {
mp_sched_schedule(MP_OBJ_FROM_PTR(&tulip_environment_transfer_done_obj), mp_const_none);
}
#else
(void)filename;
#endif
}
#ifdef ESP_PLATFORM
RTC_NOINIT_ATTR uint32_t amyboard_bootloader_flag;
#define AMYBOARD_BOOTLOADER_MAGIC 0xABCD0001
#endif
void mp_reboot_hook(uint8_t mode) {
#if defined(AMYBOARD) && defined(ESP_PLATFORM)
if (mode == 0) {
// Bootloader mode: skip sketch on next boot.
amyboard_bootloader_flag = AMYBOARD_BOOTLOADER_MAGIC;
esp_restart();
} else if (mode == 1) {
// Normal reboot: run sketch as usual.
esp_restart();
}
#endif
}
#if defined(GAMMA9001) && defined(ESP_PLATFORM)
// Map the `drums` flash partition (raw drums.bin from the amy repo, flashed by
// fs_create.py) into the data address space and hand it to AMY, which serves
// the Gamma9001 bank presets (256+) straight out of it. If the partition is
// missing or unreadable, those presets stay silent -- the baked TR-808 kit
// (patch 384) still works.
static void mount_gamma9001_drums(void) {
const esp_partition_t *part = esp_partition_find_first(
ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_ANY, "drums");
if (part == NULL) {
fprintf(stderr, "gamma9001: no drums partition, bank presets unavailable\n");
return;
}
const void *map = NULL;
esp_partition_mmap_handle_t handle; // never unmapped; the samples live as long as AMY
esp_err_t err = esp_partition_mmap(part, 0, part->size, ESP_PARTITION_MMAP_DATA, &map, &handle);
if (err != ESP_OK || map == NULL) {
fprintf(stderr, "gamma9001: drums partition mmap failed (%d)\n", (int)err);
return;
}
amy_set_gamma9001_pcm((const int16_t *)map);
}
#endif
void run_amy(uint8_t midi_out_pin) {
amy_config_t amy_config = amy_default_config();
amy_config.amy_external_midi_input_hook = tulip_midi_input_hook;
#ifdef TULIP_USER_C_DSP
amy_config.amy_external_render_hook = tulip_render_hook_chain;
#else
amy_config.amy_external_render_hook = external_cv_render;
#endif
amy_config.amy_external_fopen_hook = mp_fopen_hook;
amy_config.amy_external_fseek_hook = mp_fseek_hook;
amy_config.amy_external_fclose_hook = mp_fclose_hook;
amy_config.amy_external_fread_hook = mp_fread_hook;
amy_config.amy_external_fwrite_hook = mp_fwrite_hook;
amy_config.amy_external_file_transfer_done_hook = mp_file_transfer_done_hook;
amy_config.amy_external_update_file_hook = mp_update_file_hook;
amy_config.amy_external_exec_hook = mp_exec_hook;
amy_config.amy_external_reboot_hook = mp_reboot_hook;
amy_config.amy_external_overload_hook = tulip_amy_overload_hook;
extern void tulip_amy_sequencer_hook(uint32_t tick_count);
amy_config.amy_external_sequencer_hook = tulip_amy_sequencer_hook;
#ifdef TULIP_USER_C_DSP
extern void tulip_bus_postprocess_hook(uint8_t bus, SAMPLE *buf, uint16_t len);
amy_config.amy_external_bus_postprocess_hook = tulip_bus_postprocess_hook;
#endif
amy_config.audio = AMY_AUDIO_IS_I2S;
#if defined(AMYBOARD) || defined(AMYBOARD_WEB)
extern float cv_input_hook(uint16_t channel);
amy_config.amy_external_coef_hook = cv_input_hook;
#endif
#ifdef AMYBOARD
amy_config.features.audio_in = 1;
#ifdef AMYBOARD_USB_HOST
// USB is a MIDI host here (usb_host.c feeds AMY directly); the TinyUSB
// gadget stack is compiled but never initialized, so don't route to it.
amy_config.midi = AMY_MIDI_IS_UART;
#else
amy_config.midi = AMY_MIDI_IS_UART | AMY_MIDI_IS_USB_GADGET;
#endif
#else
amy_config.features.audio_in = 0;
amy_config.midi = AMY_MIDI_IS_UART;
#endif
amy_config.features.default_synths = 0; // midi.py does this for us
amy_config.i2s_lrc = CONFIG_I2S_LRCLK;
amy_config.i2s_bclk = CONFIG_I2S_BCLK;
amy_config.i2s_dout = CONFIG_I2S_DOUT;
amy_config.i2s_din = CONFIG_I2S_DIN;
amy_config.i2s_mclk = CONFIG_I2S_MCLK;
amy_config.midi_out = midi_out_pin;
amy_config.midi_in = MIDI_IN_PIN;
#ifndef AMYBOARD
amy_config.features.startup_bleep = 1;
#endif
#if defined(GAMMA9001) && defined(ESP_PLATFORM)
mount_gamma9001_drums();
#endif
amy_start(amy_config);
external_map = malloc_caps(amy_config.max_oscs, MALLOC_CAP_INTERNAL);
for(uint16_t i=0;i<amy_config.max_oscs;i++) external_map[i] = 0;
for(uint8_t i=0;i<MAX_CV_SYNTHS;i++) cv_synth_map[i] = 0;
}
#ifdef AMYBOARD
// Set the MIDI OUT TRS standard (Type A = pin 14, Type B = pin 15). This is the single
// MIDI OUT pin-init sequence: amyboard.set_midi_type() calls it both at boot (from
// start_amy(), right after amy_start()) and at runtime, without restarting AMY. AMY
// transmits MIDI via uart_write_bytes(UART_NUM_1, ...) — keyed on the UART number, not
// the GPIO — so moving the UART's TX line to the other TRS leg is all that's needed.
// midi_uart is 1 on AMYboard (amy's esp_get_uart(1) == UART_NUM_1). Only MIDI OUT
// differs by type; MIDI IN works for both, so RX (MIDI_IN_PIN) is left unchanged.
// Requires AMY's UART driver to be installed (amy_start() does this synchronously).
void amyboard_set_midi_out(uint8_t midi_out_pin) {
const uint8_t other_pin = (midi_out_pin == MIDI_OUT_PIN_A) ? MIDI_OUT_PIN_B : MIDI_OUT_PIN_A;
// Let any in-flight MIDI byte finish before moving the TX line.
uart_wait_tx_done(UART_NUM_1, pdMS_TO_TICKS(20));
// Re-route the UART's TX to the requested TRS data leg.
uart_set_pin(UART_NUM_1, midi_out_pin, MIDI_IN_PIN, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
// Disconnect the now-unused leg from the UART and hold it high (MIDI idle/source).
// Driving it as a plain GPIO output stops it from mirroring the TX signal.
gpio_reset_pin(other_pin);
gpio_set_direction(other_pin, GPIO_MODE_OUTPUT);
gpio_set_level(other_pin, 1);
}
#endif
#elif defined TULIP_DESKTOP
void run_amy(uint8_t capture_device_id, uint8_t playback_device_id) {
amy_config_t amy_config = amy_default_config();
amy_config.amy_external_midi_input_hook = tulip_midi_input_hook;
amy_config.amy_external_overload_hook = tulip_amy_overload_hook;
extern void tulip_amy_sequencer_hook(uint32_t tick_count);
amy_config.amy_external_sequencer_hook = tulip_amy_sequencer_hook;
#ifdef TULIP_USER_C_DSP
extern void tulip_bus_postprocess_hook(uint8_t bus, SAMPLE *buf, uint16_t len);
amy_config.amy_external_bus_postprocess_hook = tulip_bus_postprocess_hook;
extern uint8_t tulip_user_render_hook(uint16_t osc, SAMPLE *buf, uint16_t len);
amy_config.amy_external_render_hook = tulip_user_render_hook;
#endif
amy_config.features.default_synths = 0; // midi.py does this for us
amy_config.capture_device_id = capture_device_id;
amy_config.playback_device_id = playback_device_id;
amy_config.features.audio_in = 1;
amy_config.audio = AMY_AUDIO_IS_MINIAUDIO;
//amy_config.i2s_din = 0; // Dummy to indicate has audio in.
amy_config.features.startup_bleep = 1;
#ifdef GAMMA9001
// Tulip Desktop links drums.bin straight into the binary (see tulip.mk).
{
extern const int16_t gamma9001_pcm_data[];
amy_set_gamma9001_pcm(gamma9001_pcm_data);
}
#endif
amy_start(amy_config);
}
#endif
#endif