ArduboyTones FX

Source        GitHub Source

I have hacked a copy of MLXXXp’s ArduboyTones library to work with the FX chip. You can now stream music and graphics from the FX chip simultaneously. I have included a sample program that shows how and includes streaming from the FX and from Ram as a comparison.

The approach is slightly different to the other tones() functions as it uses a circular buffer to hold the data to play. The buffer is replenished as part of the standard loop() processing, as shown below. This is primarily due to the fact that the FX and ArduboyPlaytunes would fight over interrupts.

The buffer size is configurable but my testing has shown that even the smallest buffer of eight bytes is enough. I guess if you have some really, really fast music and a really, really slow frame rate you could up it to a lavish length of sixteen!

#include 
#include <Arduboy2.h>
#include "src/ArduboyTonesFX.h"
#include <ArduboyFX.h>
#include "fxdata/fxdata.h"

Arduboy2 arduboy;
uint16_t buffer[8]; 
ArduboyTonesFX sound(arduboy.audio.enabled, buffer);

void loop() {

  if (!arduboy.nextFrame()) return; 
  arduboy.pollButtons();
  sound.fillBufferFromFX();

  ...

  sound.tonesFromFX(KickOutTheJams);

  ...