Skip to content

Commit

Permalink
Fix a first round of bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
tfry-git committed Nov 13, 2023
1 parent 1c42eec commit 37cbd58
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 35 deletions.
2 changes: 1 addition & 1 deletion AudioOutput.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ struct StereoOutput {
StereoOutput(AudioOutputStorage_t l, AudioOutputStorage_t r) : _l(l), _r(r) {};
/** Default contstructor */
StereoOutput() : _l(0), _r(0) {};
#if (AUDIO_CHANNELS != STEREO)
#if (MOZZI_AUDIO_CHANNELS != MOZZI_STEREO)
/** Conversion to int operator: If used in a mono config, returns only the left channel (and gives a compile time warning).
This _could_ be turned into an operator for implicit conversion in this case. For now we chose to apply conversion on demand, only, as most of the time
using StereoOutput in a mono config, is not intended. */
Expand Down
4 changes: 2 additions & 2 deletions MozziConfigExample.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@
* on platforms that do support it may come with a considerable performance overhead. Don't enable, unless you need this.
*
* Currently allowed values are:
* - MOZZI_AUDIO_INPUT_DISABLED
* - MOZZI_AUDIO_INPUT_NONE
* No audio input
* - MOZZI_AUDIO_INPUT_STANDARD
* Audio input enabled (currently there is only the "standard" method, but future versions might allow additional choice, here).
Expand Down Expand Up @@ -233,7 +233,7 @@
* of the resistors and ground. This is discussed in much more detail on http://www.openmusiclabs.com/learning/digital/pwm-dac/dual-pwm-circuits/
* Also, there are higher quality output circuits are on the site.
*
* On the classic Arduino Uno, the default pinout in this mode is:
* On the classic Arduino Uno, the default pinout in this mode is:
* - Pin 9 (high bits) and Pin 10 (low bits) -> configurable using MOZZI_AUDIO_PIN_1 and MOZZI_AUDIO_PIN_1_LOW
*
* Here is table of the default pins on some other boards. Rows with an x on it have actually been tested (and importantly, the outcome recoreded;
Expand Down
2 changes: 1 addition & 1 deletion MozziConfigValues.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ TODO: Fix documentation
#define MOZZI_OUTPUT_I2S_DAC 107
#define MOZZI_OUTPUT_INTERNAL_DAC 108

#define MOZZI_AUDIO_INPUT_DISABLED 201
#define MOZZI_AUDIO_INPUT_NONE 201
#define MOZZI_AUDIO_INPUT_STANDARD 202

#define MOZZI_ANALOG_READ_NONE 201
Expand Down
1 change: 0 additions & 1 deletion MozziGuts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include "CircularBuffer.h"
#include "MozziGuts.h"
#include "mozzi_analog.h"
#include "mozzi_config.h" // at the top of all MozziGuts and analog files
//#include "mozzi_utils.h"
#include "AudioOutput.h"

Expand Down
6 changes: 0 additions & 6 deletions MozziGuts.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,6 @@
#include "AudioConfigRP2040.h"
#elif IS_MBED()
#include "AudioConfigMBED.h"
#elif IS_AVR() && (AUDIO_MODE == STANDARD)
#include "AudioConfigStandard9bitPwm.h"
#elif IS_AVR() && (AUDIO_MODE == STANDARD_PLUS)
#include "AudioConfigStandardPlus.h"
#elif IS_AVR() && (AUDIO_MODE == HIFI)
#include "AudioConfigHiSpeed14bitPwm.h"
#elif IS_RENESAS()
#include "AudioConfigRenesas.h"
#endif
Expand Down
5 changes: 0 additions & 5 deletions MozziGuts_impl_AVR.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,6 @@ ISR(TIMER1_OVF_vect, ISR_BLOCK) {
defaultAudioOutput();
}
#elif (AUDIO_MODE == STANDARD) || (AUDIO_MODE == STANDARD_PLUS)
# if (AUDIO_MODE == STANDARD_PLUS)
# include "AudioConfigStandardPlus.h"
# else
# include "AudioConfigStandard9bitPwm.h"
# endif
inline void audioOutput(const AudioOutput f)
{
AUDIO_CHANNEL_1_OUTPUT_REGISTER = f.l()+AUDIO_BIAS;
Expand Down
24 changes: 12 additions & 12 deletions internal/config_check_generic.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
#ifndef MOZZI_CONFIG_CHECK_GENERIC_H
#define MOZZI_CONFIG_CHECK_GENERIC_H

#include <MozziConfigValues.h> // in case not user-included
#include "../MozziConfigValues.h" // in case not user-included
#include "mozzi_macros.h"

//// Step 1: Apply missing defaults for generic config options (not the hardware specific ones)
#if not defined(MOZZI_COMPATIBILITY_LEVEL)
Expand All @@ -16,7 +17,7 @@
#warning Use of STEREO_HACK is deprecated. Use AUDIO_CHANNELS STEREO, instead.
#define MOZZI_AUDIO_CHANNELS MOZZI_STEREO
#else
#define MOZZI_MONO
#define MOZZI_AUDIO_CHANNELS MOZZI_MONO
#endif
#endif

Expand All @@ -30,10 +31,10 @@
//MOZZI_ANALOG_READ -> hardware specific

#if not defined(MOZZI_AUDIO_INPUT)
#define MOZZI_AUDIO_INPUT_DISABLED
#define MOZZI_AUDIO_INPUT MOZZI_AUDIO_INPUT_NONE
#endif

#if not defined(MOZZI_AUDIO_INPUT_PIN)
#if !MOZZI_IS(MOZZI_AUDIO_INPUT, MOZZI_AUDIO_INPUT_NONE) && !defined(MOZZI_AUDIO_INPUT_PIN)
#define MOZZI_AUDIO_INPUT_PIN 0
#endif

Expand All @@ -50,7 +51,7 @@
#include "config_checks_avr.h"
#else
// TODO

#error oops
#endif


Expand Down Expand Up @@ -80,9 +81,6 @@ MOZZI_CHECK_POW2(MOZZI_CONTROL_RATE)
// Hardware-specific checks file should have more narrow checks for most options, below, but is not required to, so let's check for anything that is wildly out of scope:
MOZZI_CHECK_SUPPORTED(MOZZI_AUDIO_MODE, MOZZI_OUTPUT_PWM, MOZZI_OUTPUT_2PIN_PWM, MOZZI_OUTPUT_EXTERNAL_TIMED, MOZZI_OUTPUT_EXTERNAL_CUSTOM, MOZZI_OUTPUT_PDM_VIA_I2S, MOZZI_OUTPUT_PDM_VIA_SERIAL, MOZZI_OUTPUT_I2S_DAC, MOZZI_OUTPUT_INTERNAL_DAC)
MOZZI_CHECK_SUPPORTED(MOZZI_ANALOG_READ, MOZZI_ANALOG_READ_NONE, MOZZI_ANALOG_READ_STANDARD)
static_assert(MOZZI_AUDIO_BITS <= (4*sizeof(AudioOutputStorage_t)), "Configured MOZZI_AUDIO_BITS is too large for the internal storage type");



/// Step 4: Init Read-only defines that depend on other values
#if !defined(MOZZI_AUDIO_BIAS)
Expand All @@ -97,7 +95,7 @@ static_assert(MOZZI_AUDIO_BITS <= (4*sizeof(AudioOutputStorage_t)), "Configured
#if MOZZI_AUDIO_RATE == 8192
#define AUDIO_RATE_AS_LSHIFT 13
#define MICROS_PER_AUDIO_TICK 122
#if MOZZI_AUDIO_RATE == 16384
#elif MOZZI_AUDIO_RATE == 16384
#define AUDIO_RATE_AS_LSHIFT 14
#define MICROS_PER_AUDIO_TICK 61 // 1000000 / 16384 = 61.035, ...* 256 = 15625
#elif MOZZI_AUDIO_RATE == 32768
Expand All @@ -107,7 +105,7 @@ static_assert(MOZZI_AUDIO_BITS <= (4*sizeof(AudioOutputStorage_t)), "Configured
#define AUDIO_RATE_AS_LSHIFT 16
#define MICROS_PER_AUDIO_TICK 15
#else
#error Whoopsie, not LSHIFT defined for this audio rate. Please report and/or fix
//#error Whoopsie, not LSHIFT defined for this audio rate. Please report and/or fix
#endif


Expand All @@ -117,7 +115,9 @@ static_assert(MOZZI_AUDIO_BITS <= (4*sizeof(AudioOutputStorage_t)), "Configured
#define CONTROL_RATE MOZZI_CONTROL_RATE
#endif



/// Step 6: Some more checks that need to be at the end, because of requiring end of the foodchain headers
// TODO: Rather move this up again, and make AudioOutputStorage_t a primary config option
#include "../AudioOutput.h"
static_assert(MOZZI_AUDIO_BITS <= (8*sizeof(AudioOutputStorage_t)), "Configured MOZZI_AUDIO_BITS is too large for the internal storage type");

#endif
11 changes: 6 additions & 5 deletions internal/config_checks_avr.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
// NOTE: This step is actually required for all ports

#if not defined(MOZZI_AUDIO_MODE)
#define MOZZI_OUTPUT_PWM
#define MOZZI_AUDIO_MODE MOZZI_OUTPUT_PWM
#endif

#if not defined(MOZZI_AUDIO_RATE)
#define 16384
#define MOZZI_AUDIO_RATE 16384
#endif

#if not defined(MOZZI_ANALOG_READ)
#define MOZZI_ANALOG_READ MOZZI_ANALOG_READS_STANDARD
#define MOZZI_ANALOG_READ MOZZI_ANALOG_READ_STANDARD
#endif

// Pins for regular PWM output
Expand Down Expand Up @@ -58,10 +58,10 @@

MOZZI_CHECK_SUPPORTED(MOZZI_AUDIO_MODE, MOZZI_OUTPUT_PWM, MOZZI_OUTPUT_2PIN_PWM, MOZZI_OUTPUT_EXTERNAL_TIMED, MOZZI_OUTPUT_EXTERNAL_CUSTOM)

#if (MOZZI_IS(MOZZI_AUDIO_MODE, MOZZI_OUTPUT_PWM)
#if MOZZI_IS(MOZZI_AUDIO_MODE, MOZZI_OUTPUT_PWM)
MOZZI_CHECK_SUPPORTED(MOZZI_AUDIO_CHANNELS, MOZZI_MONO, MOZZI_STEREO)
#endif
#if (MOZZI_IS(MOZZI_AUDIO_MODE, MOZZI_OUTPUT_2PIN_PWM)
#if MOZZI_IS(MOZZI_AUDIO_MODE, MOZZI_OUTPUT_2PIN_PWM)
MOZZI_CHECK_SUPPORTED(MOZZI_AUDIO_CHANNELS, MOZZI_MONO)
#endif

Expand All @@ -72,6 +72,7 @@ MOZZI_CHECK_SUPPORTED(MOZZI_AUDIO_RATE, 16384, 32768)

MOZZI_CHECK_SUPPORTED(MOZZI_ANALOG_READ, MOZZI_ANALOG_READ_NONE, MOZZI_ANALOG_READ_STANDARD)
MOZZI_CHECK_SUPPORTED(MOZZI_AUDIO_INPUT, MOZZI_AUDIO_INPUT_NONE, MOZZI_AUDIO_INPUT_STANDARD)
#include "../config/known_16bit_timers.h"
#if defined(TIMER1_C_PIN)
MOZZI_CHECK_SUPPORTED(MOZZI_AUDIO_PIN_1, TIMER1_A_PIN, TIMER1_B_PIN, TIMER1_C_PIN);
#else
Expand Down
2 changes: 1 addition & 1 deletion internal/mozzi_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
MOZZI__INVALID_CONFIG_VALUE, MOZZI__INVALID_CONFIG_VALUE, MOZZI__INVALID_CONFIG_VALUE, MOZZI__INVALID_CONFIG_VALUE, MOZZI__INVALID_CONFIG_VALUE, MOZZI__INVALID_CONFIG_VALUE))

/// Complain if the given argument is not a power of two
#define MOZZI_CHECK_POW_2(X) static_assert((X & (X - 1)) == 0, #X " must be a power of two");
#define MOZZI_CHECK_POW2(X) static_assert((X & (X - 1)) == 0, #X " must be a power of two");

/// Simply a way to check if X is Y, realiably, in case one or both are defined empty (such as because of a programmer's typo)
#define MOZZI_IS(X, Y) (X == Y)
Expand Down
1 change: 0 additions & 1 deletion mozzi_analog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
*/


#include "mozzi_config.h"
#include "mozzi_analog.h"

#include "hardware_defines.h"
Expand Down

0 comments on commit 37cbd58

Please sign in to comment.