ArduboyTones FX

ArduboyRecording(5)

I have hacked a copy of @MLXXXp’s ArduboyTones 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.

It can be found here.

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 ArduboyTones would fight over interrupts.

The buffer size is configurable but my testing has shown that even the smallest buffer of 4 - 6 unit16_ts 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 16!

#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);
4 Likes

This is awesome news, more and more tools to use the FX capabilites!

These little distractions are preventing from creating my next game.

ArduboyPlaytunes next!

Nice! How many royalty free songs can we cram in one game system? :smiley:

Royalty free? Muzak??

I don’t have time to look at the internals, but I will point out that if you also add this constructor:

template<size_t size>
ArduboyTones(boolean (*enabled)(), uint16_t (&buffer)[size]) :
	ArduboyTones(enabled, buffer, size)
{
	static_assert(size < 256, "Buffer too large");
}

People can just do ArduboyTones sound { arduboy.audio.enabled, buffer }; and then not have to worry about providing the size manually.


Oddly enough, royalty-free music tends to be more electronic techno-beat/synth stuff.

It might not be Nintendo-tier, but some of it is better than Minecraft’s music (though that’s not saying much).

(‘Muzak’ is another one of those pesky genericised trademarks by the way.)

Because no one would pay for that crap?

After speaking with @mlxxxp, I might maintain this library in parallel to the official ArduboyTones library. I was thinking what I started with would be heavily altered to incorporate into the official library in a way that doesn’t add additional memory requirements or break anything.

Thus, these sorts of improvements are more than welcome.

1 Like

I’d agree, but I feel like I might be deeply offending someone somewhere. (Probably someone who lives in a very urban area and likes to go clubbing. Or Markus Persson.)

If you’re going to do that, perhaps it would be better to name it ArduboyTonesFX, ditch the conditional compilation and only retain the FX-relevant functionality?

After all, I doubt many people are likely to be storing their sounds both in progmem and on the FX.

That’s about all I have to offer at the moment, and I only really mention it because it’s a bit of a no-brainer (zero cost + ease of use + extra safety), but if I get chance to look in more detail and spot anything useful I’ll let you know.

Yes definitely a name change is in order so as not to confuse people (and the compiler).

That’s an interesting question. Its possible that you might want a theme to be playing from the FX but have small beeps and tones in memory or be generated randomly.

Please do.

1 Like

I would have thought BeepPin1/BeepPin2 would suffice for the former at least.

I suppose the real litmus tests would be:

  • How often is anyone likely to mix (complex) progmem and FX sounds?
  • If you dropped progmem support, could you reduce the memory footprint?

You could possibly do this from your proposed ArduboyPlaytunesFX library.

1 Like

I have updated the sample program to show streaming music and graphics from the FX card simultaneously.

New repo GitHub - filmote/ArduboyTonesFX