[WIP] 4 channel Music

The current standard V1.1 Arduboy library’s audio class doesn’t change the speaker pin modes. This was something added in the develop branch and which my Arduboy2 library inherited.

Besides, this was something that was added as a “safety” in the hopes that it would work for non-Arduboy-compliant libraries. There’s still a chance that it won’t work if whatever code generates the sound sets the pins back to outputs.

It’s expected that an Arduboy compliant sound library will initialise and control the speaker pin modes itself and that it will honour the current mute state using audio.enabled().

The bottom line is that although ATMlib works with the current Arduboy library V1.1 (I tried it), it doesn’t handle the standardised audio class muting in this case.

Ok thanks for clearing that out. I’ll look into this and come with a solution. I would prefer that the “main” library is able to set the pins and change their state, because … well those pins will always be the same pins. Maybe this is something we can look into together. BUT before all that, let me do some tests this week.

It’s only when all these small things are solved too, I’ll make a bigger announcement about the library.

But it’s the sound library that actually modulates the pins, so it has to know which ones they are, anyway. On that note, you should be using the defines PIN_SPEAKER_1 and/or PIN_SPEAKER_2 in your library rather than just hard coding them.

The reason that the sound library should be responsible for setting up and controlling the speaker pin modes is because the “main” library may not know how to, for a particular sound library.

For instance, with the current Arduboy hardware it’s possible to set one pin as an output and the other as an “input with pullup” (mode INPUT_PULLUP). If you then toggle only the output pin, the speaker is coupled to the input pin through the built in pullup resistor. This results in a lower volume. I’ve talked about this here. A particular sound library could take advantage of this. However, if the “main” library changes the pin modes each time it changes the mute state, this could screw up this “non-standard” pin configuration that the sound library has set.

I’ve proposed that the next generation Arduboy be based on the Arduino Zero (and I’ve seen hints that it may be). This will mean that there will probably be a true hardware DAC available for sound. Some sound libraries may use this. Others may just toggle the pin digitally as they do now. Again, you don’t want the “main” library messing with the pin configuration that the sound library has set up.

For the above reasons, I’m really tempted to change the Arduboy2 library so that it never touches the speaker pins (or at most just sets them both to outputs once, during boot). Required pin settings would be the sole responsibility of the sound library. The “main” library’s audio class would only logically maintain the global mute state, with no sound hardware control whatsoever. In the future, it’s possible that the audio class could maintain a global volume level, in addition to the mute state, but this would still only provide a volume level value to the sound library, and the sound library would control the hardware to provide this volume, within it’s capabilities.

If I were to make this change to the Arduboy2 library, the ArduboyTones and ArduboyPlaytune libraries would still work fine because they both set the speaker pin modes themselves and use a callback to audio.enabled() to handle global muting themselves, as they see fit.

Ok … Just tested one our games (using ARGlib) that uses the audio.enabled(), arduboy.audio.on() and arduboy.audio.off()
I added a song to the game and included ATMlib … nothing more

and … it just works out of the box, like I thought. The music is completely muted when I select sound Off in our menu.

1 Like

That’s with Arglib and Arduboy2. Did you try it with the Arduboy library?

huh … to be honest I never used the Arduboy Library, but ARGlib was based on it and the only thing I changed was ditching … tunes

It looks like pin control was added to the Arduboy library in March 2016 but only for the development code. Either Arglib is based on a development version or the changes were ported over.

However, as I said above, I’m highly inclined to remove the speaker pin control code from Aruduboy2 so as not to interfere with how some future sound libraries may need to set the pins. I don’t think it should be the responsibility of the main library to control the sound hardware.


was wondering if there is a working Web Editor already ready.
And if a Zelda “song.h” is available somewhere?


1 Like

hi @derchris,

We don’t have a web editor yet … working hard to get something, but with the Holidays coming …

We do have all the examples songs AND we have a WEB PLAYER. You can download this for now (I will add it to our website later) just put the folder somewhere and open the index.html in the Chrome Browser. Now you can just drop a song.h file on it and it will start to play (good for testing)

PS: The Zelda tune playing on an arduboy was made for the OLD SQUAWK Library (witch no longer works …)

1 Like

Hi @JO3RI,

thanks for the quick response.
Yes, I actually tried to flash the demoScene3_AB.ino onto my Arduboy, and it was throwing error after error.
Would it be difficult to port the Melody/Aquawk into the current ATM format?
And how much different is the ATM format from lets say Midi.
Would there be a chance to put together a Midi to ATM converter?


ATM uses a whole now song format/structure, which is needed to get very small songs (we don’t have much room in the Arduboy). SQUAWK is based on the old MOD songs (amiga), which takes A LOT of space. Converting MOD to ATM is almost impossible.

Now, converting 1 midi line into something usable for ATM should be doable (we only need note and duration), but again … Time is not on my side. (If you want to create one, I can help you with the song format)

I’m working on a new Demo “Christmas”, which I will release this week. To create the song I just looked at a midi song and “wrote/coded” the song in ATM format.

PS: if you just wanted to play the demo, I’ll make a working .hex file soon. You can upload those files with our GameLoader for Arduboy

A Midi converter sounds like a good idea then.
Maybe I can have a look at it.
But it will most likely be in Python, not so good with any decent desktop language.
A hex of the demo would be nice, just to check it out.

For a MIDI to ATM converter, adding another output format to midi2tones may be a good way convert MIDI to at least a subset of ATM format. midi2tones currently can convert to ArduboyPlaytune and ArduboyTones formats.

I’ve considered doing this, but alas, like @JO3RI my time is not available at the moment to do this. Anyone is welcome to attempt it. I could probably provide some assistance by answering questions.

A specification for exactly how to map MIDI to ATM would need to be created.

An new Update on the 4 channel Tracker editor. Basics are working, you can create drum tracks, add them in the song. You can also create tune tracks and add them into the song. You can export the song as code and even a file song.h you can use in your game with ATMlb OR just drag and drop on the ATMwebplayer: https://teamarg.github.io/ATMwebplayer/

FX have not been implemented yet, which is very needed for chip-tune songs. And the Editor isn’t publicly available yet.

Here you see the editor with the Tune Editor active.

Here you see the editor with the Drum Editor active


Wow you’ve been working on this for a really long time! Amazing to see it!

Yes and we finally have an online version you can Beta test. No Sound effects are implemented yet, so actually it doesn’t really show off what it can do, but it’s a start.

ATM Track Editor http://teamarg.github.io/trackerEditor/

if you export your song, you can play it by dropping the file on the ATM web player: https://teamarg.github.io/ATMwebplayer/

Sorry … no manual yet, let us work on the editor to complete it first :slight_smile:


Great work so far :slight_smile: can’t wait until it’s fully usable!

1 Like

Sorry for thr double post, but are there any secret behinf the scenes converters someone could borrow if they needed to add some realy nice music to their almost finished game?

Am I the only person having trouble getting this to work? I can play an example song on my arduboy, but nothing that I create myself will play.

You’re probably the only one using it so far, other than Team A.R.G. :wink: