Lab Session – 31/01/22 –

In this session, we discussed our previous blog posts and revised the content from last week. We were then set on the task of finding a few audio libraries for Arduino and below is the research I found.

DFPlayerMini: included within the IDE software libraries page and is a reliable, responsive driver for DFPlayer Mini sound module for Arduino, and functions with SD card readers you can buy from DF and third parties.

ESP8266Audio: Arduino library for parsing and decoding MOD, WAV, MP3, FLAC, MIDI, AAC, and RTTL files and playing them on an I2S DAC

MD_YM2413: the YM2413 can only play one user-defined instrument at a time, with an additional 15 read-only hard-coded instrument profiles available

Mozzi: Expands on the current beeps that the Arduino is capable of, implementing much more complex sounds to be available for playback. You can use Mozzi to generate algorithmic music for an installation or performance.

Musician: This library implements a virtual musician. You can easily ask him to play a melody, based on the MELO music notation from the Melody Library.

Teensy: Audio Library is a toolkit for building streaming audio projects, featuring Polyphonic Playback, Recording, Synthesis, Analysis, Effects, Filtering, Mixing, Multiple Simultaneous Inputs & Outputs, and Flexible Internal Signal Routing.

#include <MozziGuts.h>
#include <Oscil.h>
#include <tables/sin2048_int8.h>

#define CONTROL_RATE 128
Oscil <2048, AUDIO_RATE> aSin(SIN2048_DATA);
Oscil <2048, CONTROL_RATE> kVib(SIN2048_DATA);

float centre_freq = 440.0;
float depth = 0.25;

void setup(){
	kVib.setFreq(6.5f);
	startMozzi(CONTROL_RATE);
}

void updateControl(){
	float vibrato = depth * kVib.next();
	aSin.setFreq(centre_freq+vibrato);
}

int updateAudio(){
	return aSin.next();
}

void loop(){
	audioHook();
}

So to summarise this Mozzi library tutorial, any Mozzi classes/modules or tables need to be called using the #include <_____>, for example : #include <MozziGuts.h> is the main library, whilst #include <Oscil.h> is used to call the oscillator. #include <tables/sin2048_int8.h> is the Wavetable that corresponds to the sinewave we are using in the example.

Next, we create an instance for the oscillator using Oscil to which we will then alter.

Oscil <table_size, update_rate> name(table_data);

So we input our values into the format above to create something that looks like this below. Note that the table size value typically needs to be a power of two for compatibility. The oscillator uses an audio generator

Oscil <2048, AUDIO_RATE> aSin(SIN2048_DATA);

Leave a Reply

Your email address will not be published. Required fields are marked *