diff --git a/MicroDexed.ino b/MicroDexed.ino index e1082ad..82b286b 100644 --- a/MicroDexed.ino +++ b/MicroDexed.ino @@ -29,6 +29,7 @@ #include #include #include +#include "OpenAudio_ArduinoLibrary.h" #include "midi_devices.hpp" #include "synth_dexed.h" #include "dexed_sd.h" @@ -43,7 +44,8 @@ #include "UI.hpp" // Audio engines -AudioSynthDexed* MicroDexed[NUM_DEXED]; +AudioSynthDexed_F32* MicroDexed[NUM_DEXED]; +AudioConvert_F32toI16* convertf32toi16[NUM_DEXED]; #if defined(USE_FX) AudioSynthWaveform* chorus_modulator[NUM_DEXED]; #if MOD_FILTER_OUTPUT != MOD_NO_FILTER_OUTPUT @@ -165,15 +167,19 @@ AudioConnection patchCord24(audio_thru_mixer_l, 0, i2s1, 1); // uint16_t nDynamic = 0; #if defined(USE_FX) && MOD_FILTER_OUTPUT != MOD_NO_FILTER_OUTPUT -AudioConnection * dynamicConnections[NUM_DEXED * 16]; +//AudioConnection * dynamicConnections[NUM_DEXED * 16]; +AudioConnection * dynamicConnections[NUM_DEXED * 17]; #elif defined(USE_FX) && MOD_FILTER_OUTPUT == MOD_NO_FILTER_OUTPUT -AudioConnection * dynamicConnections[NUM_DEXED * 15]; +//AudioConnection * dynamicConnections[NUM_DEXED * 15]; +AudioConnection * dynamicConnections[NUM_DEXED * 16]; #else -AudioConnection * dynamicConnections[NUM_DEXED * 4]; +//AudioConnection * dynamicConnections[NUM_DEXED * 4]; +AudioConnection * dynamicConnections[NUM_DEXED * 5]; #endif void create_audio_engine_chain(uint8_t instance_id) { - MicroDexed[instance_id] = new AudioSynthDexed(SAMPLE_RATE); + MicroDexed[instance_id] = new AudioSynthDexed_F32(SAMPLE_RATE); + convertf32toi16[instance_id] = new AudioConvert_F32toI16(); mono2stereo[instance_id] = new AudioEffectMonoStereo(); #if defined(USE_FX) chorus_modulator[instance_id] = new AudioSynthWaveform(); @@ -187,10 +193,15 @@ void create_audio_engine_chain(uint8_t instance_id) delay_mixer[instance_id] = new AudioMixer4(); #endif - dynamicConnections[nDynamic++] = new AudioConnection(*MicroDexed[instance_id], 0, microdexed_peak_mixer, instance_id); + //dynamicConnections[nDynamic++] = new AudioConnection(*MicroDexed[instance_id], 0, microdexed_peak_mixer, instance_id); + dynamicConnections[nDynamic++] = new AudioConnection(*MicroDexed[instance_id], 0, *convertf32toi16[instance_id], 0); + dynamicConnections[nDynamic++] = new AudioConnection(*convertf32toi16[instance_id], 0, microdexed_peak_mixer, instance_id); + #if defined(USE_FX) - dynamicConnections[nDynamic++] = new AudioConnection(*MicroDexed[instance_id], 0, *chorus_mixer[instance_id], 0); - dynamicConnections[nDynamic++] = new AudioConnection(*MicroDexed[instance_id], 0, *modchorus[instance_id], 0); + //dynamicConnections[nDynamic++] = new AudioConnection(*MicroDexed[instance_id], 0, *chorus_mixer[instance_id], 0); + //dynamicConnections[nDynamic++] = new AudioConnection(*MicroDexed[instance_id], 0, *modchorus[instance_id], 0); + dynamicConnections[nDynamic++] = new AudioConnection(*convertf32toi16[instance_id], 0, *chorus_mixer[instance_id], 0); + dynamicConnections[nDynamic++] = new AudioConnection(*convertf32toi16[instance_id], 0, *modchorus[instance_id], 0); #if MOD_FILTER_OUTPUT != MOD_NO_FILTER_OUTPUT dynamicConnections[nDynamic++] = new AudioConnection(*chorus_modulator[instance_id], 0, *modchorus_filter[instance_id], 0); dynamicConnections[nDynamic++] = new AudioConnection(*modchorus_filter[instance_id], 0, *modchorus[instance_id], 1); @@ -207,7 +218,8 @@ void create_audio_engine_chain(uint8_t instance_id) dynamicConnections[nDynamic++] = new AudioConnection(*mono2stereo[instance_id], 0, reverb_mixer_r, instance_id); dynamicConnections[nDynamic++] = new AudioConnection(*mono2stereo[instance_id], 1, reverb_mixer_l, instance_id); #else - dynamicConnections[nDynamic++] = new AudioConnection(*MicroDexed[instance_id], 0, *mono2stereo[instance_id], 0); + //dynamicConnections[nDynamic++] = new AudioConnection(*MicroDexed[instance_id], 0, *mono2stereo[instance_id], 0); + dynamicConnections[nDynamic++] = new AudioConnection(*convertf32toi16[instance_id], 0, *mono2stereo[instance_id], 0); #endif dynamicConnections[nDynamic++] = new AudioConnection(*mono2stereo[instance_id], 0, master_mixer_r, instance_id); dynamicConnections[nDynamic++] = new AudioConnection(*mono2stereo[instance_id], 1, master_mixer_l, instance_id); @@ -274,6 +286,7 @@ void setup() // Start audio system //AudioNoInterrupts(); AudioMemory(AUDIO_MEM); + AudioMemory_F32(AUDIO_MEM_F32); #ifdef DISPLAY_LCD_SPI pinMode(SDCARD_CS_PIN, OUTPUT); @@ -454,6 +467,7 @@ void setup() // Initialize processor and memory measurements AudioProcessorUsageMaxReset(); AudioMemoryUsageMaxReset(); + AudioMemoryUsageMaxReset_F32(); #ifdef DEBUG for (uint8_t instance_id = 0; instance_id < NUM_DEXED; instance_id++) @@ -2227,6 +2241,12 @@ void show_cpu_and_mem_usage(void) Serial.print(AudioProcessorUsageMax(), 2); Serial.print(F("%|CPUMAXCNT:")); Serial.print(cpumax, DEC); + Serial.print(F("|MEM_F32:")); + Serial.print(AudioMemoryUsage_F32(), DEC); + Serial.print(F("|MEMMAX_F32:")); + Serial.print(AudioMemoryUsageMax_F32(), DEC); + Serial.print(F("|AUDIO_MEM_MAX_F32:")); + Serial.print(AUDIO_MEM_F32, DEC); Serial.print(F("|MEM:")); Serial.print(AudioMemoryUsage(), DEC); Serial.print(F("|MEMMAX:")); @@ -2263,6 +2283,7 @@ void show_cpu_and_mem_usage(void) #endif AudioProcessorUsageMaxReset(); AudioMemoryUsageMaxReset(); + AudioMemoryUsageMaxReset_F32(); } #endif diff --git a/UI.hpp b/UI.hpp index 7968a3f..ee360e3 100644 --- a/UI.hpp +++ b/UI.hpp @@ -70,7 +70,7 @@ extern void change_disp_sd(bool d); #endif extern AudioControlSGTL5000 sgtl5000_1; -extern AudioSynthDexed* MicroDexed[NUM_DEXED]; +extern AudioSynthDexed_F32* MicroDexed[NUM_DEXED]; #if defined(USE_FX) extern AudioSynthWaveform* chorus_modulator[NUM_DEXED]; extern AudioEffectModulatedDelay* modchorus[NUM_DEXED]; diff --git a/config.h b/config.h index e314618..9748a5f 100644 --- a/config.h +++ b/config.h @@ -128,11 +128,12 @@ //* AUDIO SOFTWARE SETTINGS //************************************************************************************************* #define SAMPLE_RATE 44100 -#if AUDIO_BLOCK_SAMPLES == 64 -#define AUDIO_MEM 256 -#else -#define AUDIO_MEM 128 -#endif +//#if AUDIO_BLOCK_SAMPLES == 64 +//#define AUDIO_MEM 256 +//#else +#define AUDIO_MEM 300 +#define AUDIO_MEM_F32 10 +//#endif #ifdef TEENSY_AUDIO_BOARD /* diff --git a/dexed_sd.h b/dexed_sd.h index 4a00eb9..f18364d 100644 --- a/dexed_sd.h +++ b/dexed_sd.h @@ -24,13 +24,13 @@ */ #include "config.h" +#include "synth_dexed.h" #ifndef DEXED_SYSEX_H_INCLUDED #define DEXED_SYSEX_H_INCLUDED extern uint8_t sd_card; -extern Dexed* dexed; -extern AudioSynthDexed * MicroDexed[NUM_DEXED]; +extern AudioSynthDexed_F32* MicroDexed[NUM_DEXED]; extern void show_patch(uint8_t instance_id); extern void send_sysex_voice(uint8_t midi_channel, uint8_t* data); diff --git a/synth_dexed.cpp b/synth_dexed.cpp index 68baae8..26db1f7 100644 --- a/synth_dexed.cpp +++ b/synth_dexed.cpp @@ -409,7 +409,7 @@ void Dexed::getSamples(uint16_t n_samples, float32_t* buffer) { for (i = 0; i < max_notes; i++) { - if ( voices[i].live ) + if (voices[i].live) voices[i].dx7_note->update(data, voices[i].midi_note, voices[i].velocity, voices[i].porta, &controllers); } lfo.reset(data + 137); @@ -437,7 +437,7 @@ void Dexed::getSamples(uint16_t n_samples, float32_t* buffer) for (j = 0; j < _N_; ++j) { - buffer[i + j] += static_cast(audiobuf.get()[j]) / 32768; + buffer[i + j] += static_cast(audiobuf.get()[j]) / 32768.0f; audiobuf.get()[j] = 0; } } diff --git a/synth_dexed.h b/synth_dexed.h index d860687..2cbd5ab 100644 --- a/synth_dexed.h +++ b/synth_dexed.h @@ -1,9 +1,7 @@ #include #include +#include #include "config.h" -#if defined(USE_OPEN_AUDIO_LIB) -#include "OpenAudio_ArduinoLibrary.h" -#endif /***************************************************** CODE; orig_code/synth.h @@ -1171,54 +1169,6 @@ struct Porta { CODE; orig_code/source_microdexed.h *****************************************************/ -class AudioSynthDexed : public AudioStream, public Dexed { - public: - const uint16_t audio_block_time_us = 1000000 / (SAMPLE_RATE / AUDIO_BLOCK_SAMPLES); - uint32_t xrun = 0; - uint16_t render_time_max = 0; - - AudioSynthDexed(int sample_rate) : AudioStream(0, NULL), Dexed(sample_rate) { }; - - void update(void) - { - if (in_update == true) - { - xrun++; - return; - } - else - in_update = true; - - elapsedMicros render_time; - audio_block_t *lblock; - - lblock = allocate(); - - if (!lblock) - { - in_update = false; - return; - } - - getSamples(AUDIO_BLOCK_SAMPLES, lblock->data); - - if (render_time > audio_block_time_us) // everything greater audio_block_time_us (2.9ms for buffer size of 128) is a buffer underrun! - xrun++; - - if (render_time > render_time_max) - render_time_max = render_time; - - transmit(lblock, 0); - release(lblock); - - in_update = false; - }; - - private: - volatile bool in_update = false; -}; - -#if defined(USE_OPEN_AUDIO_LIB) class AudioSynthDexed_F32 : public AudioStream_F32, public Dexed { public: const uint16_t audio_block_time_us = 1000000 / (SAMPLE_RATE / AUDIO_BLOCK_SAMPLES); @@ -1265,4 +1215,3 @@ class AudioSynthDexed_F32 : public AudioStream_F32, public Dexed { private: volatile bool in_update = false; }; -#endif