Offline
Newbie
Karma: 0
Posts: 21
// no comment
|
 |
« on: January 15, 2013, 10:33:36 pm » |
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/ToneLibraryDocumentationAccording 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!
|
|
|
|
|
Logged
|
|
|
|
|
Phoenix, Arizona USA
Offline
Faraday Member
Karma: 27
Posts: 5078
Where's the beer?
|
 |
« Reply #1 on: January 15, 2013, 11:45:10 pm » |
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?
|
|
|
|
|
Logged
|
|
|
|
|
UK
Offline
Tesla Member
Karma: 89
Posts: 6368
-
|
 |
« Reply #2 on: January 16, 2013, 07:25:01 am » |
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.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 21
// no comment
|
 |
« Reply #3 on: January 16, 2013, 11:13:00 am » |
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!
|
|
|
|
|
Logged
|
|
|
|
|
Dubai, UAE
Offline
Edison Member
Karma: 20
Posts: 1627
|
 |
« Reply #4 on: January 16, 2013, 12:52:15 pm » |
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 - Duane B rcarduino.blogspot.com
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 21
// no comment
|
 |
« Reply #5 on: January 17, 2013, 06:33:47 pm » |
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!
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Boston area, metrowest
Offline
Brattain Member
Karma: 242
Posts: 16507
Available for Design & Build services
|
 |
« Reply #6 on: January 17, 2013, 11:17:25 pm » |
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.pdfhttp://www.mouser.com/ds/2/389/CD00000480-103598.pdfSee 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.
|
|
|
|
|
Logged
|
|
|
|
|
Phoenix, Arizona USA
Offline
Faraday Member
Karma: 27
Posts: 5078
Where's the beer?
|
 |
« Reply #7 on: January 17, 2013, 11:27:39 pm » |
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
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 21
// no comment
|
 |
« Reply #8 on: January 21, 2013, 06:02:41 pm » |
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!
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Boston area, metrowest
Offline
Brattain Member
Karma: 242
Posts: 16507
Available for Design & Build services
|
 |
« Reply #9 on: January 21, 2013, 06:16:18 pm » |
|
|
|
|
|
Logged
|
|
|
|
|
|
|
Global Moderator
Boston area, metrowest
Offline
Brattain Member
Karma: 242
Posts: 16507
Available for Design & Build services
|
 |
« Reply #11 on: January 22, 2013, 10:05:31 pm » |
I don't know, I usually glaze over trying to read someone else's code.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 21
// no comment
|
 |
« Reply #12 on: January 22, 2013, 10:37:26 pm » |
LOL  Can anyone else help me out here?
|
|
|
|
|
Logged
|
|
|
|
|
Dubai, UAE
Offline
Edison Member
Karma: 20
Posts: 1627
|
 |
« Reply #13 on: January 23, 2013, 12:18:45 am » |
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
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 21
// no comment
|
 |
« Reply #14 on: January 23, 2013, 12:18:58 pm » |
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?
|
|
|
|
|
Logged
|
|
|
|
|
|