Arduboy Audio Library

I am looking at the arduboy code and there is not very much code on the audio front. I think my plan is to create an Audio Library for it over the next few weeks and am looking for suggestions.

My goal is to have it monotonic using the tone function to generate sounds. There will also be an override function which will stop the background music to play an audio effect and resume background music once played and a mute option. The functions will include the following:

  • playSong(int length, byte[] array); // Plays a music loop.
  • playEffect(int length, byte[] array); // One time short effect
  • mute();
  • unmute();
  • setTempo(int speed); // Changes The Speed

All music will be in the following format

2 bytes Representing Frequency
6bits duration - 1 = 16th Note, 2 = 8th Note, 4 = Quarter Note, 8= 1/2 Note Etc.
the other 2 bits will represent Note style.
2bits note seperation

  • 00 = Staccato
  • 01 = Normal
  • 10 = Tenuto
  • 11 = Slur
1 Like

Has the circuit for for how the piezo speaker is wired to the CPU been released, or has someone reverse engineered it from a dev unit (I don’t have one myself)? I think this is something you would need to know in order to create an audio library.

It would be interesting to know what is meant by the 2 Channel Piezo Speaker specification given on the Kickstarter campaign page. All I can tell from the ArduBreakout code is that the speaker is, at least, wired to pin A2. But, if it has 2 channels then there must be more to it, unless the “channels” are implemented solely through software.

I didn’t realize that there was a 2 channel piezo attached. I will have to try stuff on my dev kit.

I was able to produce sound from pins A2, and A3 on the Arduboy individually however I was unable to produce chords. I have done some quick research and think it has something to do with the code wanting to use the same timer. Polyphonic sounds may be possible but I believe the arduino tone function will need a rewrite.

I was talking to @bateske on IRC earlier and he said that they already have a sound library written. They hacked a library called PlayTune (or was it PlayTone?) to support 2 channels. I was hoping they would release it for us, now that some people have dev kits. :slight_smile:

Thanks I have been playing at different methods for generating polytonics sounds with no avail. I may have to wait a bit to get it then.

It appears that there is a separate tone library available, that the built-in Arduino tone library was based on. Unlike the built-in library, this one can play multiple tones simultaneously, based on the number of timers available in the CPU. Here’s the library info:
https://code.google.com/p/rogue-code/wiki/ToneLibraryDocumentation

For multi-tone info, look in the Ugly Details section:
https://code.google.com/p/rogue-code/wiki/ToneLibraryDocumentation#Ugly_Details

2 Likes