Skip to content

Commit

Permalink
Temporarily bring back mozzi_config.h to allow intermediate testing
Browse files Browse the repository at this point in the history
Fix some bits in AVR in reaction to that. Seems to work overall, however.
  • Loading branch information
tfry-git committed Nov 14, 2023
1 parent 4b03226 commit 9b100ca
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 15 deletions.
2 changes: 1 addition & 1 deletion AudioOutput.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
#ifndef AUDIOOUTPUT
#define AUDIOOUTPUT

#include "MozziGuts.h"
#include "mozzi_config.h"

/** The type used to store a single channel of a single frame, internally. For compatibility with earlier versions of Mozzi this is defined as int.
* If you do not care about keeping old sketches working, you may be able to save some RAM by using int16_t, instead (on boards where int is larger
Expand Down
1 change: 1 addition & 0 deletions MozziGuts.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#endif

#include "hardware_defines.h"
#include "mozzi_config.h"

#if IS_TEENSY3() || IS_TEENSY4()
// required from http://github.com/pedvide/ADC for Teensy 3.*
Expand Down
19 changes: 7 additions & 12 deletions MozziGuts_impl_AVR.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,6 @@ ISR(TIMER1_OVF_vect, ISR_BLOCK) {
}

#elif MOZZI_IS(MOZZI_AUDIO_MODE, MOZZI_OUTPUT_2PIN_PWM)
# include "AudioConfigHiSpeed14bitPwm.h"
inline void audioOutput(const AudioOutput f) {
// read about dual pwm at
// http://www.openmusiclabs.com/learning/digital/pwm-dac/dual-pwm-circuits/
Expand All @@ -258,25 +257,21 @@ inline void audioOutput(const AudioOutput f) {
either the OCR1x buffer or OCR1x Compare Register in
the same system clock cycle.
*/
MOZZI_AUDIO_PIN_1_REGISTER = (f.l()+MOZZI_AUDIO_BIAS) >> MOZZI_AUDIO_BITS_PER_REGISTER;
MOZZI_AUDIO_PIN_1_LOW_REGISTER = (f.l()+MOZZI_AUDIO_BIAS) & ((1 << MOZZI_AUDIO_BITS_PER_REGISTER) - 1);
MOZZI_AUDIO_PIN_1_REGISTER = (f.l()+MOZZI_AUDIO_BIAS) >> MOZZI_AUDIO_BITS_PER_CHANNEL;
MOZZI_AUDIO_PIN_1_LOW_REGISTER = (f.l()+MOZZI_AUDIO_BIAS) & ((1 << MOZZI_AUDIO_BITS_PER_CHANNEL) - 1);
}

static void setupTimer2();
static void startAudio() {
backupPreMozziTimer1();
// pwm on timer 1
pinMode(MOZZI_AUDIO_CHANNEL_1_PIN,
OUTPUT); // set pin to output for audio, use 3.9k resistor
pinMode(MOZZI_AUDIO_CHANNEL_1_LOW_PIN,
OUTPUT); // set pin to output for audio, use 499k resistor
pinMode(MOZZI_AUDIO_PIN_1, OUTPUT); // set pin to output for audio, use 3.9k resistor
pinMode(MOZZI_AUDIO_PIN_1_LOW, OUTPUT); // set pin to output for audio, use 499k resistor
Timer1.initializeCPUCycles(
F_CPU/125000,
FAST); // set period for 125000 Hz fast pwm carrier frequency = 14 bits
Timer1.pwm(MOZZI_AUDIO_CHANNEL_1_PIN,
0); // pwm pin, 0% duty cycle, ie. 0 signal
Timer1.pwm(MOZZI_AUDIO_CHANNEL_1_LOW_PIN,
0); // pwm pin, 0% duty cycle, ie. 0 signal
Timer1.pwm(MOZZI_AUDIO_PIN_1, 0); // pwm pin, 0% duty cycle, ie. 0 signal
Timer1.pwm(MOZZI_AUDIO_PIN_1_LOW, 0);
// audio output interrupt on timer 2, sets the pwm levels of timer 1
setupTimer2();
}
Expand Down Expand Up @@ -310,7 +305,7 @@ static void backupPreMozziTimer2() {
// levels of timer 2
static void setupTimer2() {
backupPreMozziTimer2(); // to reset while pausing
unsigned long period = F_CPU / AUDIO_RATE;
unsigned long period = F_CPU / MOZZI_AUDIO_RATE;
FrequencyTimer2::setPeriodCPUCycles(period);
FrequencyTimer2::setOnOverflow(dummy);
FrequencyTimer2::enable();
Expand Down
4 changes: 2 additions & 2 deletions internal/config_checks_avr.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
#define MOZZI_AUDIO_PIN_1 TIMER1_A_PIN
#define MOZZI_AUDIO_PIN_1_REGISTER OCR1A
# endif
# if !defined(MOZZI_AUDIO_PIN_1)
# if !defined(MOZZI_AUDIO_PIN_1_LOW)
#define MOZZI_AUDIO_PIN_1_LOW TIMER1_B_PIN
#define MOZZI_AUDIO_PIN_1_LOW_REGISTER OCR1B
# endif
Expand All @@ -50,7 +50,7 @@
#define MOZZI_PWM_RATE 125000
# endif

# if !defined(MOZZI_PWM_RATE)
# if !defined(MOZZI_AUDIO_BITS_PER_CHANNEL)
#define MOZZI_AUDIO_BITS_PER_CHANNEL 7
# endif

Expand Down
1 change: 1 addition & 0 deletions mozzi_analog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "mozzi_analog.h"

#include "hardware_defines.h"
#include "mozzi_config.h"

/** NOTE: Since analog input code is heavily hardware dependent, and also heavily interweaved with AUDIO_INPUT,
* it was moved to MozziGuts.cpp / MozziGuts_impl_XYZ.hpp for better maintainability.
Expand Down
12 changes: 12 additions & 0 deletions mozzi_config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/** TODO: Temporarily brought back to life for testing config rework.
*
* The plan still is to have config in user space, instead.
*/

#include "MozziConfigValues.h"

//#define MOZZI_AUDIO_MODE MOZZI_OUTPUT_2PIN_PWM
//#define MOZZI_AUDIO_CHANNELS MOZZI_STEREO

#include "internal/config_check_generic.h"

0 comments on commit 9b100ca

Please sign in to comment.