Exchanged main loop.

Added better MIDI test functions.
pull/4/head
Holger Wirtz 7 years ago
parent 1d282f5d81
commit 83611463ad
  1. 105
      MicroDexed.ino

@ -16,11 +16,11 @@
#include <looper.h> #include <looper.h>
#include "dexed.h" #include "dexed.h"
#define AUDIO_MEM 8 #define AUDIO_MEM 32
#define AUDIO_BUFFER_SIZE 128 #define AUDIO_BUFFER_SIZE 128
#define SAMPLEAUDIO_BUFFER_SIZE 44100 #define SAMPLEAUDIO_BUFFER_SIZE 44100
#define MIDI_QUEUE_LOCK_TIMEOUT_MS 5 #define MIDI_QUEUE_LOCK_TIMEOUT_MS 0
//#define INIT_AUDIO_QUEUE 1 #define INIT_AUDIO_QUEUE 1
#define TEST_MIDI 1 #define TEST_MIDI 1
#define TEST_NOTE1 60 #define TEST_NOTE1 60
@ -62,7 +62,7 @@ void setup()
AudioMemory(AUDIO_MEM); AudioMemory(AUDIO_MEM);
sgtl5000_1.enable(); sgtl5000_1.enable();
sgtl5000_1.volume(0.4); sgtl5000_1.volume(0.2);
// Initialize processor and memory measurements // Initialize processor and memory measurements
AudioProcessorUsageMaxReset(); AudioProcessorUsageMaxReset();
@ -84,17 +84,10 @@ void setup()
dexed->activate(); dexed->activate();
#ifdef TEST_MIDI #ifdef TEST_MIDI
midi_queue_t m; threads.addThread(midi_test_thread, 1);
m.cmd = 0x90;
m.data1 = TEST_NOTE1;
m.data2 = 100;
midi_queue.enqueue(m);
m.data1 = TEST_NOTE2;
midi_queue.enqueue(m);
m.cmd = 0xb0;
#endif #endif
threads.addThread(audio_thread, 1); threads.addThread(midi_thread, 1);
sched.addJob(cpu_and_mem_usage, 1000); sched.addJob(cpu_and_mem_usage, 1000);
@ -102,46 +95,15 @@ void setup()
} }
void loop() void loop()
{
#ifdef TEST_MIDI
if (millis() > 3000 && millis() < 3050)
dexed->ProcessMidiMessage(0x80, TEST_NOTE1, 0);
if (millis() > 5000 && millis() < 5050)
dexed->ProcessMidiMessage(0x80, TEST_NOTE2, 0);
#endif
// process midi->audio
while (MIDI.read())
{
midi_queue_t m;
m.cmd = MIDI.getType();
m.data1 = MIDI.getData1();
m.data2 = MIDI.getData2();
if (midi_queue_lock.lock(MIDI_QUEUE_LOCK_TIMEOUT_MS))
{
midi_queue.enqueue(m);
midi_queue_lock.unlock();
}
}
sched.scheduler();
}
void audio_thread(void)
{ {
int16_t* audio_buffer; // pointer to 128 * int16_t int16_t* audio_buffer; // pointer to 128 * int16_t
bool break_for_calculation; bool break_for_calculation;
Serial.println(F("audio thread start"));
while (42 == 42) // Don't panic!
{
audio_buffer = queue1.getBuffer(); audio_buffer = queue1.getBuffer();
if (audio_buffer == NULL) if (audio_buffer == NULL)
{ {
Serial.println(F("audio_buffer allocation problems!")); Serial.println(F("audio_buffer allocation problems!"));
continue; return;
} }
while (!midi_queue.isEmpty()) while (!midi_queue.isEmpty())
{ {
@ -159,7 +121,60 @@ void audio_thread(void)
dexed->GetSamples(AUDIO_BUFFER_SIZE, audio_buffer); dexed->GetSamples(AUDIO_BUFFER_SIZE, audio_buffer);
queue1.playBuffer(); queue1.playBuffer();
sched.scheduler();
}
void midi_test_thread(void)
{
delay(500);
queue_midi_event(0x90, TEST_NOTE1, 100);
queue_midi_event(0x90, TEST_NOTE2, 100);
delay(1000);
queue_midi_event(0x80, TEST_NOTE1, 100);
delay(1000);
queue_midi_event(0x80, TEST_NOTE2, 100);
delay(500);
for (uint8_t i = 0; i < 16; i++)
{
queue_midi_event(0x90, 55 + i, 100);
delay(100);
}
delay(1000);
for (uint8_t i = 0; i < 16; i++)
{
queue_midi_event(0x80, 55 + i, 100);
}
threads.yield();
}
void midi_thread(void)
{
Serial.println(F("midi thread start"));
while (42 == 42) // Don't panic!
{
while (MIDI.read())
{
queue_midi_event(MIDI.getType(), MIDI.getData1(), MIDI.getData2());
}
}
}
bool queue_midi_event(uint8_t type, uint8_t data1, uint8_t data2)
{
midi_queue_t m;
m.cmd = type;
m.data1 = data1;
m.data2 = data2;
if (midi_queue_lock.lock(MIDI_QUEUE_LOCK_TIMEOUT_MS))
{
midi_queue.enqueue(m);
midi_queue_lock.unlock();
return (true);
} }
return (false);
} }
void cpu_and_mem_usage(void) void cpu_and_mem_usage(void)

Loading…
Cancel
Save