Calculation of the frequency value of any note and an interesting sound of “pseudo-natural” tuning

I have been writing various melodies in various genres for a long time, but only recently decided to relate this activity to a scientific approach.

What if there is a formula for finding the frequency of any selected note on any chord? Well, having delved into the construction of note frequencies and the tuning of musical instruments, you can find out that, firstly, it is better to use an algorithm, and secondly, everything will depend on which scale is used:

Today, the standard of the scale is “equal temperament“. In it, the notes of all chords are formed from the note “la”, and the ratio between adjacent notes is always the same: 1 divided by the root of two in base 12. The frequency value of the “la” note in the so-called “first octave” (fourth according to the MIDI standard) is equal to 440 hertz.

It is not unlikely that you have come across disputes about the frequency in 432 hertzthey say it sounds better, which can be heard from ordinary people, or that it subconsciously affects the body, cures any diseases, and in general it was changed so that we live worse, which can be heard from preachers of the truth hiding from the authorities who live in the place registration.

And before – there was no standard for the frequency of the note “la”. It was tuned differently for different compositions and instruments, which made each tune more unique. Try to compare the notes “A” in modern melodies and on real recordings of old compositions: notes in old melodies will often sound much lower, because the frequency was often in the region 415 hertz.

But just changing the frequency of the note “la” and forming others from it is boring, because it is almost equivalent to simply lowering the pitch of the final melody. What if you can achieve a very unusual sound? For example: change the scale.

Apart from “equal temperament“, exists “natural tuning“, in which chords are built differently, and the ratio between notes is generally crazy, but most importantly, they may not be equal in different chords, which is why everyone began to use “equal temperament“. I’m not sure that this is suitable for a modern composer, because sometimes you want to register the bass part first at high frequencies – I registered it, shifted it down, and got a mess at the output.

And what if we combine the systems, taking from “equal temperament“the fact that all notes are built from the note “la”, and the ratios between notes are taken from “natural tuning“? That’s right, it’s going to be a cacophony. Perhaps successful frequencies for rather unusual melodies will turn out.

Correlations between frequencies according to official data
Correlations between frequencies according to official data

And so, now we need to write a program that will calculate all the frequencies for us with fairly good accuracy, and give them out as an array of fractional numbers.

First you need to understand what the frequency of the “la” note will be in the subcontract octave (zero chord according to the MIDI standard):

Standard (440)

440 – 220 – 110 – 55 – 27.5

Average old tunes (415)

415 – 207.5 – 103.75 – 51.875 – 25.9375

For the fans 432 (432, wow)

432 – 216 – 108 – 54 – 27

And the ratios can be taken inverse to those shown in the picture a little higher.

Well, now you can think through the whole algorithm:

база_ля          = 27.5 либо 25.9375 либо 27
колтчество_октав = 15
ноты_равномерные = []
ноты_натуральные = []

// Генерация нот в равномерном соотношении

// Можно заранее высчитать соотношения, ведь они одинаковые
полтона_вверх = 1.0594630943592953
полтона_вниз  = 0.9438743126816934

// Основной цикл
для "октава" в количестве "колтчество_октав":
  ля = база_ля
  умножаем ноту ля на два столько раз, какая сейчас октава - 1
  // Теперь считаем ноты, одну за другой
  ля_диез = ля * полтона_вверх
  си = ля_диез * полтона_вверх
  соль_диез = ля * полтона_вниз
  соль = соль_диез * полтона_вниз
  до_диез = ре * полтона_вниз
  до = до_диез * полтона_вниз
  добавить все ноты в массив друг за другом, от "до" до "си"

// Генерация нот в натуральном соотношении, уже интереснее

для "октава" в количестве "колтчество_октав":
  ля = база_ля
  умножаем ноту ля на два столько раз, какая сейчас октава - 1
  // И начинается самое интересное:
  ля_диез = ля * (16/15) иррациональное значение
  си = ля_диез * 1.0546875
  соль_диез = ля * 0.96
  соль = соль_диез * 0.9375
  фа_диез = соль * 0.9375
  фа = фа_диез * (128/135) иррациональное значение
  ми = фа * 0.9375
  ре_диез = ми * 0.96
  ре = ре_диез * 0.9375
  до_диез = ре * (128/135) иррациональное значение
  до = до_диез * 0.9375
  добавить все ноты в массив друг за другом, от "до" до "си"

As you can see, all the data completely coincide with the official ones, and even if they do not match, this is because our result is more accurate, and the official data contains abbreviated values.

The result of the algorithm for all standards, write it down, it may come in handy
The result of the algorithm for all standards, write it down, it may come in handy

I have already written the implementation of this algorithm in a programming language Pythonyou can see it in my codeberg repository (long live free software!).

And having calculated all the notes, having received them in the form of an array, you can generate sounds of the desired frequencies. I even wrote a program on the same Pythonwhich can be found in the same repositoryand which allows you to play a melody on a MIDI keyboard “in any order”changing it by pressing the left and right arrows.

With the frequency of the note “la” in 415 hertz and in “pseudonatural order“The notes sound like a semitone lower, but this is not entirely true (which can even be noticed), and they sound like they are more emotional, more expressive and sincere.

Screenshot from the above program for playing with different frequencies
Screenshot from the above program for playing with different frequencies

Why did I do it?

Of course, I started to get involved in this for a reason. I have Napoleonic plans to create our own, completely free and cross-platform analogue of FLStudio, with convenient controls and beautiful design, and not like it is done in LMMS (no offense, but the controls in it are very crooked, and distract from writing music). I have even thought about how the tools will be arranged (not VST, but maybe even better, and definitely safer, because I’m paranoid and want to protect users from vulnerabilities through tools).

And one of the main features of my analogue will be to transfer to the instruments not only the number of the pressed note according to the MIDI standard, but also the frequencies, so that the instruments mostly work with frequencies, and you can achieve unusual sounds right at the time of writing.

Of the problems so far unresolved, what is better to write on (for now I think on C++using multimedia library SFML), and how to generate the sounds themselves, because for now I only get noise, but flies away to infinity along the sine. The second problem will be solved by a detailed study of the principles of superimposing different waves of different frequencies to create a beautiful sound and the principles of working with samples. It will be difficult, especially since I haven’t been in music school for ten years.

And for those who were in a music school, and not a few – I suggest writing clarifications for this article in the comments, as well as sharing your unusual facts. I think many will be interested in reading.

And if you are interested in developing VST plugins or are generally interested in writing a free analogue of FLStudio – you can contact me, you can think something over together.

Thank you very much for your attention.

Similar Posts

Leave a Reply