Go Down

Topic: Playing simultaneous tones? (Read 3842 times) previous topic - next topic

wherewolfe

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:

http://www.jeremyblum.com/2010/09/05/driving-5-speakers-simultaneously-with-an-arduino/

and

http://sealedabstract.com/code/bassdll-an-arduino-piezo-music-library/

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!

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 will not respond to Arduino help PM's from random forum users; if you have such a question, start a new topic thread.

PeterH

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.
I only provide help via the forum - please do not contact me for private consultancy.

wherewolfe


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)

Quote
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!

DuaneB

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
Read this
http://rcarduino.blogspot.com/2012/04/servo-problems-with-arduino-part-1.html
then watch this
http://rcarduino.blogspot.com/2012/04/servo-problems-part-2-demonstration.html

Rcarduino.blogspot.com

wherewolfe

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!

CrossRoads

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.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

cr0sh


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
I will not respond to Arduino help PM's from random forum users; if you have such a question, start a new topic thread.

wherewolfe

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!

CrossRoads

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.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

wherewolfe

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.

CrossRoads

I don't know, I usually glaze over trying to read someone else's code.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

wherewolfe

LOL  :smiley-yell: Can anyone else help me out here?

DuaneB

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
Read this
http://rcarduino.blogspot.com/2012/04/servo-problems-with-arduino-part-1.html
then watch this
http://rcarduino.blogspot.com/2012/04/servo-problems-part-2-demonstration.html

Rcarduino.blogspot.com

wherewolfe

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?

Go Up