forked from marcel-licence/esp32_basic_synth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathesp32_basic_synth.ino
198 lines (146 loc) · 3.33 KB
/
esp32_basic_synth.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
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
/*
* pinout of ESP32 DevKit found here:
* https://circuits4you.com/2018/12/31/esp32-devkit-esp32-wroom-gpio-pinout/
*
* Author: Marcel Licence
*/
#include "config.h"
/*
* required include files
*/
#include <arduino.h>
#include <WiFi.h>
/* this is used to add a task to core 0 */
TaskHandle_t Core0TaskHnd ;
void setup()
{
/*
* this code runs once
*/
delay(500);
Serial.begin(115200);
Serial.println();
Serial.printf("Initialize Reverb Module\n");
Reverb_Setup();
Serial.printf("Initialize Delay Module\n");
Delay_Init();
Serial.printf("Initialize Synth Module\n");
Synth_Init();
Serial.printf("Initialize I2S Module\n");
// Reverb_Setup();
Blink_Setup();
#ifdef ESP32_AUDIO_KIT
ac101_setup();
#endif
setup_i2s();
Serial.printf("Initialize Midi Module\n");
Midi_Setup();
Serial.printf("Turn off Wifi/Bluetooth\n");
#if 0
setup_wifi();
#else
WiFi.mode(WIFI_OFF);
#endif
#ifndef ESP8266
btStop();
// esp_wifi_deinit();
#endif
Serial.printf("ESP.getFreeHeap() %d\n", ESP.getFreeHeap());
Serial.printf("ESP.getMinFreeHeap() %d\n", ESP.getMinFreeHeap());
Serial.printf("ESP.getHeapSize() %d\n", ESP.getHeapSize());
Serial.printf("ESP.getMaxAllocHeap() %d\n", ESP.getMaxAllocHeap());
Serial.printf("Firmware started successfully\n");
#if 0 /* activate this line to get a tone on startup to test the DAC */
Synth_NoteOn(0, 64, 1.0f);
#endif
#ifdef ADC_TO_MIDI_ENABLED
xTaskCreatePinnedToCore(Core0Task, "Core0Task", 8000, NULL, 999, &Core0TaskHnd, 0);
#endif
}
void Core0TaskSetup()
{
/*
* init your stuff for core0 here
*/
#ifdef ADC_TO_MIDI_ENABLED
AdcMul_Init();
#endif
// Init I2C
}
void Core0TaskLoop()
{
/*
* put your loop stuff for core0 here
*/
// Request Data from I2C
// Update LEDs via I2C
#ifdef ADC_TO_MIDI_ENABLED
AdcMul_Process();
#endif
}
void Core0Task(void *parameter)
{
Core0TaskSetup();
while (true)
{
Core0TaskLoop();
/* this seems necessary to trigger the watchdog */
delay(1);
yield();
}
}
/*
* use this if something should happen every second
* - you can drive a blinking LED for example
*/
inline void Loop_1Hz(void)
{
Blink_Process();
}
/*
* our main loop
* - all is done in a blocking context
* - do not block the loop otherwise you will get problems with your audio
*/
float fl_sample, fr_sample;
void loop()
{
static uint32_t loop_cnt_1hz;
static uint8_t loop_count_u8 = 0;
loop_count_u8++;
loop_cnt_1hz ++;
if (loop_cnt_1hz >= SAMPLE_RATE)
{
Loop_1Hz();
loop_cnt_1hz = 0;
}
#ifdef I2S_NODAC
if (writeDAC(l_sample))
{
l_sample = Synth_Process();
}
#else
if (i2s_write_stereo_samples(&fl_sample, &fr_sample)){
/* nothing for here */
}
Synth_Process(&fl_sample, &fr_sample);
/*
* add also some reverb
*
*
*/
// rocess Reverb
Reverb_Process( &fl_sample, &fr_sample, SAMPLE_BUFFER_SIZE );
/*
* process delay line
*/
Delay_Process(&fl_sample, &fr_sample);
#endif
/*
* Midi does not required to be checked after every processed sample
* - we divide our operation by 8
*/
if (loop_count_u8 % 8 == 0){
Midi_Process();
}
}