Added global midi_bpm and synced delay (to midi_bpm).

pull/44/head
Holger Wirtz 3 years ago
parent 7d1ce9bce6
commit fcf70e3392
  1. 91
      MicroDexed.ino
  2. 16
      config.h
  3. 1
      synth_dexed.h

@ -220,13 +220,12 @@ void create_audio_engine_chain(uint8_t instance_id)
uint8_t sd_card = 0; uint8_t sd_card = 0;
Sd2Card card; Sd2Card card;
SdVolume volume; SdVolume volume;
uint8_t midi_ticks[10] = {0, 6, 9, 12, 18, 24, 36, 48, 72, 96}; float midi_ticks_factor[10] = {0.0, 0.0625, 0.09375, 0.125, 0.1875, 0.25, 0.375, 0.5, 0.75 , 1.0};
uint8_t midi_bpm_counter = 0; uint8_t midi_bpm_counter = 0;
elapsedMillis midi_bpm; uint8_t midi_bpm = 0;
#ifdef USE_FX int16_t _midi_bpm = -1;
uint8_t midi_timing_counter[NUM_DEXED] = {0, 0}; bool midi_clock_running = false;
elapsedMillis midi_timing_timer[NUM_DEXED]; elapsedMillis midi_bpm_timer;
#endif
elapsedMillis long_button_pressed; elapsedMillis long_button_pressed;
elapsedMillis control_rate; elapsedMillis control_rate;
uint8_t active_voices[NUM_DEXED]; uint8_t active_voices[NUM_DEXED];
@ -1374,71 +1373,75 @@ void handleTuneRequest(void)
void handleClock(void) void handleClock(void)
{ {
#ifdef DEBUG if (midi_clock_running != true)
return;
if (midi_bpm_counter % 24 == 0) if (midi_bpm_counter % 24 == 0)
{ {
midi_bpm = (60000.0f / float(midi_bpm_timer) + 0.5);
if (_midi_bpm > -1 && _midi_bpm != midi_bpm)
{
#ifdef DEBUG
Serial.print(F("MIDI Clock: ")); Serial.print(F("MIDI Clock: "));
Serial.print(60000.0f / midi_bpm, 2); Serial.print(midi_bpm);
Serial.print(F("bpm (")); Serial.print(F(" bpm ("));
Serial.print(midi_bpm, DEC); Serial.print(midi_bpm_timer, DEC);
Serial.println(F("ms per quarter)")); Serial.println(F("ms per quarter)"));
midi_bpm = 0;
midi_bpm_counter = 0;
}
midi_bpm_counter++;
#endif #endif
#ifdef USE_FX #ifdef USE_FX
for (uint8_t instance_id = 0; instance_id < NUM_DEXED; instance_id++)
{
if (midi_ticks[configuration.fx.delay_sync[instance_id]] > 0)
{
/* /*
1 1/16 = 6 ticks 1 1/16 = 6 ticks / 0.0625
2 1/16T = 9 ticks 2 1/16T = 9 ticks / 0.09375
3 1/8 = 12 ticks 3 1/8 = 12 ticks / 0.125
4 1/8T = 18 ticks 4 1/8T = 18 ticks / 0.1875
5 1/4 = 24 ticks 5 1/4 = 24 ticks / 0.25
6 1/4T = 36 ticks 6 1/4T = 36 ticks / 0.375
7 1/2 = 48 ticks 7 1/2 = 48 ticks / 0.5
8 1/2T = 72 ticks 8 1/2T = 72 ticks / 0.75
9 1/1 = 96 ticks 9 1/1 = 96 ticks / 1.0
*/ */
if (midi_timing_counter[instance_id] % midi_ticks[configuration.fx.delay_sync[instance_id]] == 0) for (uint8_t instance_id = 0; instance_id < NUM_DEXED; instance_id++)
{ {
int32_t t = midi_timing_timer[instance_id]; if (configuration.fx.delay_sync[instance_id] > 0)
delay_fx[instance_id]->delay(0, constrain(t*10, DELAY_TIME_MIN*10, DELAY_TIME_MAX*10)); {
uint16_t t = uint16_t(60.0 / float(midi_bpm) * 1000.0 * midi_ticks_factor[configuration.fx.delay_sync[instance_id]] + 0.5);
delay_fx[instance_id]->delay(0, constrain(t, DELAY_TIME_MIN * 10, DELAY_TIME_MAX * 10));
#ifdef DEBUG #ifdef DEBUG
Serial.print(F("Delay-Sync to ")); Serial.print(F("Setting Delay-Sync to "));
Serial.print(constrain(t, DELAY_TIME_MIN, DELAY_TIME_MAX), DEC); Serial.print(constrain(t, DELAY_TIME_MIN * 10, DELAY_TIME_MAX * 10), DEC);
Serial.print(F(" ms / ")); Serial.println(F(" ms"));
Serial.print(midi_timing_counter[instance_id], DEC);
Serial.println(F(" ticks"));
#endif #endif
midi_timing_counter[instance_id] = 0;
midi_timing_timer[instance_id] = 0;
}
midi_timing_counter[instance_id]++;
} }
} }
#else
;
#endif #endif
}
_midi_bpm = midi_bpm;
midi_bpm_counter = 0;
midi_bpm_timer = 0;
}
midi_bpm_counter++;
} }
void handleStart(void) void handleStart(void)
{ {
; midi_clock_running = true;
midi_bpm_timer = 0;
midi_bpm_counter = 0;
_midi_bpm = -1;
} }
void handleContinue(void) void handleContinue(void)
{ {
; midi_clock_running = true;
} }
void handleStop(void) void handleStop(void)
{ {
; midi_clock_running = false;
} }
void handleActiveSensing(void) void handleActiveSensing(void)

