-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpico_polysynth_2.c
More file actions
115 lines (86 loc) · 2.22 KB
/
Copy pathpico_polysynth_2.c
File metadata and controls
115 lines (86 loc) · 2.22 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
#include <stdio.h>
#include "pico/stdlib.h"
#include "pico/multicore.h"
#include "midi_input_driver.h"
#include "voice_allocator.h"
#include "mcp4921.h"
#include "voice.h"
#define dac_init mcp4921_init
volatile bool wait = 1;
void midi_handle_note_on(struct midi_message * message)
{
uint8_t voice = 0;
if(!voice_allocator_note_on(message->channel, message->data.note_on.note, &voice))
return;
//yea. trigger da note
voice_note_on(voice, message->channel, message->data.note_on.note, message->data.note_on.velocity);
}
void midi_handle_note_off(struct midi_message * message)
{
uint8_t voice = 0;
if (!voice_allocator_note_off(message->channel, message->data.note_off.note, &voice))
return;
//trigger the note off.
voice_note_off(voice);
}
void midi_handle_cc(struct midi_message * message)
{
voice_handle_cc(message->channel, message->data.control_change.controller, message->data.control_change.value);
}
void midi_handle_pitch_bend(struct midi_message * message)
{
voice_handle_pitch_bend(message->channel, message->data.pitch_bend.value - 8192);
}
int32_t core_0_process_audio_rate()
{
int32_t sample = 0;
for (int x = 0; x < SYNTH_NUM_VOICES; x++)
sample += voice_process_audio(x);
return sample / SYNTH_NUM_VOICES;
}
void core_0_process_audio_params()
{
for(int x = 0; x < SYNTH_NUM_VOICES; x++)
voice_process_params(x);
}
void core_0()
{
dac_init();
int32_t audio_buffer[SAMPLE_BUFFER_SIZE];
while(wait)
;
wait = 1;
while(1)
{
core_0_process_audio_params();
for (int x = 0; x < SAMPLE_BUFFER_SIZE; x++)
audio_buffer[x] = core_0_process_audio_rate();
mcp4921_send_buffer(audio_buffer);
}
}
void core_1()
{
midi_input_driver_init();
for(int voice = 0; voice < SYNTH_NUM_VOICES; voice++)
{
for (int timbre = 0; timbre < SYNTH_NUM_TIMBRES; timbre++)
{
voice_init(voice, timbre, 0);
}
}
wait = 0;
while(!wait)
;
while(1)
{
midi_input_driver_read();
}
}
int main()
{
//set_sys_clock_khz(250, 1);
/* do general setup here, leds and whatnot */
multicore_launch_core1(core_1);
core_0();
return 0;
}