diff --git a/MicroDexed.ino b/MicroDexed.ino index 7ac0846..84a6e82 100644 --- a/MicroDexed.ino +++ b/MicroDexed.ino @@ -90,8 +90,8 @@ AudioMixer4 audio_thru_mixer_l; #ifdef NUM_DRUMS AudioPlaySdRaw* Drum[NUM_DRUMS]; AudioEffectMonoStereo* drum_mono2stereo[NUM_DRUMS]; -AudioMixer8 drum_mixer_r; -AudioMixer8 drum_mixer_l; +AudioMixer4 drum_mixer_r; +AudioMixer4 drum_mixer_l; #endif // Audio chain tail @@ -174,6 +174,8 @@ AudioConnection patchCord24(audio_thru_mixer_l, 0, i2s1, 1); #ifdef USE_FX AudioConnection patchCord25(drum_mixer_r, 0, reverb_mixer_r, 4); AudioConnection patchCord26(drum_mixer_l, 0, reverb_mixer_l, 4); +AudioConnection patchCord27(drum_mixer_r, 0, master_mixer_r, 2); +AudioConnection patchCord28(drum_mixer_l, 0, master_mixer_l, 2); #else AudioConnection patchCord25(drum_mixer_r, 0, master_mixer_r, 2); AudioConnection patchCord26(drum_mixer_l, 0, master_mixer_l, 2); @@ -248,10 +250,6 @@ void create_audio_drum_chain(uint8_t instance_id) dynamicDrumConnections[nDrumDynamic++] = new AudioConnection(*Drum[instance_id], 0, *drum_mono2stereo[instance_id], 0); dynamicDrumConnections[nDrumDynamic++] = new AudioConnection(*drum_mono2stereo[instance_id], 0, drum_mixer_r, instance_id); dynamicDrumConnections[nDrumDynamic++] = new AudioConnection(*drum_mono2stereo[instance_id], 1, drum_mixer_l, instance_id); - - drum_mono2stereo[instance_id]->panorama(0.0); - drum_mixer_r.gain(instance_id, 1.0); - drum_mixer_l.gain(instance_id, 1.0); } #endif @@ -446,6 +444,9 @@ void setup() Serial.println(instance_id, DEC); #endif create_audio_drum_chain(instance_id); + + drum_mixer_r.gain(instance_id, 1.0); + drum_mixer_l.gain(instance_id, 1.0); } #endif @@ -709,44 +710,64 @@ void handleNoteOn(byte inChannel, byte inNumber, byte inVelocity) } #ifdef NUM_DRUMS + static uint8_t drum_counter; + // Check for Drum if (inChannel == DRUM_MIDI_CHANNEL) { + if (drum_counter >= NUM_DRUMS) + drum_counter = 0; + #ifdef DEBUG - Serial.print(F("Drum ")); - Serial.println(inNumber - 48, DEC); + char note_name[4]; + getNoteName(note_name, inNumber); + Serial.print(F("=> Drum[")); + Serial.print(drum_counter, DEC); + Serial.print(F("]: ")); + Serial.println(note_name); #endif + switch (inNumber - 48) { case 0: - Drum[0]->play("drm/bd01.raw"); + Drum[drum_counter % 4]->play("/DRM/BD01.RAW"); + drum_counter++; break; case 1: - Drum[1]->play("drm/cp02.raw"); + Drum[drum_counter % 4]->play("/drm/cp02.raw"); + drum_counter++; break; case 2: - Drum[2]->play("drm/sd15.raw"); + Drum[drum_counter % 4]->play("/drm/sd15.raw"); + drum_counter++; break; case 6: - Drum[3]->play("drm/hh01.wav"); + Drum[drum_counter % 4]->play("/drm/hh01.wav"); + drum_counter++; break; case 8: - Drum[3]->play("drm/hh02.wav"); + Drum[drum_counter % 4]->play("/drm/hh02.wav"); + drum_counter++; break; case 10: - Drum[3]->play("drm/oh02.wav"); + Drum[drum_counter % 4]->play("/drm/oh02.wav"); + drum_counter++; break; case 5: - Drum[4]->play("drm/lt01.raw"); + Drum[drum_counter % 4]->play("/drm/lt01.raw"); + drum_counter++; break; case 7: - Drum[5]->play("drm/ht01.raw"); + Drum[drum_counter % 4]->play("/drm/ht01.raw"); + drum_counter++; break; case 13: - Drum[6]->play("drm/rd01.raw"); + Drum[drum_counter % 4]->play("/drm/rd01.raw"); + drum_counter++; break; case 15: - Drum[7]->play("drm/rd02.raw"); + Drum[drum_counter % 4]->play("/drm/rd02.raw"); + drum_counter++; break; } } diff --git a/config.h b/config.h index bdeaf6f..60f1224 100644 --- a/config.h +++ b/config.h @@ -109,7 +109,7 @@ #define USE_FX 1 // NUMBER OF SAMPLEDRUMS -#define NUM_DRUMS 8 // Max is currently 8! +#define NUM_DRUMS 4 #define DRUM_MIDI_CHANNEL 1 // CHORUS parameters @@ -120,7 +120,7 @@ // SGTL5000 #ifdef TEENSY_AUDIO_BOARD #define SGTL5000_AUDIO_ENHANCE 1 -//#define SGTL5000_AUDIO_THRU 1 +#define SGTL5000_AUDIO_THRU 1 #define SGTL5000_HEADPHONE_VOLUME 0.8 #endif #if defined(TEENSY4) @@ -148,20 +148,12 @@ //* AUDIO SOFTWARE SETTINGS //************************************************************************************************* #define SAMPLE_RATE 44100 + #ifdef USE_FX -#ifdef NUM_DRUMS -#define AUDIO_MEM (SAMPLE_RATE * NUM_DEXED * DELAY_MAX_TIME / 128000 + 36) + NUM_DRUMS * 3 -#else -// #define AUDIO_MEM 380 // T_4.1, 2 Instances, 0.5ms delay -#define AUDIO_MEM (SAMPLE_RATE * NUM_DEXED * DELAY_MAX_TIME / 128000 + 36) -#endif -#else -#ifdef NUM_DRUMS -#define AUDIO_MEM NUM_DEXED * 15 + NUM_DRUMS * 3 +#define AUDIO_MEM SAMPLE_RATE * NUM_DEXED * DELAY_MAX_TIME / 128000 + 36 #else #define AUDIO_MEM NUM_DEXED * 15 #endif -#endif #ifdef TEENSY_AUDIO_BOARD /* diff --git a/effect_auto_pan.cpp b/effect_auto_pan.cpp index 64a2cea..455ac31 100644 --- a/effect_auto_pan.cpp +++ b/effect_auto_pan.cpp @@ -36,8 +36,13 @@ void AudioEffectAutoPan::update(void) audio_block_t *out[2]; in = receiveReadOnly(0); - mod = receiveReadOnly(1); + if (!in) + return; + mod = receiveReadOnly(1); + if (!mod) + return; + out[0] = allocate(); out[1] = allocate(); diff --git a/effect_modulated_delay.cpp b/effect_modulated_delay.cpp index d750b7a..22d5af9 100644 --- a/effect_modulated_delay.cpp +++ b/effect_modulated_delay.cpp @@ -77,7 +77,12 @@ void AudioEffectModulatedDelay::update(void) return; block = receiveWritable(0); + if (!block) + return; + modulation = receiveReadOnly(1); + if (!modulation) + return; if (block && modulation) { diff --git a/effect_mono_stereo.cpp b/effect_mono_stereo.cpp index eec47ca..efd3ae9 100644 --- a/effect_mono_stereo.cpp +++ b/effect_mono_stereo.cpp @@ -49,6 +49,8 @@ void AudioEffectMonoStereo::update(void) audio_block_t *out[2]; in = receiveReadOnly(0); + if (!in) + return; out[0] = allocate(); out[1] = allocate(); diff --git a/effect_stereo_mono.cpp b/effect_stereo_mono.cpp index 8f4c00e..0a5d924 100644 --- a/effect_stereo_mono.cpp +++ b/effect_stereo_mono.cpp @@ -39,7 +39,12 @@ void AudioEffectStereoMono::update(void) audio_block_t *block[2]; block[0] = receiveWritable(0); + if (!block[0]) + return; + block[1] = receiveWritable(1); + if (!block[1]) + return; if (_enabled == false) {