Playing simultaneous tones?

Hello-

I am working on a song with multiple buzzers and I’ve downloaded a library that allows me to play two simultaneous tones:

https://code.google.com/p/rogue-code/wiki/ToneLibraryDocumentation

According to their manual, my Uno r3 should be able to play 3 simultaneous tones, since it has an ATmega328 chip, with three internal timers. My friend told me that one of these timers is a system timer, and it cannot be used for anything except for system processes. Is there any way around this while (preferably) still using the above mentioned library?

I already know of a couple libraries in which I can play several simultaneous tones by “hacking” one of the internal timers:

and

However, both of these seem especially confusing, and I’d rather know what I’m working with before using it. I would also be OK if someone told me how to use these libraries, and what are the different things I can do with it.

Thanks!

I can't really tell whether these guy's are using multiple speakers on different pins or what - are they? If so, why?

Why not a single speaker, and a simple audio mixer?

The timer interrupt approach described in 'driving-5-speakers-simultaneously-with-an-arduino' seems to be what you need.

If tone generation was all you wanted the sketch to do, and you don't need to generate very high frequencies, you might even be able to manage it just by polling micros() to check when it was time to toggle each output. This would use more processing power and not cope with as many outputs/as high frequencies as the interrupt based approach, but would be much easier to understand and get working. Essentially you'd use 'blink without delay' but using micros() instead of millis() to measure really short intervals.

cr0sh: I can't really tell whether these guy's are using multiple speakers on different pins or what - are they? If so, why?

Why not a single speaker, and a simple audio mixer?

I am using three different speakers on three different pins. What's an audio mixer? (Sorry, I'm new)

If tone generation was all you wanted the sketch to do, and you don't need to generate very high frequencies, you might even be able to manage it just by polling micros() to check when it was time to toggle each output. This would use more processing power and not cope with as many outputs/as high frequencies as the interrupt based approach, but would be much easier to understand and get working. Essentially you'd use 'blink without delay' but using micros() instead of millis() to measure really short intervals.

This did seem like a viable solution, but the problem is that I can't understand a word of what he is saying. None of the variables are defined (I assume they are some sort of system variables), and he uses a bunch of bitwise operations that I don't understand. For using the micros() technique, how would I know which frequencies to play? I use notes in a range of an octave or two, so that might also be a factor.

As for tone generation being ALL I wanted to do, I was thinking of adding in some synchronized lights while the song was playing (if that's possible)

Thank you!

Why dont you just try the illutron synth ? You could output four voices/notes at a time through a single pin or two voices through two pins. The project will play a sequence which you can set by writting the midi note numbers into a file in the sketch.

It does lights as well - http://www.youtube.com/watch?v=fTmLKKLv5cE

Duane B rcarduino.blogspot.com

I actually DID see the illutron synth thing, but I actually wanted to "do it myself", if using other people's libraries didn't count. Feeding the notes into another program didn't seem like much fun on my part.

Thanks for your input anyway!

Does it have to be a library? Or can you control NE555, NE556 chips that are setup as astable oscillators? http://www.mouser.com/ds/2/389/CD00000479-103226.pdf http://www.mouser.com/ds/2/389/CD00000480-103598.pdf See figure 16 as one way to set it up - trigger a tone for a length of time. Or replace the output of the first with the arduino output. Set up as many oscillators as you want, use shift register outputs to control them. Take all the tone outputs, run into a op-amp summing amplifier. See NE555 Figure 15, use either waveform for different sounds.

wherewolfe: I am using three different speakers on three different pins. What's an audio mixer? (Sorry, I'm new)

Basically - it's a fairly simple circuit that allows you to combine multiple signals into a single signal - here's an article (you can find more on the net - just search for "audio mixer schematic"):

http://sound.westhost.com/articles/audio-mixing.htm

Hello (sorry for the late response) :

I had considered using 556 timers, but it seemed a bit pricey, considering how my local electronics store prices each one at around $1.50, and I want to play a range of notes. The cheapest audio mixer also costs $30. This is out of my budget, and, in fact, I was actually looking for more of a software based approach. I think the most helpful feedback I could get right now would be if someone could explain the code in: http://www.jeremyblum.com/2010/09/05/driving-5-speakers-simultaneously-with-an-arduino/

If someone could explain what this does, how it works , and how I could use it, it would be really REALLY helpful.

Thanks!

You can get DIP parts for 45 cents http://www.mouser.com/ProductDetail/Texas-Instruments/NE556N/?qs=sGAEpiMZZMuHTYi1bHPYEC2zhCiQJdMm and surface mount for 23 cents http://www.mouser.com/ProductDetail/STMicroelectronics/NE556DT/?qs=sGAEpiMZZMtf0BNRzfLjAhLt9HcSj294

So $5 for 10 chips and some Rs & Cs and you have 20 'channels'

You don't need a $30 mixer - use an op-amp to make a summing amplifier to create the mixer. http://masteringelectronicsdesign.com/how-to-derive-the-summing-amplifier-transfer-function/

Run that output into a power ampllifier to boost the sound level.

Thank you- I will buy these shortly.

I still am curious - what exactly IS jeremy blum doing in http://www.jeremyblum.com/2010/09/05/driving-5-speakers-simultaneously-with-an-arduino/ Even though I probably won't need to ever use it, I still am interested in what his code would be doing, and how someone could use his code.

I don't know, I usually glaze over trying to read someone else's code.

LOL :stuck_out_tongue_closed_eyes: Can anyone else help me out here?

Hi, Its well explained in the link -

timer interrupt triggers every 64us and looks at a counter for each speaker to determine whether it needs to toggle the pin driving the speaker. Thats it.

Its very similar to the way the servo library allows you to drive 16 servos from a single timer - In fact I can't see why you could not drive 8 or more speakers, the code could easily be optimised using direct port manipulation to squeeze out some more perfomance.

Duane B

rcarduino.blogspot.com

Thanks, DuaneB.

So if I were going to play more notes than the frequencies he has created, I would just add more count and toggle variables, and then add more if statements accordingly?

never mind, I get it now.

What about http://sealedabstract.com/code/bassdll-an-arduino-piezo-music-library/? What does this one do, and how would I use it? (sorry for prolonging this thread, I just want to learn as much as I can)

Playing simultaneous tones?

Use the hardware pwm modules or even with timer isrs if the frequencies aren't too high.

There are basically two ways to generate sound from the Arduino -

1) using the timers to generate squarewaves

2) using DDS to generate waveforms which may include square, triangle, sine, noise and many others.

DDS has the advantage that you can easily add envelopes to create a more interesting sound, you can also add more channels or mix multiple channels into fewer channels etc. Then you can get into waveshapers, digital filters, wavefolding etc etc etc.

Peizo projects will tend to be based on 1) the output volume is not controlled by software, only the frequency, a lot like just using the tone library.

With the timer based methods you can fake envelopes to a degree by dropping the fequency rapidly which creates and effect similar to a note tailing off as it decays for a more interesting sound.

Duane B

rcarduino.blogspot.com

I assume bassDLL uses DDS, judging from your description. How would I use it?

I am not sure that it does, but if you want to I can only point you to the same Illutron B project that I have suggested in the past. The post includes a nice external link to a DDS introduction which generates a sinewave, the post itself then goes into more detail on creating musical sound.

If you pm me your email address i can send you the code.

I know that in the past you have concluded that its too complicated, it isnt really I have extensivley commented the code and if you want to take the next step to better sound its as good a step as any.

Duane B