@ -32,7 +32,7 @@
// ATTENTION! For better latency you have to redefine AUDIO_BLOCK_SAMPLES from // ATTENTION! For better latency you have to redefine AUDIO_BLOCK_SAMPLES from
// 128 to 64 in <ARDUINO-IDE-DIR>/cores/teensy3/AudioStream.h // 128 to 64 in <ARDUINO-IDE-DIR>/cores/teensy3/AudioStream.h
// For this audio buffers (AUDIO_MEM) are doubled! // For this you have manually change audio buffers (AUDIO_MEM) to the doubled value!
// If you want to test the system with Linux and without any keyboard and/or audio equipment, you can do the following: // If you want to test the system with Linux and without any keyboard and/or audio equipment, you can do the following:
// 1. In Arduino-IDE enable "Tools->USB-Type->Serial + MIDI + Audio" // 1. In Arduino-IDE enable "Tools->USB-Type->Serial + MIDI + Audio"
@ -59,7 +59,7 @@
// sed -i.orig 's/^#define USB_MIDI_SYSEX_MAX 290/#define USB_MIDI_SYSEX_MAX 4104/' /usr/local/arduino-teensy/hardware/teensy/avr/cores/teensy4/usb_midi.h // sed -i.orig 's/^#define USB_MIDI_SYSEX_MAX 290/#define USB_MIDI_SYSEX_MAX 4104/' /usr/local/arduino-teensy/hardware/teensy/avr/cores/teensy4/usb_midi.h
//#define USB_MIDI_SYSEX_MAX 4104 //#define USB_MIDI_SYSEX_MAX 4104
#define VERSION "1.0.18" #define VERSION "1.0.19"
//************************************************************************************************* //*************************************************************************************************
//* DEVICE SETTINGS //* DEVICE SETTINGS
@ -131,8 +131,7 @@
//#if AUDIO_BLOCK_SAMPLES == 64 //#if AUDIO_BLOCK_SAMPLES == 64
//#define AUDIO_MEM 256 //#define AUDIO_MEM 256
//#else //#else
#define AUDIO_MEM 128 #define AUDIO_MEM 750
#define AUDIO_MEM_F32 10
//#endif //#endif
#ifdef TEENSY_AUDIO_BOARD #ifdef TEENSY_AUDIO_BOARD
@ -164,17 +163,20 @@
#if defined(TEENSY3_6) #if defined(TEENSY3_6)
#define DELAY_MAX_TIME 250 #define DELAY_MAX_TIME 250
#elif defined(TEENSY4) #elif defined(TEENSY4)
#define DELAY_MAX_TIME 750 #define DELAY_MAX_TIME 500
#else #else
#define DELAY_MAX_TIME 125 #define DELAY_MAX_TIME 125
#endif #endif
#else #else
#if defined(TEENSY3_6) #if defined(TEENSY3_6)
#define DELAY_MAX_TIME 500 #define DELAY_MAX_TIME 500
#define AUDIO_MEM 360
#elif defined(TEENSY4) #elif defined(TEENSY4)
#define DELAY_MAX_TIME 1500 #define DELAY_MAX_TIME 1000
#define AUDIO_MEM 750
#else #else
#define DELAY_MAX_TIME 250 #define DELAY_MAX_TIME 250
#define AUDIO_MEM 200
#endif #endif
#endif #endif
@ -420,7 +422,7 @@
#define DELAY_SYNC_MIN 0 #define DELAY_SYNC_MIN 0
#define DELAY_SYNC_MAX 9 #define DELAY_SYNC_MAX 9
#define DELAY_SYNC_DEFAULT 7 #define DELAY_SYNC_DEFAULT 0
#define REVERB_ROOMSIZE_MIN 0 #define REVERB_ROOMSIZE_MIN 0
#define REVERB_ROOMSIZE_MAX 100 #define REVERB_ROOMSIZE_MAX 100

@ -1,6 +1,5 @@
#include <Arduino.h> #include <Arduino.h>
#include <Audio.h> #include <Audio.h>
#include <OpenAudio_ArduinoLibrary.h>
#include "config.h" #include "config.h"
/***************************************************** /*****************************************************

Loading…
Cancel
Save