Loading...
Pages: 1 2 3 [4]   Go Down
Author Topic: toneAC v1.2 - Twice the volume, higher quality, higher frequency, etc.  (Read 5150 times)
0 Members and 1 Guest are viewing this topic.
Toledo, OH
Offline Offline
Sr. Member
****
Karma: 16
Posts: 410
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Library toneAC version 1.2 tested with Uno, Leonardo, Mega 2560, ATmega8 16MHz. Everything is okay.
Library toneAC version 1.2 with option TONEAC_TINY tested with ATmega8 16MHz. Also okay, 140 bytes smaller.

The TONEAC_TINY version has implications for the source code.
If I would use toneAC(1000,5); and switch to TONEAC_TINY, I must change that line. That is not obvious, since it is the same function "toneAC".
The second parameter changes from volume to duration.
Adding a second parameter (an unused volume byte) changes the size saving from 140 to 106.
I don't know what to think of it.

It was an oversight not changing the function name for TONEAC_TINY.  I now changed the function name to toneAC_tiny() when using the TINY code.

Adding the volume in for TINY code makes the TINY savings only 52 bytes on my 1.0.3 compile on Uno.  If it's only 52 bytes of savings I should probably just remove the TINY code totally.

What about a ToneAC page in the Playground section ?

That's the plan, just haven't got to it yet.

Tim
« Last Edit: January 31, 2013, 12:54:19 pm by teckel » Logged

Arduino Uno - Teensy 2.0 - Teensy 3.0 - Raspberry Pi Model B w/512MB RAM
My libraries: NewPing library - LCDBitmap library - toneAC library - NewTone library

Cebu City
Offline Offline
Newbie
*
Karma: 0
Posts: 34
Hi im new to arduino!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi. Can you add ADSR with your library sir? smiley

http://en.flossmanuals.net/pure-data/audio-tutorials/envelope-generator/
Logged

Toledo, OH
Offline Offline
Sr. Member
****
Karma: 16
Posts: 410
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


Can't be done with toneAC as the ATmega controls all the switching.  In order to do ADSR (Attack-Decay-Sustain-Release) we should first create a sine wave instead of a square wave.  To do a sine wave, we need to interrupt the ATmega's PWM switching and adjust the duty, this takes valuable CPU cycles.  Further, to do ADSR we would need to also adjust the amplitude while the note is being played, further using limited CPU cycles.

All of this "could" be done on the ATmega.  But, I'm not sure what the frequency range would be.  It would also be well outside the scope of the toneAC library as it would be quite large, slow (CPU intense), and limit the frequency range by a huge amount.

Further, to really do ADSR correctly, it would need to be able to output the release phase of the previous note as the current note was starting the attack phase.  This really disqualifies the ATmega as an option.

You'd probably need a more powerful processor and one designed to output audio to really do what you're looking for effectively with any amount of fidelity.

Tim
Logged

Arduino Uno - Teensy 2.0 - Teensy 3.0 - Raspberry Pi Model B w/512MB RAM
My libraries: NewPing library - LCDBitmap library - toneAC library - NewTone library

Toledo, OH
Offline Offline
Sr. Member
****
Karma: 16
Posts: 410
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

What about a ToneAC page in the Playground section ?

toneAC in the playground:

http://playground.arduino.cc/Code/ToneAC

Tim
Logged

Arduino Uno - Teensy 2.0 - Teensy 3.0 - Raspberry Pi Model B w/512MB RAM
My libraries: NewPing library - LCDBitmap library - toneAC library - NewTone library

Des Moines, Iowa, USA
Offline Offline
Newbie
*
Karma: 0
Posts: 27
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I don't have the code handy - but waaaay back when I was kid, I remember playing around on my TRS-80 Color Computer with the PLAY command; there was a way, via using certain values (I think random notes played with very, very short durations) with a rapidly decreasing volume level (the CoCo had a 6 bit DAC - so there were 64 volume levels) - you could make an "explosion" or "gun" sound of sort...

Nice to see a CoCo reference here... I recently ported a 1983 Extended Color BASIC program I wrote on the CoCo over to Arduino C (line by line, as literally as possible) and I put in a placeholder for the CoCo's SOUND command. It only took tone and duration, though. There was no built in provision to do noise or volume.

But the Extended Basic PLAY command did allow volume and some great tricks could be done with it. I have been working on a PLAY command, and finding this thread is helpful as it sounds like it would be better to use than what I was working on.
Logged

Embedded Software Engineer
UNO | Leonardo | Due | Teensy | BASIC Stamp
http://www.subethasoftware.com

Pages: 1 2 3 [4]   Go Up
Print
 
Jump to: