electro-music.com   Dedicated to experimental electro-acoustic
and electronic music
 
    Front Page  |  Radio
 |  Media  |  Forum  |  Wiki  |  Links
Forum with support of Syndicator RSS
 FAQFAQ   CalendarCalendar   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   LinksLinks
 RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in  Chat RoomChat Room 
 Forum index » DIY Hardware and Software » Microcontrollers and Programmable Logic
correct way to calculate octave shift?
Post new topic   Reply to topic Moderators: State Machine
Page 1 of 1 [7 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Author Message
rhdf



Joined: Jul 11, 2014
Posts: 39
Location: Sweden

PostPosted: Tue Apr 04, 2017 1:50 pm    Post subject: correct way to calculate octave shift? Reply with quote  Mark this post and the followings unread

I have a array with the frequencies for "all" midinotes.
To get the correct pitch I simply use f=notetable[midinote]. But if I want to shift one octave up/down? Just add/subtract 12 to/from midinote? (and check that I dont end upp below 0 or over 127)

I've seen examples where f is multiplied with 2 for one octave up.
that would work fine for A where A4=440.00 A5=880.00 etc. But for C where C4 =261.63 C5=523.25 you end up slightly out of tune

witch metod is recomended

(Later I will add control for +semitune and detune/fine-tune.)
Back to top
View user's profile Send private message
blue hell
Site Admin


Joined: Apr 03, 2004
Posts: 24079
Location: The Netherlands, Enschede
Audio files: 278
G2 patch files: 320

PostPosted: Tue Apr 04, 2017 2:15 pm    Post subject: Reply with quote  Mark this post and the followings unread

Should not matter .. one octave by definition is a factor of two in frequency .. and also by definition 12 semitones up or down.

The frequency values are rounded values, on those things may seem off, but the internal representation has more digits .. except for A being tuned to exactly 440 Hz ... also by definition.

C being four semitones up from A would then have a frequency of 2^(4/12)*440 or approximately 554.36525 Hz .. hmm .. not sure where your values for C come from ... they seem off.

Strictly speaking it depends on the actual tuning being used, there are many variations on the theme .. but this is what is mostly used.

_________________
Jan
also .. could someone please turn down the thermostat a bit.
Posted Image, might have been reduced in size. Click Image to view fullscreen.
Back to top
View user's profile Send private message Visit poster's website
mosc
Site Admin


Joined: Jan 31, 2003
Posts: 18197
Location: Durham, NC
Audio files: 212
G2 patch files: 60

PostPosted: Tue Apr 04, 2017 3:39 pm    Post subject: Reply with quote  Mark this post and the followings unread

I think you might have a error in you math. Here is a web site that has the correct way to do it.

http://www.phy.mtu.edu/~suits/NoteFreqCalcs.html

There is also a nice table of the frequencies:

http://www.phy.mtu.edu/~suits/notefreqs.html

In virtually all tuning systems an octave is exactly a factor of 2, one way or the other.

_________________
--Howard
my music and other stuff
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
mosc
Site Admin


Joined: Jan 31, 2003
Posts: 18197
Location: Durham, NC
Audio files: 212
G2 patch files: 60

PostPosted: Tue Apr 04, 2017 3:48 pm    Post subject: Reply with quote  Mark this post and the followings unread

I forgot something important though. Real life pianos are not tuned to exact octaves; octaves are "stretched". Good piano tuners do this. I don't know any electronic instruments tuned like this, but I'd like to know if there is.

Here's a nice link (scan down to the "Stretch" section):

https://en.wikipedia.org/wiki/Piano_tuning

_________________
--Howard
my music and other stuff
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
gdavis



Joined: Feb 27, 2013
Posts: 359
Location: San Diego
Audio files: 1

PostPosted: Tue Apr 04, 2017 4:27 pm    Post subject: Reply with quote  Mark this post and the followings unread

Blue Hell wrote:

C being four semitones up from A would then have a frequency of 2^(4/12)*440 or approximately 554.36525 Hz .. hmm .. not sure where your values for C come from ... they seem off.

C is three semitones up from A. Your forgot that B# = C Wink

As Blue Hell said, both methods produce essentially the same result. The trade off between the two methods is memory vs. computation, so the choice comes down to what platform you're on and how each of these two factors weigh against each other.

The issue you are noting about the values not "matching" is a matter of computational precision and round off error. This has to be taken into consideration regardless of the method you use.

While the "multiply by two" method may at first seem to give you a result that is "out of tune", it really doesn't.

Take your example of C4=261.63 and C5=523.25. As you noted, 261.63 * 2 is not 523.25. However, this is not because C5 does not equal 2*C4. The discrepancy is actually due to the fact that C4 does not equal 261.63, but has been rounded off. They're both slightly out of tune.

None of those values are exact based on the 2^(n/12)*440 relation, but they don't have to be. You need to decide how much precision is necessary to sound "in tune".

Once you have a suitable precision for your lowest frequency, the method for calculating higher frequencies won't matter.

Consider this:
65.41Hz +/- .005 (2 decimal point precision) is accurate to about .0076 percent.
4186.01Hz +/- .005 (again, 2 decimal point precision) is accurate to .00012 percent, way more accurate than 65.41.

What this is illustrating is that as you go up in frequency, you don't need as many decimal places to maintain the same level of accuracy. So, while the two calculations may not be mathematically equal, you don't loose any accuracy when you multiply to get higher octaves.

What this means is that if rounding off C4 to two decimal places is enough to sound "in tune", then C5 = 2*C4 will also be in tune. Even if the value isn't exactly the same as the 2^n/12 based calculation, it's "close enough" that you can't hear the difference, and will continue to be up through all the octaves.


mosc wrote:
I forgot something important though. Real life pianos are not tuned to exact octaves; octaves are "stretched". Good piano tuners do this. I don't know any electronic instruments tuned like this, but I'd like to know if there is.

Here's a nice link (scan down to the "Stretch" section):

https://en.wikipedia.org/wiki/Piano_tuning

This is due to how strings physically vibrate, not a factor in electronic synthesis.

_________________
My synth build blog: http://gndsynth.blogspot.com/
Back to top
View user's profile Send private message
blue hell
Site Admin


Joined: Apr 03, 2004
Posts: 24079
Location: The Netherlands, Enschede
Audio files: 278
G2 patch files: 320

PostPosted: Wed Apr 05, 2017 1:46 am    Post subject: Reply with quote  Mark this post and the followings unread

gdavis wrote:
C is three semitones up from A. Your forgot that B# = C Wink


Worse .. counted the notes and not the intervals Shocked

_________________
Jan
also .. could someone please turn down the thermostat a bit.
Posted Image, might have been reduced in size. Click Image to view fullscreen.
Back to top
View user's profile Send private message Visit poster's website
mosc
Site Admin


Joined: Jan 31, 2003
Posts: 18197
Location: Durham, NC
Audio files: 212
G2 patch files: 60

PostPosted: Thu Apr 06, 2017 12:56 pm    Post subject: Reply with quote  Mark this post and the followings unread

Quote:

mosc wrote:
I forgot something important though. Real life pianos are not tuned to exact octaves; octaves are "stretched". Good piano tuners do this. I don't know any electronic instruments tuned like this, but I'd like to know if there is.

Here's a nice link (scan down to the "Stretch" section):

https://en.wikipedia.org/wiki/Piano_tuning

This is due to how strings physically vibrate, not a factor in electronic synthesis.


I agree about the physical strings differing from electronic circuits. I've noticed that guitars, ukuleles, and banjos that I play sound best when I tune only the lowest note by electronic tuner and tune the higher strings by ear. Plucked or struck strings play a little sharp at first and then drift down as they sustain.

Also, if one is going to play in one particular key, equal-temperament tuning is not going to sound as good as an alternative tuning, like just intonation, for example. That's another subject. but something to consider if you're deciding to use calculated values for equal-tempered tuning versus reading frequency values from a table.

We are lucky to have an alternative tuning master here on electro-music.com. Check out Seraph's artist forum.

http://electro-music.com/forum/forum-84.html

_________________
--Howard
my music and other stuff
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
Display posts from previous:   
Post new topic   Reply to topic Moderators: State Machine
Page 1 of 1 [7 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
 Forum index » DIY Hardware and Software » Microcontrollers and Programmable Logic
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Forum with support of Syndicator RSS
Powered by phpBB © 2001, 2005 phpBB Group
Copyright © 2003 through 2009 by electro-music.com - Conditions Of Use