CACHED_FUNCTION_ATTR defaultAudioOutput();
31 #if MOZZI_IS(MOZZI_ANALOG_READ, MOZZI_ANALOG_READ_STANDARD) 32 static voidadvanceADCStep();
33 static voidstartSecondADCReadOnCurrentChannel();
34 staticuint8_t adc_count = 0;
38 template<
byteBITS_IN,
byteBITS_OUT,
typenameT> constexpr T smartShift(T value) {
39 return(BITS_IN > BITS_OUT) ? value >> (BITS_IN - BITS_OUT) : (BITS_IN < BITS_OUT) ? value << (BITS_OUT - BITS_IN) : value;
45 # include "MozziGuts_impl_AVR.hpp" 47 # include "MozziGuts_impl_STM32.hpp" 49 # include "MozziGuts_impl_STM32duino.hpp" 51 # include "MozziGuts_impl_ESP32.hpp" 53 # include "MozziGuts_impl_ESP8266.hpp" 54 #elif (IS_TEENSY3() || IS_TEENSY4()) 55 # include "MozziGuts_impl_TEENSY.hpp" 57 # include "MozziGuts_impl_SAMD.hpp" 59 # include "MozziGuts_impl_RP2040.hpp" 61 # include "MozziGuts_impl_MBED.hpp" 63 # include "MozziGuts_impl_RENESAS.hpp" 65 # error "Platform not (yet) supported. Check MozziGuts_impl_template.hpp and existing implementations for a blueprint for adding your favorite MCU." 71 #if !defined(MOZZI__LEGACY_AUDIO_INPUT_IMPL) 72 # if !MOZZI_IS(MOZZI_AUDIO_INPUT, MOZZI_AUDIO_INPUT_NONE) 73 # define MOZZI__LEGACY_AUDIO_INPUT_IMPL 1 75 # define MOZZI__LEGACY_AUDIO_INPUT_IMPL 0 81 #if BYPASS_MOZZI_OUTPUT_BUFFER == true 82uint64_t samples_written_to_buffer = 0;
84 inline voidbufferAudioOutput(
const AudioOutputf) {
86++samples_written_to_buffer;
90 # define canBufferAudioOutput() (!output_buffer.isFull()) 91 # define bufferAudioOutput(f) output_buffer.write(f) 92 static voidCACHED_FUNCTION_ATTR defaultAudioOutput() {
94 #if MOZZI_IS(MOZZI__LEGACY_AUDIO_INPUT_IMPL, 1) 97startSecondADCReadOnCurrentChannel();
99audioOutput(output_buffer.read());
111 #if MOZZI_IS(MOZZI_ANALOG_READ, MOZZI_ANALOG_READ_STANDARD) 114 static volatileuint16_t analog_readings[NUM_ANALOG_INPUTS];
116 volatile staticint8_t current_channel = -1;
120 voidadcReadSelectedChannels() {
122 if((current_channel = adc_channels_to_read.
pop()) >= 0) adcStartConversion(current_channel);
128__attribute__((noinline))
voidadcStartReadCycle() {
129 if(current_channel < 0)
131 #if MOZZI_IS(MOZZI__LEGACY_AUDIO_INPUT_IMPL, 1) 134adcReadSelectedChannels();
140uint16_t mozziAnalogRead(uint8_t pin) {
141pin = adcPinToChannelNum(pin);
142adc_channels_to_read.
push(pin);
143 returnanalog_readings[channelNumToIndex(pin)];
146 #if !MOZZI_IS(MOZZI_AUDIO_INPUT, MOZZI_AUDIO_INPUT_NONE) 147 staticuint16_t audio_input;
151 #if MOZZI_IS(MOZZI__LEGACY_AUDIO_INPUT_IMPL, 1) 154 #define audioInputAvailable() (!input_buffer.isEmpty()) 155 #define readAudioInput() (input_buffer.read()) 157 inline voidadvanceADCStep() {
162input_buffer.write(getADCReading());
163adcReadSelectedChannels();
169startSecondADCReadOnCurrentChannel();
174analog_readings[channelNumToIndex(current_channel)] = getADCReading();
187inline void advanceADCStep() {
190startSecondADCReadOnCurrentChannel();
194analog_readings[channelNumToIndex(current_channel)] = getADCReading();
195adcReadSelectedChannels();
205 returnanalogRead(pin);
214 staticuint16_t update_control_timeout;
215 staticuint16_t update_control_counter;
217 inline voidadvanceControlLoop() {
218 if(!update_control_counter) {
219update_control_counter = update_control_timeout;
221 #if MOZZI_IS(MOZZI_ANALOG_READ, MOZZI_ANALOG_READ_STANDARD) 225--update_control_counter;
232 if(canBufferAudioOutput()) {
233advanceControlLoop();
236 #if defined(LOOP_YIELD) 240 #if !MOZZI_IS(MOZZI_AUDIO_INPUT, MOZZI_AUDIO_INPUT_NONE) 241 if(audioInputAvailable()) audio_input = readAudioInput();
245 #if defined(AUDIO_HOOK_HOOK) 257 #if (BYPASS_MOZZI_OUTPUT_BUFFER != true) 258 returnoutput_buffer.count();
259 #elif defined(AUDIOTICK_ADJUSTMENT) 260 returnsamples_written_to_buffer - (AUDIOTICK_ADJUSTMENT);
262 returnsamples_written_to_buffer;
271 voidstartMozzi(
intcontrol_rate_hz) {
272 #if !MOZZI_IS(MOZZI_ANALOG_READ, MOZZI_ANALOG_READ_NONE) 273MozziPrivate::setupMozziADC(FAST_ADC);
281uint32_t MozziRandPrivate::x=132456789;
282uint32_t MozziRandPrivate::y=362436069;
283uint32_t MozziRandPrivate::z=521288629;
290 #undef BYPASS_MOZZI_OUTPUT_BUFFER 291 #undef AUDIO_HOOK_HOOK 292 #undef AUDIOTICK_ADJUSTMENT 293 #undef MOZZI__LEGACY_AUDIO_INPUT_IMPL 300 unsigned long mozziMicros() {
returnMozziPrivate::mozziMicros(); };
301 unsigned long audioTicks() {
returnMozziPrivate::audioTicks(); };
302 voidstartMozzi(
intcontrol_rate_hz) { MozziPrivate::startMozzi(control_rate_hz); };
304 template<
byteRES> uint16_t
mozziAnalogRead(uint8_t pin) {
returnMozziPrivate::smartShift<MOZZI__INTERNAL_ANALOG_READ_RESOLUTION, RES>(MozziPrivate::mozziAnalogRead(pin));};
305 #if !MOZZI_IS(MOZZI_AUDIO_INPUT, MOZZI_AUDIO_INPUT_NONE) 308 #if MOZZI_IS(MOZZI_ANALOG_READ, MOZZI_ANALOG_READ_STANDARD) 309 voidsetupMozziADC(int8_t speed) { MozziPrivate::setupMozziADC(speed); };
311uint8_t adcPinToChannelNum(uint8_t pin) {
returnMozziPrivate::adcPinToChannelNum(pin); };
316 #if !MOZZI_IS(MOZZI_AUDIO_MODE, MOZZI_OUTPUT_EXTERNAL_TIMED, MOZZI_OUTPUT_EXTERNAL_CUSTOM) 317MOZZI_DEPRECATED(
"n/a",
"Sketch has audioOutput() function, although external output is not configured.") void audioOutput(const
AudioOutput) {};
319 #if !MOZZI_IS(MOZZI_AUDIO_MODE, MOZZI_OUTPUT_EXTERNAL_CUSTOM)A simple stack, used internally for keeping track of analog input channels as they are read.
void push(T item)
Put an item on the stack.
T pop()
Get the item on top of the stack.
uint16_t getAudioInput()
See getAudioInput().
uint16_t mozziAnalogRead(uint8_t pin)
See mozziAnalogRead().
void setupFastAnalogRead(int8_t speed=FAST_ADC)
This is automatically called in startMozzi.
#define MOZZI_AUDIO_RATE
Defines the audio rate, i.e.
#define MOZZI_AUDIO_INPUT_PIN
This sets which analog input channel to use for audio input, if you have enabled MOZZI_AUDIO_INPUT,...
#define MOZZI_ANALOG_READ
Whether to compile in support for non-blocking analog reads.
void audioHook()
This is required in Arduino's loop().
unsigned long audioTicks()
An alternative for Arduino time functions like micros() and millis().
void updateControl()
This is where you put your control code.
void stopMozzi()
Stops audio and control interrupts and restores the timers to the values they had before Mozzi was st...
AudioOutput_t updateAudio()
This is where you put your audio code.
unsigned long mozziMicros()
An alternative for Arduino time functions like micros() and millis().
This struct encapsulates one frame of mono audio output.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4