diff --git a/MozziGuts.cpp b/MozziGuts.cpp index 375801005..facc8fef8 100644 --- a/MozziGuts.cpp +++ b/MozziGuts.cpp @@ -18,12 +18,33 @@ //#include "mozzi_utils.h" #include "AudioOutput.h" -// forward-declarations for use in hardware-specific implementations: -static void advanceADCStep(); -static uint8_t adc_count = 0; -// forward-declarations; to be supplied by plaform specific implementations -static void startSecondADCReadOnCurrentChannel(); +// Forward declaration +static void CACHED_FUNCTION_ATTR defaultAudioOutput(); + +// Include the appropriate implementation +#if IS_AVR() +# include "MozziGuts_impl_AVR.hpp" +#elif IS_STM32() +# include "MozziGuts_impl_STM32.hpp" +#elif IS_ESP32() +# include "MozziGuts_impl_ESP32.hpp" +#elif IS_ESP8266() +# include "MozziGuts_impl_ESP8266.hpp" +#elif (IS_TEENSY3() || IS_TEENSY4()) +# include "MozziGuts_impl_TEENSY.hpp" +#elif (IS_SAMD21()) +# include "MozziGuts_impl_SAMD.hpp" +#elif (IS_RP2040()) +# include "MozziGuts_impl_RP2040.hpp" +#elif (IS_MBED()) +# include "MozziGuts_impl_MBED.hpp" +#else +# error "Platform not (yet) supported. Check MozziGuts_impl_template.hpp and existing implementations for a blueprint for adding your favorite MCU." +#endif + + +static uint8_t adc_count = 0; ////// BEGIN Output buffering ///// #if BYPASS_MOZZI_OUTPUT_BUFFER == true @@ -53,29 +74,8 @@ static void CACHED_FUNCTION_ATTR defaultAudioOutput() { ////// END Output buffering /////// -// Include the appropriate implementation -#if IS_AVR() -# include "MozziGuts_impl_AVR.hpp" -#elif IS_STM32() -# include "MozziGuts_impl_STM32.hpp" -#elif IS_ESP32() -# include "MozziGuts_impl_ESP32.hpp" -#elif IS_ESP8266() -# include "MozziGuts_impl_ESP8266.hpp" -#elif (IS_TEENSY3() || IS_TEENSY4()) -# include "MozziGuts_impl_TEENSY.hpp" -#elif (IS_SAMD21()) -# include "MozziGuts_impl_SAMD.hpp" -#elif (IS_RP2040()) -# include "MozziGuts_impl_RP2040.hpp" -#elif (IS_MBED()) -# include "MozziGuts_impl_MBED.hpp" -#else -# error "Platform not (yet) supported. Check MozziGuts_impl_template.hpp and existing implementations for a blueprint for adding your favorite MCU." -#endif - -////// BEGIN Analog inpput code //////// +////// BEGIN Analog input code //////// /* Analog input code was informed initially by a discussion between jRaskell, bobgardner, theusch, Koshchi, and code by jRaskell. http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&p=789581 @@ -208,8 +208,12 @@ void audioHook() // 2us on AVR excluding updateAudio() #if defined(LOOP_YIELD) LOOP_YIELD +#endif + } +// Like LOOP_YIELD, but running every cycle of audioHook(), not just once per sample +#if defined(AUDIO_HOOK_HOOK) + AUDIO_HOOK_HOOK #endif - } // setPin13Low(); } diff --git a/MozziGuts_impl_MBED.hpp b/MozziGuts_impl_MBED.hpp index 234a5d2ca..34fce04bc 100644 --- a/MozziGuts_impl_MBED.hpp +++ b/MozziGuts_impl_MBED.hpp @@ -163,10 +163,21 @@ void stopMozzi() { #define US_PER_AUDIO_TICK (1000000L / AUDIO_RATE) #include #include -#if (MBED_AUDIOw_OUT_MODE == TIMEDPWM) +mbed::Ticker audio_output_timer; + +#if (EXTERNAL_AUDIO_OUTPUT == true) +volatile bool audio_output_requested = false; +inline void defaultAudioOutputCallback() { + audio_output_requested = true; +} +#define AUDIO_HOOK_HOOK { if (audio_output_requested) { audio_output_requested = false; defaultAudioOutput(); } } +#else +#define defaultAudioOutputCallback defaultAudioOutput +#endif + +#if (MBED_AUDIO_OUT_MODE == TIMEDPWM && EXTERNAL_AUDIO_OUTPUT != true) #define US_PER_PWM_CYCLE (US_PER_AUDIO_TICK) mbed::PwmOut pwmpin1(digitalPinToPinName(AUDIO_CHANNEL_1_PIN)); -mbed::Ticker audio_output_timer; #if (AUDIO_CHANNELS > 1) mbed::PwmOut pwmpin2(digitalPinToPinName(AUDIO_CHANNEL_2_PIN)); #endif @@ -179,10 +190,10 @@ inline void audioOutput(const AudioOutput f) { pwmpin2.write(.5 + (float) f.r() / ((float) (1L << AUDIO_BITS))); #endif } -#endif +#endif // #if (MBED_AUDIO_OUT_MODE == TIMEDPWM && EXTERNAL_AUDIO_OUTPUT != true) static void startAudio() { -#if (MBED_AUDIO_OUT_MODE == TIMEDPWM) +#if (MBED_AUDIO_OUT_MODE == TIMEDPWM && EXTERNAL_AUDIO_OUTPUT != true) pwmpin1.period_us(US_PER_UPDATE); pwmpin1.write(.5); #if (AUDIO_CHANNELS > 1) @@ -190,7 +201,7 @@ static void startAudio() { pwmpin2.write(.5); #endif #endif - audio_output_timer.attach_us(&defaultAudioOutput, US_PER_AUDIO_TICK); + audio_output_timer.attach_us(&defaultAudioOutputCallback, US_PER_AUDIO_TICK); } void stopMozzi() {