tone() - multiple instances for polyphony


I am very excited to see the addition of tone() to the regular Arduino release. I was experiencing compiler errors when I used the servo() and tone() libraries together in the previous version (0017). This new version seems to have fixed the problems I was experiencing before.

However, I have a new problem. The new implementation of tone() does not allow you to create multiple instances (new objects) to have more than one tone playing at a time. Perhaps the previous object-based implementation could be re-introduced in the next version.

I hope this is an easy fix/addition because as it is now I will have to use a separate Arduino board for each audio channel I want which is, of course, very costly.

Somebody should build an Arduino-based soundboard shield; write custom firmware that could listen via I2C or SPI for commands, then output an FM sound-synthesis via an 8-10 bit DAC; if you did it right, you could do two 8-bit sound channels into a simple resistor ladder DAC, and still have enough pins left over for the serial comm channel.

This really wouldn’t be that expensive to do; a few dollars for the ATMega328, and pennies for the other components - if you used a shield protoboard for development, you could probably do the whole thing for under $25.00. If you used perfboard and jumper wires, doing it under $10.00 is feasible. The difficult part, as always, would be the coding…but certainly doable.

Even though the basic tone() functionality is available in the new 0018 version, you can still use the fully functional Tone library to produce multiple tones.

Go here:

Get the library from there, install it to your *SKETCHBOOK*/libraries folder, start the Arduino IDE and you're good to go.


The problem is that when I use the servo and tone libraries together, I get compiler errors (I am running Arduino 0018 on WinXP).

If I “verify” this script in Arduino:

#include <Servo.h> 
#include <Tone.h>

void setup(){}

void loop(){}

I get the following errors:

[path to library]\Tone\Tone.cpp.o: In function __vector_11':* *[path to library]\Tone\Tone.cpp:438: multiple definition of __vector_11’
[path to library]\Servo\Servo.cpp.o:[path to library]\Servo\Servo.cpp:103: first defined here

and p.s. cr0sh, I think the synth shield is a great idea!

Ooops. Didn't know you were using the Servo library. Unfortunately, there's no real easy solution to using both libraries at the same time.


No problem. I was actually developing both parts of my project separately -- servo and tone in different scripts. I didn't realize there was a conflict between tone and servo until I merged the two scripts together -- big bummer.

I am hoping that it will be possible (easy/whatever) for the implementation to be object based in the next version. That way you create a new tone object for each sound channel you need.

Fingers crossed.

p.s. cr0sh, I think the synth shield is a great idea!

I'm full of free ideas; my problem isn't knowledge or money (ok, for some of my ideas, money is the problem) - it's time and other projects that have to come first before I die (not dying anytime soon that I know of - I just have so many damn projects lined up already!).


Yeah - I would love to see a synth shield; it wouldn't be very hard at all to create - like I said, the details are in the coding, but even there it should take much; a few small LUTs for the waveforms (sine, triangle, square), a noise generator (somebody already posted one of those for some Arduino game someone posted on these forums), ASDR envelope programming and control, mixing (or you could do external analog mixing), etc.

This idea is really just a segment of an idea I had to take various parts of things I've seen and build a "gameduino" type system; using multiple ATMega328s tied together via SPI, one of the 128x64 GLCD displays, and an SD card hung off the SPI, you could build one kickin' handheld system (once you hacked the bootloader to download hex files from the SD card).

Unfortunately, I am building my UGV right now - so I leave it for someone else to do (unless I get there first - I can justify it as a hand-held user interface for my UGV...?).


I just realized that I posted this thread to the wrong section. It really should be posted in the "software" section. I will re-post it there.