Mozzi brings your Arduino to life by allowing it to produce much more complex and interesting growls, sweeps and chorusing atmospherics. These sounds can be quickly and easily constructed from familiar synthesis units like oscillators, delays, filters and envelopes.
The AudioKit is a cheap ESP32 based audio board that usually uses an ES8388 audio chip.
Quite some time ago I was working on a Mozzi integration for my AudioTools and had it usable. But because I needed to do quite some substantial changes to Mozzi, I pretty much halted this development, because I expected that a merge would not be accepted.
If you want to use Mozzi (or any other Audio Library which outputs audio via I2S to the ESP32) with the AudioKit you still have a pretty easy way to deal with this using my Audio Driver library directly.
So here are the steps that are necessary:
Select Your Board
There a quite of few different variants out there with different audio chips and different pin assignments, so follow the instructions that you can find in the README of the Audiokit project to select your board!
Mozzi Configuration for the ESP32
Make sure that Mozzi is using I2S with a DAC and the correct pins. This is done in AudioConfigESP32.h by using the following settings:
// Set output mode
#define ESP32_AUDIO_OUT_MODE PT8211_DAC
// For external I2S output, only: I2S_PINS
#define ESP32_I2S_BCK_PIN 27
#define ESP32_I2S_WS_PIN 25
#define ESP32_I2S_DATA_PIN 26
You can determine the relevant pins for your model by consulting this table.
Using the Codec
In the sketch you need to set up the audio chip of the AudioKit:
// setup of AudioKit codec
CodecConfig cfg;
cfg.input_device = ADC_INPUT_NONE;
cfg.output_device = DAC_OUTPUT_ALL;
cfg.i2s.bits = BIT_LENGTH_16BITS;
cfg.i2s.rate = RATE_32K;
AudioKitEs8388V1.begin(cfg); ```
The Complete Arduino Sketch
Here is the extended SineWave Sketch that works on an AudioKit or LyraT board:
#include <MozziGuts.h>
#include <Oscil.h> // oscillator template
#include <tables/sin2048_int8.h> // sine table for oscillator
#include "AudioBoard.h"
// use: Oscil <table_size, update_rate> oscilName (wavetable), look in .h file of table #included above
Oscil <SIN2048_NUM_CELLS, AUDIO_RATE> aSin(SIN2048_DATA);
// use #define for CONTROL_RATE, not a constant
#define CONTROL_RATE 64 // Hz, powers of 2 are most reliable
void setup(){
// setup codec
CodecConfig cfg;
cfg.input_device = ADC_INPUT_NONE;
cfg.output_device = DAC_OUTPUT_ALL;
cfg.i2s.bits = BIT_LENGTH_16BITS;
cfg.i2s.rate = RATE_32K;
AudioKitEs8388V1.begin(cfg);
startMozzi(CONTROL_RATE); // :)
aSin.setFreq(440); // set the frequency
}
void updateControl(){
// put changing controls in here
}
AudioOutput_t updateAudio(){
return MonoOutput::from8Bit(aSin.next()); // return an int signal centred around 0
}
void loop(){
audioHook(); // required here
}
3 Comments
Felix · 31. July 2024 at 12:14
Hej Phil!
Thanks for this very detailed description on how to use the Audiokit with Mozzi. At the beginning of June Mozzi version 2 has been released, which lead to many changes in the sturcture of mozzi as far as i can tell.
Do you plan on releasing another updated tutorial on how to make it work, or do you maybe have any hints what has to be done to make them play togehther again?
Best
Felix
pschatzmann · 31. July 2024 at 12:16
Just install the latest update and have a look at the examples provided in the examples directory
Felix · 31. July 2024 at 12:37
ok, i found it 🙂
thanks a lot!