Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 32 additions & 28 deletions MozziGuts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
}

Expand Down
21 changes: 16 additions & 5 deletions MozziGuts_impl_MBED.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,21 @@ void stopMozzi() {
#define US_PER_AUDIO_TICK (1000000L / AUDIO_RATE)
#include <mbed.h>
#include <pinDefinitions.h>
#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
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that the latest fixes there are not yet merged: arduino-libraries/Arduino_AdvancedAnalog#36 . Are you sure you are using that?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy-and-paste fail?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oups, and an epic one! I wanted to ask if this was for forward compatibility for other output modes as defaultAudioOutput is never used (yet?) in this implementation.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. It doesn't really make sense as long as there is no TIMED_PWM. I'll clean up (this and other bits) later.

#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
Expand All @@ -179,18 +190,18 @@ 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)
pwmpin2.period_us(US_PER_UPDATE);
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() {
Expand Down