Pages: [1]   Go Down
Author Topic: Piano sounds frequencies and tone function questions  (Read 1058 times)
0 Members and 1 Guest are viewing this topic.
Belgium
Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

I'm new to Arduino and I've been playing around with sound.
I just found this site http://jarv.org/files/midi-avr/arduino_all_piano_tones.html
It has a table for all the piano note frequencies. Now I see that those frequencies have a decimal.
example : C8 (Eighth octave) = 4186.01
But the tone() function only accepts an unsigned int as the frequency parameter.
Could I just drop the decimals and use the rounded values? Will this still sound good?

I've read ton's more about generation audio with an Arduino, including wavetable synthesis combined with envelopes, but for now I've realised that that way of generating sound is too complicated for me. So I'll settle with the tone() function and the Tone library that allows playing 2 tones at the same time...

Also if one presses a piano key, the sound it produces will fade out over time instead of abruptly stopping.
Is this possible to simulate this with the tone() function? Or does that require wavetable synthesis too?
Or could I maybe achieve some effect like this with a circuit at the output useing 555 timers/capacitators/whatever... ?
 
Thanks for reading & kind regards,
Memorex
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 441
Posts: 23834
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, drop the decimal point, doubt you will hear any difference.

Envelope - use same key press that start the tone generation to have a 555 create an envelope.
Use the envelope to control a Voltage Controlled Amplifier
http://www.analog.com/en/specialty-amplifiers/variable-gain-amplifiers/ssm2164/products/product.html
I don't know if this one is still purchasable.

This one seems to be in production still
http://www.analog.com/en/all-operational-amplifiers-op-amps/operational-amplifiers-op-amps/ssm2018/products/product.html

You can search for same from other sources as well - linear.com, maxim-ic.com, microchip.com for example

The envelope ideally will have an Attack period where the volume ramps up, a Decay period where it holds the level, a Release period where it drops off, a Sustain period where it fades out, and then a Release period where it finally stops.  You will see this referred to as ADSR.
This circuit might do it for you.  Scroll around, interesting stuff
http://www.uni-bonn.de/~uzs159/adsr.html
http://www.uni-bonn.de/~uzs159/vcadsr.html
http://www.uni-bonn.de/~uzs159/vca.html

When I was in college in early 80's, we could buy chips where the 4 periods could be set up with potentiometers, and used to feed voltage controlled amplifiers to control the envelope of a sound waveform.  Maybe static hiss for a snare drum, lower frequency for a bass drum, etc..

This one seems recent, a microcontroller programmed for ADSR:
http://www.electricdruid.net/datasheets/VCADSR7Datasheet.pdf
http://www.electricdruid.net/index.php?page=projects.envgen7

Chips for sale:
http://www.electricdruid.net/index.php?page=projects.chips
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 170
Posts: 12480
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
It has a table for all the piano note frequencies. Now I see that those frequencies have a decimal.
example : C8 (Eighth octave) = 4186.01

You only need the highest octave in the table

C8 = 4186  => C7 = C8/2    C6 = C8/4   C5 = C*/8 etc

so if you know the tone and octave you can calculate the freq very fast  // assume tone = 0..11 mapping C..B#
The table must be of the type int.

freq = table[tone] >> (8-octave);  // 1 bit shifted is division by 2 .






Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Vienna (Austria - Europe)
Offline Offline
Jr. Member
**
Karma: 0
Posts: 56
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@crossroads: there is an inexpensive substitute for the ssm2164: V2164 (coolaudio)
http://www.mammothelectronics.com/Coolaudio-V2164D-Quad-Voltage-Controlled-Amplifier-p/400-1034.htm
i think, this is the only affordable vca chip at the moment...
otherwise: build it yourself smiley http://hem.bredband.net/bersyn/VCA/vca_shootout.htm

@memorex: //555 timer
i´ve played around with this two (basic!) schematics:
555 timer as vco: http://tymkrs.tumblr.com/post/4496507556/19-fm-vco-555timer-i-ham-lesson-o-de-day
getting cv-voltage with pwm: http://i50.tinypic.com/29ffjoo.png
please note, that using other opamps (like tl072,...) than the lm358 in the cv results in strange behaviors
I try to realize just a VCA using digital potentiometers.

Some fundamental resources for adsr envelopes and coding them in C(++): http://hackmeopen.com/2011/12/synth-diy-software-for-generating-adsr-envelopes/
regards
matthias
« Last Edit: January 17, 2013, 06:17:40 pm by madias » Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 441
Posts: 23834
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

"there is an inexpensive substitute for the ssm2164: V2164 (coolaudio)
http://www.mammothelectronics.com/Coolaudio-V2164D-Quad-Voltage-Controlled-Amplifier-p/400-1034.htm"

Is there a datasheet available? Pinout? I'm not seeing one on the page.

Ah - here we go
http://www.coolaudio.com/products.html
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Offline Offline
Edison Member
*
Karma: 9
Posts: 1010
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

At this moment the toneAC library is being developed.
You need version 1.2 (will be ready soon).
http://arduino.cc/forum/index.php/topic,142097.msg1066968.html#msg1066968
The toneAC library is very small and fast and can control the volume.
So some kind of fade out is possible. But with digital pulsed sound, also the sound changes.
But if you make a fast fade out, it's not a big problem.
It is ment to drive a loudspeaker with two pins of the Arduino, it is not a signal for an amplifier.

Another option is the Mozzi library.
http://sensorium.github.com/Mozzi/
The Mozzi library is very big, and can create awesome sounds.
Logged

Pages: [1]   Go Up
Jump to: