-
Notifications
You must be signed in to change notification settings - Fork 190
How to use Mozzi
sensorium edited this page Jun 12, 2012
·
1 revision
// This includes Mozzi's core functions, which are the small set in this sketch
#include <MozziGuts.h>
// CONTROL_RATE is #defined rather than being a constant, because Oscils (Mozzi oscillators) run
// faster in tests when initialised with a literal value rather than a constant. Maybe something
// to do with the compiler optimising for size rather than speed? It's a power of two (minimum 64)
// because of the way Oscils have been coded for speed.
#define CONTROL_RATE 64 // or some other power of 2
void setup() {
// This starts the timers for audio and control interrupts. Audio is fixed at 16384 Hz.
StartMozzi(CONTROL_RATE);
}
void loop() {
// This fills the audio buffer. Don't need to do anything special here.
audioHook();
}
// You need both of the following functions or your sketch won't compile.
int updateAudio() {
// Your audio code which returns an int between -244 and 243.
// Actually, a char is fine.
// This is called 16384 times a second, so the code here needs to be efficient!
}
void updateControl() {
// Your control code. Do as much as you can here, rather than in updateAudio().
}