From
Ivan Roshin
→
To
All
1 August 2001
Hello, All!
═══════════════════ 1 .W ══════════════════
(c) Ivan Roshchin, Moscow
Fido: 2:5020/689.53
ZXNet: 500:95/462.53
E-mail: asder_ffc@softhome.net
WWW: http://www.ivr.da.ru
Frequency table with zero error
════════════════════ ════════════════════
("Radio Amateur. Your Computer" 6-8/2001)
Music is the unconscious
an exercise of the soul in arithmetic.
G. Leibniz
Excursion into history
─────────────────
It has long been noted that frequencies located between each other
in simple numerical ratios, most pleasing to the ear.
Based on this, ancient musicians tuned their
instruments so that the ratios of sounds in an octave represent
are ratios of small integers (Fig. 1). We will call
such a scale is natural.
┌──────────────────────1/ 2───────────────────────┐
│ │
│ ┌─────5/6─────┐ ┌─────4/5─────┤
│ │ │ │ │
╔══╧═══╤══╧═══╤══════╤══╧═══╤═══ ═══╤══╧═══╤══════╗--┴---┬------┐
║ A │ B │ C │ D │ E │ F │ G ║ A | B |
║ │ │ │ │ │ │ ║ | |║ la │ si │ do │ re │ mi │ fa │ sol ║ la | si |
╚══╤═══╧══╤═══╧══╤═══╧══╤═══╧══╤ ═══╧══╤═══╧══╤═══╝--┬---┴--┬---┘
│ │ │ │ │ │ │ │ │
├─8/9──┴15/16─┼─8/9 ─┴─9/10─┼15/16─┴─8/9──┼─9/10─┘ │
│ │ │ │ │
└─────5/6─────┴─────4/5───── ┴─────5/6─────┴─────4/5─────┘
Fig. 1
On an instrument tuned to suit nature's
scale, it was impossible to play a melody, say, a tone higher
or lower. To play in a different key it was necessary
reconfigure. In order to somehow overcome this inconvenience,
five additional sounds were added to the octave - where the interval
between the main sounds was equal to a whole tone (8/9 or 9/10). But
this did not completely solve the problem: not from any key to any
it was possible to cross easily and simply.
Around VI-V centuries. BC Pythagoras took on the solution to this problem
(he was not only a scientist, but also a brilliant musician). A little
by changing the frequencies of three of the seven notes in an octave and accurately calculating
frequencies of additional sounds, he provided the musicians with
the ability to move from tonality to tonality is much more
freer. But still some need for reconfiguration
instruments remained.
At the end of the 17th century, a new musical reform took place.
building: German organist Andreas Werkmeister proposed to dorelationships between frequencies of neighboring sounds that are the same and
equal to 2^(1/12). On the one hand, it was complete and
the final solution to the problem of transition from tonality to
tonality without retuning the instrument. On the other hand,
after this reform there was not a single integer left in the octave
ratio - each note was a little out of tune. Therefore many
The musicians were initially outraged by Werkmeister's proposal. But in
In the end, considerations of convenience outweighed, and such a scale
(called tempered) is still used today.
To today's days
──────────────────
After Werkmeister invented his scale,
almost three centuries, when no less great inventor, sir
Clive Sinclair released his famous "ZX Spectrum 128" with
music coprocessor.
The output frequency of each of the three available in the coprocessor
tone generators is obtained by dividing the clock frequency by 16
and subsequent division by an integer in the range 1..4095. This
the number is called the division factor.
Below are the formulas relating the clock frequency
coprocessor (CLK), division factor (k) and output frequency
(F). Using them, you can calculate each of these three quantities
according to the other two, the meanings of which are known.
F = CLK/(16*k) (*)
k = [CLK/(16*F)+0.5] (**)
CLK = 16*F*k (***)In all music editors for the ZX Spectrum that I
seen (Sound Tracker, ASC Sound Master, Pro Tracker, Pro Sound
Creator, etc.) a tempered scale is used. Immediately
without making any calculations, we can say that this
the scale is reproduced by the coprocessor only with a certain
error. Indeed, the ratio of the frequencies of any two
neighboring sounds in it are 2^(1/12) - an irrational number, and according to
definition cannot be represented as a quotient of two
integers. At the same time, any two frequencies formed
coprocessor, will relate to each other exactly as whole
numbers: from formula (*) it immediately follows that F1/F2=k2/k1.
The error can be reduced by increasing the clock frequency
coprocessor [4], but it’s fundamental to completely get rid of it
impossible.
════════════════════════ ════════════════════════
Best regards, Ivan Roshchin.
From
Ivan Roshin
→
To
All
1 August 2001
Hello, All!
═══════════════════ 2 .W ══════════════════
In a tempered scale, each note is a little
false, and when the error inherent in it adds up to
error in its implementation on the coprocessor (Table 1), result
cannot satisfy even the undemanding listener.
┌──────┬──────────────────────── ───────────────────────────────┐
│ │ Frequency, Hz │
│ ├─────────────┬───────────── ────┬───────────────────────┤
│ Note │ │ │ Best approximation │
│ │ Natural │ Tempered │ to tempered │
│ │ scale │ scale │ scale for AY (YM) │
│ │ │ │ at CLK=1.75 MHz │
├──────┼─────────────┼────────── ───────┼───────────────────────┤
│ A-1 │ 440.0 │ 440.0 │ 439.3 │
├──────┼─────────────┼────────── ───────┼───────────────────────┤
│ B-1 │ 495.0 │ 493.9 │ 494.9 │
├──────┼─────────────┼────────── ───────┼───────────────────────┤
│ C-2 │ 528.0 │ 523.3 │ 523.3 │
├──────┼─────────────┼────────── ───────┼───────────────────────┤
│ D-2 │ 594.0 │ 587.3 │ 588.0 │
├──────┼─────────────┼────────── ───────┼───────────────────────┤│ E-2 │ 660,0 │ 659,3 │ 658,9 │
├──────┼─────────────┼─────────────────┼───────────────────────┤
│ F-2 │ 704,0 │ 698,5 │ 696,7 │
├──────┼─────────────┼─────────────────┼───────────────────────┤
│ G-2 │ 792,0 │ 784,0 │ 781,3 │
├──────┼─────────────┼─────────────────┼───────────────────────┤
│ A-2 │ 880,0 │ 880,0 │ 882,1 │
└──────┴─────────────┴─────────────────┴───────────────────────┘
Таблица 1
Проблема получает неожиданное решение
─────────────────────────────────────
Любые две частоты, сформированные сопроцессором, относятся
друг к другу как целые числа. Да ведь это как раз то, что нужно
для реализации природного звукоряда!
Посмотрим на рис. 1 и, учитывая, что между коэффициентом
деления и частотой на выходе сопроцессора существует обратная
зависимость, выпишем соотношения коэффициентов деления для нот
от "ля" одной октавы до "ля" следующей октавы:
k(a)/k(b) = 9/8 (1)
k(b)/k(c) = 16/15 (2)
k(c)/k(d) = 9/8 (3)
k(d)/k(e) = 10/9 (4)
k(e)/k(f) = 16/15 (5)
k(f)/k(g) = 9/8 (6)
k(g)/k(a') = 10/9 (7)Let's try to select the minimum set of coefficients k(a),
k(b),...,k(g), which would satisfy these relations.
The coefficients, as we remember, must be integers. To
equality (1) holds, take k(a)=9, k(b)=8. From (2)
it follows that k(b) must be divisible by 16. Let’s double the initial
the values of the first two coefficients, which will not change the ratio
between them: k(a)=18, k(b)=16. Then k(c)=15. But k(c) must
divisible by 9 - this is required by condition (3). Let's triple the odds:
k(a)=54, k(b)=48, k(c)=45. Then k(d)=45*8/9=40. From equality
(4) we get k(e)=40*9/10=36. From (5) it follows that k(e) should
divided by 16. To do this, multiply the coefficients by four:
k(a)=216, k(b)=192, k(c)=180, k(d)=160, k(e)=144. Then k(f)=
144*15/16=135. And finally, k(g)=135*9/10=120.
So, the required set of division coefficients is obtained: 216,
192,180,160,144,135,120. The first coefficient, k(a), corresponds to
the note “A” - it was previously considered the first note of the octave. B
letter designations of notes (A,B,C,D,E,F,G) this was preserved until
until now. The standard note has also been preserved - “A” of the first octave (440
Hz). It is now customary to begin the octave with the note "C". According to
with this, let's represent the set of coefficients so that it starts with
k(c), and k(a) and k(b) are divided by two and moved to the end: 180,
160,144,135,120,108,96.
Since this set is the smallest, it determines the coefficientsfor the highest octave that will sound without distortion.
By doubling these coefficients, we obtain values corresponding to
lower octaves. On the contrary, successively dividing them into two,
we will get values corresponding to higher octaves - but
each time the division cannot be carried out completely, there will be
an error may occur.
Let us carry out the above actions, taking into account that the coefficient
ents should not go beyond the range 1..4095. Round
fractional values obtained by dividing to the nearest integer
We will not provide numbers for now to avoid the accumulation of errors.
We summarize the calculated values in a table.
├──────┼──────┼──────┼─── ───┼──────┼──────┼──────┤
│ │ │ │ │ 3840 │ 3456 │ 3072 │
├──────┼──────┼──────┼─── ───┼──────┼──────┼──────┤
│ 2880 │ 2560 │ 2304 │ 2160 │ 1920 │ 1728 │ 1536 │
├──────┼──────┼──────┼─── ───┼──────┼──────┼──────┤
│ 1440 │ 1280 │ 1152 │ 1080 │ 960 │ 864 │ 768 │
├──────┼──────┼──────┼─── ───┼──────┼──────┼──────┤
│ 720 │ 640 │ 576 │ 540 │ 480 │ 432 │ 384 │
├──────┼──────┼──────┼─── ───┼──────┼──────┼──────┤
│ 360 │ 320 │ 288 │ 270 │ 240 │ 216 │ 192 │
╔══════╤══════╤══════╤═══ ═══╤══════╤══════╤══════╗
║ 180 │ 160 │ 144 │ 135 │ 120 │ 108 │ 96 ║
╚══════╧══════╧══════╧═══ ═══╧══════╧══════╧══════╝│ 90 │ 80 │ 72 │ 67,5 │ 60 │ 54 │ 48 │
├──────┼──────┼──────┼──────┼──────┼──────┼──────┤
│ 45 │ 40 │ 36 │33,75 │ 30 │ 27 │ 24 │
├──────┼──────┼──────┼──────┼──────┼──────┼──────┤
│ 22,5 │ 20 │ 18 │16,875│ 15 │ 13,5 │ 12 │
├──────┼──────┼──────┼──────┼──────┼──────┼──────┤
│11,25 │ 10 │ 9 │8,4375│ 7,5 │ 6,75 │ 6 │
├──────┼──────┼──────┼──────┼──────┼──────┼──────┤
│5,625 │ 5 │ 4,5 │4,2188│ 3,75 │3,375 │ 3 │
├──────┼──────┼──────┼──────┼──────┼──────┼──────┤
│2,8125│ 2,5 │ 2,25 │2,1094│1,875 │1,6875│ 1,5 │
├──────┼──────┼──────┼──────┼──────┼──────┼──────┤
│1,4063│ 1,25 │1,125 │1,0547│ │ │ │
├──────┼──────┼──────┼──────┼──────┼──────┼──────┤
Таблица 2
════════════════════════════════════════════════
С уважением, Иван Рощин.
From
Ivan Roshin
→
To
All
1 August 2001
Hello, All!
═══════════════════ 3 .W ══════════════════
Now, given that the coefficients must be integers,
Let's do the rounding. We mark the rounded values with shading.
At the same time, let’s mark with the “√” symbol values that are multiples of 16 (why is this
necessary, I will explain later).
┌──────┬──────┬──────┬─── ───┬──────┬──────┬──────┐
│ C │ D │ E │ F │ G │ A │ B │
├──────┼──────┼──────┼─── ───┼──────┼──────┼──────┤
│ │ │ │ │√3840 │√3456 │√3072 │
├──────┼──────┼──────┼─── ───┼──────┼──────┼──────┤
│√2880 │√2560 │√2304 │√2160 │√1920 │√1728 │√1536 │
├──────┼──────┼──────┼─── ───┼──────┼──────┼──────┤
│√1440 │√1280 │√1152 │ 1080 │√960 │√864 │√768 │
├──────┼──────┼──────┼─── ───┼──────┼──────┼──────┤
│√720 │√640 │√576 │ 540 │√480 │√432 │√384 │
├──────┼──────┼──────┼─── ───┼──────┼──────┼──────┤
│ 360 │√320 │√288 │ 270 │√240 │ 216 │√192 │
├──────┼──────┼──────┼─── ───┼──────┼──────┼──────┤
│ 180 │√160 │√144 │ 135 │ 120 │ 108 │√ 96 │
├──────┼──────┼──────┼─── ───┼──────┼──────┼──────┤
│ 90 │√ 80 │ 72 │▒▒68▒▒│ 60 │ 54 │√ 48 │
├──────┼──────┼──────┼─── ───┼──────┼──────┼──────┤
│ 45 │ 40 │ 36 │▒▒34▒▒│ 30 │ 27 │ 24 │├──────┼──────┼──────┼──────┼──────┼──────┼──────┤
│▒▒23▒▒│ 20 │ 18 │▒▒17▒▒│ 15 │▒▒14▒▒│ 12 │
├──────┼──────┼──────┼──────┼──────┼──────┼──────┤
│▒▒11▒▒│ 10 │ 9 │▒▒8▒▒▒│▒▒8▒▒▒│▒▒7▒▒▒│ 6 │
├──────┼──────┼──────┼──────┼──────┼──────┼──────┤
│▒▒6▒▒▒│ 5 │▒▒5▒▒▒│▒▒4▒▒▒│▒▒4▒▒▒│▒▒3▒▒▒│ 3 │
├──────┼──────┼──────┼──────┼──────┼──────┼──────┤
│▒▒3▒▒▒│▒▒3▒▒▒│▒▒2▒▒▒│▒▒2▒▒▒│▒▒2▒▒▒│▒▒2▒▒▒│▒▒2▒▒▒│
├──────┼──────┼──────┼──────┼──────┼──────┼──────┤
│▒▒1▒▒▒│▒▒1▒▒▒│▒▒1▒▒▒│▒▒1▒▒▒│ │ │ │
└──────┴──────┴──────┴──────┴──────┴──────┴──────┘
Таблица 3
Что можно сказать, взглянув на эту таблицу? Она содержит 84
значения коэффициентов, соответствующие 84 нотам. Это 11 полных
октав и две неполные. 59 нот звучат абсолютно точно, а
оставшиеся 25 - фальшивые. В начале таблицы имеется непрерывный
участок из 41 ноты, звучащих без погрешностей. Это почти шесть
октав - такого диапазона достаточно для проигрывания значитель-
ной части музыкальных произведений.
Зачем мы отмечали в таблице значения, кратные 16? Вспомним,
что сопроцессор может формировать звуки не только с помощью
генераторов тона, но и с помощью генератора огибающей. Частота
тона зависит от делителя частоты тона, а частота огибающей,
соответственно, от делителя частоты огибающей. Разница в том,that when the envelope generator operates, the clock frequency at first
is divided not by 16, but by 256. As we can see, the frequency of the envelope
is regulated more roughly than the tone frequency. Because of this
sounds produced by an envelope generator are usually
They are quite out of tune, and musicians avoid using them.
So, the values we noted correspond to the sounds that
can be obtained using an envelope generator without
any error! As you might guess, the meaning
the envelope divider when playing them will be exactly 16 times
less than the value in the table. Using an envelope generator
You can get accurate sounds in lower octaves, down to
lower limit of audibility, because the value of the envelope divider
can be in the range 1-65535.
Let's now decide on the clock frequency of the coprocessor. Her
easy to calculate, knowing that the frequency of the note "A" of the first octave
is equal to 440 Hz, knowing the division coefficient corresponding to this
note, and using the formula (***).
Let me remind you that octaves are named in this order (from bottom to top):
subcontractive, counteroctave, major, minor, first, second,
third, fourth and fifth. The first octave, considered the most
commonly used, is located approximately in the middle of the scale.
Where in the table is the coefficient corresponding to the note
"A" of the first octave? Obviously, in column "A" - this is exactly whatthe letter designation of this note. But in what line? String
we can choose ourselves, guided by the fact that those used in
мелодии ноты попали на область значений с нулевой погрешностью.
For example, let's calculate the clock frequency of the coprocessor if
The first octave corresponds to the fifth row from the top of the table.
CLK = 16*440*216 = 1520640 Hz
If we chose not the fifth, but the fourth line from the top, then
the CLK value would be twice as large. And if the sixth line from the top,
that's half as much.
At this clock speed we will be able to play in pure C
major and A minor. To play in other keys, time signature
the frequency will have to be changed.
If we want to be able to play any melody,
starting with any sound of the octave (which, in fact, was what we dreamed of
ancient musicians), and if we consider the basic value of the clock
frequency 1520640 Hz, then we need the following set of frequencies:
┌─────────────┬───── ────────────────────┐
│ key │ CLK, Hz │
├─────────────┼───── ────────────────────┤
│ C major │ 1520640 │
│ D major │ 1520640*9/8 = 1710720 │
│ E major │ 1710720*10/9 = 1900800 │
│ F major │ 1900800*16/15 = 2027520 │
│ G major │ 2027520*9/8 = 2280960 │
│ A major │ 2280960*10/9 = 2534400 ││ B major │ 2534400*9/8 = 2851200 │
├─────────────┼───── ────────────────────┤
│ A minor │ 1520640▐│
│ B minor │ 1520640*9/8 = 1710720▐│
│ C minor │ 1710720*16/15 = 1824768 │
│ D minor │ 1824768*9/8 = 2052864 │
│ E minor │ 2052864*10/9 = 2280960▐│
│ F minor │ 2280960*16/15 = 2433024 │
│ G minor │ 2433024*9/8 = 2737152 │
└─────────────┴───── ────────────────────┘
Table 4
════════════════════════ ════════════════════════
Best regards, Ivan Roshchin.
From
Ivan Roshin
→
To
All
1 August 2001
Hello, All!
═══════════════════ 4 .W ══════════════════
A total of eleven different frequencies, since three values
are repeated twice in the table (they are marked with the symbol "▐"). For
so that you can shift the range of notes from zero
error by an octave up or down, adjusting to
specific melody, you will need twice as large and twice as
smaller values.
If you need to perform works in all twenty
four keys - twelve major and twelve
minor - apparently, it would be most optimal to do so,
so that for each subsequent key the clock frequency is
2^(1/12) times more than for the previous one. This will require
There are twelve different CLK values in total:
┌────────────────────── ────────────┬─────────┐
│ key │ CLK, Hz │
├────────────────────── ────────────┼─────────┤
│ C major, A minor │ 1520640 │
│ C sharp major, A sharp minor │ 1611062 │
│ D major, B minor │ 1706861 │
│ D sharp major, C minor │ 1808356 │
│ E major, C sharp minor │ 1915886 │
│ F major, D minor │ 2029811 │
│ F sharp major, D sharp minor │ 2150510 │
│ G major, E minor │ 2278386 ││ G sharp major, F minor │ 2413866 │
│ A major, F sharp minor │ 2557401 │
│ A-sharp major, G minor │ 2709472 │
│ B major, G sharp minor │ 2870586 │
└────────────────────── ────────────┴─────────┘
Table 5
As you can see, for playing music in different keys
при использовании натурального звукоряда с нулевой погрешностью
requires hardware modification to allow changing the clock
coprocessor frequency. (Нечто подобное было описано в [4], только
в нашем случае возможных значений CLK должно быть не два, а
more, and switching should not be done manually, but
by writing a specific value to a specific port.)
If you are not going to change this frequency, and it is equal to
1750000 Hz (as in my Pentagon, and in many others
моделях спектрум-совместимых компьютеров), то вы сможете
исполнять музыку лишь в некоторой средней тональности между
D major and D sharp major (or between B minor and C minor), as
follows from table 5.
From theory to practice
────────────────────
С помощью чего вы будете сочинять и проигрывать музыку?
Obviously, with the help of a music editor. Most Popular
the editor is currently Pro Tracker (hereinafter PT) -
Let's talk about it.
The range available in PT is eight octaves: from counteroctave tofifth octave. In the editor they are designated by numbers from 1 to 8.
Let us compare with them the first eight complete rows from Table 3. In these
lines, only five values out of 56 are shaded - which means only
five notes will be out of tune: F-6, F-7, C-8, F-8 and A-8 (numbers
octaves are indicated here as is customary in PT). All other notes
will sound with zero error.
Information about what division factor corresponds to
each note, is contained inside PT in a special table (its
called frequency). For each coefficient value there is allocated
two bytes; number of coefficients - 12*8=96, hence the size
tables - 192 bytes.
Let's create the frequency table we need using assembler.
The values of the coefficients, as already mentioned, will be taken from
the first eight full rows of table 3. Since when using
natural scale additional sounds (C#, D#, F#, G#, A#)
are not needed, let us make the corresponding coefficients zero.
ORG #8000
DW 2880.0.2560.0.2304.2160.0.1920.0.1728.0.1536
DW 1440,0,1280,0,1152,1080,0,960,0,864,0,768
DW 720,0.640,0.576,540,0.480,0.432,0.384
DW 360,0,320,0,288,270,0,240,0,216,0,192
DW 180,0,160,0,144,135,0,120,0,108,0,96
DW 90,0,80,0,72,68,0,60,0,54,0,48
DW 45,0,40,0,36,34,0,30,0,27,0,24
DW 23,0,20,0,18,17,0,15,0,14,0,12This text must be compiled and the object code written into
file "table.C". Well, if you don’t know how to use assembler,
you can create a file with a frequency table in any hex editor
according to the dump below:
#0000: 400B 0000 000A 0000 0009 7008 0000 8007
#0010: 0000 C006 0000 0006 A005 0000 0005 0000
#0020: 8004 3804 0000 C003 0000 6003 0000 0003
#0030: D002 0000 8002 0000 4002 1C02 0000 E001
#0040: 0000 B001 0000 8001 6801 0000 4001 0000
#0050: 2001 0E01 0000 F000 0000 D800 0000 C000
#0060: B400 0000 A000 0000 9000 8700 0000 7800
#0070: 0000 6C00 0000 6000 5A00 0000 5000 0000
#0080: 4800 4400 0000 3C00 0000 3600 0000 3000
#0090: 2D00 0000 2800 0000 2400 2200 0000 1E00
#00A0: 0000 1B00 0000 1800 1700 0000 1400 0000
#00B0: 1200 1100 0000 0F00 0000 0E00 0000 0C00
════════════════════════ ════════════════════════
Best regards, Ivan Roshchin.
From
Ivan Roshin
→
To
All
1 August 2001
Hello, All!
═══════════════════ 5 .W ══════════════════
PT also has a so-called envelope table (it is needed
only when writing music - you can play what has already been written
and without it). It contains the values of the coefficients from the frequency
tables divided by eight. Each value is stored in one
byte; if it does not fit in a byte (i.e. more than 255), then
The table contains the number 255. The entire table occupies 96 bytes.
Note that dividing by eight corresponds to shifting by three
octaves up. Therefore we can take the values for the table
envelopes from Table 3, moving three lines down from
first full line.
The assembly text describing the envelope table will be
look like this:
ORG #8000
DB 255,0,255,0,255,255,0,240,0,216,0,192
DB 180,0,160,0,144,135,0,120,0,108,0,96
DB 90,0,80,0,72,68,0,60,0,54,0,48
DB 45,0,40,0,36,34,0,30,0,27,0,24
DB 23,0,20,0,18,17,0,15,0,14,0,12
DB 11,0,10,0,9,8,0,8,0,7,0,6
DB 6,0,5,0,5,4,0,4,0,3,0,3
DB 3,0,3,0,2,2,0,2,0,2,0,2
The object code obtained after compilation (its dump is given
below) write it to the file "envelope.C".
#0000: FF00 FF00 FFFF 00F0 00D8 00C0 B400 A000
#0010: 9087 0078 006C 0060 5A00 5000 4844 003C#0020: 0036 0030 2D00 2800 2422 001E 001B 0018
#0030: 1700 1400 1211 000F 000E 000C 0B00 0A00
#0040: 0909 0008 0007 0006 0600 0500 0504 0004
#0050: 0003 0003 0300 0300 0202 0002 0002 0002
Unfortunately, in PT (as well as in any other well-known
music editor for ZX Spectrum) is not provided for me
possibility of using a frequency table defined
user. It contains only four pre-calculated
tables for different coprocessor clock speeds. You can
replace one of them with the one we need, but for this we will have to
work hard. Let's take a closer look at this process.
We will need Pro Tracker 3.51 (this is the latest version on
the moment of writing this article; you may have another version -
in this case, proceed by analogy), monitor-debugger STS
any version, HRUST packer version 1.2 or 1.3 and my program
BestView version 2.9 or higher.
To avoid damaging any valuable information, all
We will carry out operations on a separate blank disk. Let's copy
PT to this disk and change the file name to "PTv3.51z" so that it
could be easily distinguished from the original. The letter "z" is from the word
"zero" - "zero"; this is a hint that a table with
zero error.
Now, from the four tables available in the editor, you need to select
the one that we will replace with our own. Let this be a table"1.750000 Hz" (in PT 3.4 it was called "ASM OR PSC").
To make a replacement, you need to know where this is located
table. And for this, in turn, you need to know how she
looks at what byte sequence it starts with.
It is known that in a module compiled with the player,
The frequency table is located at offset #200 from the beginning. Let's create
such a module containing the table we are interested in. For this
immediately after launching PT, set the "Frequency" parameter in setup
table" equal to 1.750000 Hz (by default this is the value there
and costs), select the "Compiler" item and in the window that appears, select
"Save compiled song". Let's write the module, for example, under the name
"test".
Then, using BestView, we will view the dump of this module. By
at offset #200 there will be the following:
#0200: 100D 550C A40B FC0A 5F0A CA09 3D09 B808
#0210: 3B08 C507 5507 EC06 8806 2A06 D205 7E05
#0220: 2F05 E504 9E04 5C04 1D04 E203 AB03 7603
...... .....................................
Let's start searching for this table in PT. Press the combination
keys "CS+A" on the file "PTv3.51z". From the list that appears
recognized blocks we are interested in "p_blk_01" - table
is located right there. By pressing "Z" on this packed block,
Let's look at its parameters:
┌────────────┬───────────────── ───────────────────────────────┐
│ PTv3.51z B │First #10FC=4348 bytes: Packed block ││ code__01 │ │
│█p_blk_01███│Compressor : HRUST 1 │
│ p_blk_02 │Block length : #10FC=4348 │
│ code__02 │Decompressor : No │
│ │Unpacked length: #2F55=12117 │
│ │K=35%, save 65% │
│ │ │
Fig. 2
Next, use the "L" key to scroll the file panel
to the right to find out the track-sector address of the block: #01/#02.
By pressing SS+ENTER, unpack the block to disk under the name “unpack1”.
Let's dump the unpacked block using "CS+ENTER" and, knowing,
What byte sequence does the table start with? Let’s try it
find. As it turns out, it is located at offset #47F.
The envelope table is easy to find, knowing that the first few
the bytes in it are equal to #FF, and the following bytes correspond to the elements
frequency table, only three octaves higher. She is located by
offset #3BF.
Well, you can replace these tables with your own. Launch STS
and upload the unpacked block to address #8000. Frequency table
load from the file "table.C" to the address #8000+#47F= #847F. Table
load envelopes from the file "envelope.C" to the address #8000+#3BF=
#83BF. Let's write the changed block under the same name "unpack1",start=#8000, length=#2F55. All that's left is to package it and record it
inside PT.
════════════════════════ ════════════════════════
Best regards, Ivan Roshchin.
From
Ivan Roshin
→
To
All
1 August 2001
Hello, All!
═══════════════════ 6 .W ══════════════════
We launch HRUST, pack the block without an unpacker and
write it to a file named "unpack1*.C". If length
packed block in sectors does not exceed #11 sectors, then
everything is fine. In our case this is true. But if the block
turned out to be longer (say, if you inserted some other
table, poorly packed), then it will not fit into the allotted
inside PT place. Then you will have to reset inside the unpacked
block something unnecessary (for example, another frequency
table - it comes immediately after the first one) and repack it.
Let's write the packed block inside the file "PTv3.51z".
We know the track-sector address of the beginning of the block. Launch STS
upload the file "unpack1*.C" to address #8000 and write #11
sectors from #8000 to track #01, sector #02.
All! Now the "1.750000 Hz" table in the editor is yours! You can
launch the editor and evaluate the sound.
Already converted in this way Pro Tracker 3.51 you can
receive by contacting me at one of the indicated at the beginning
address articles.
To play in C major or A minor, the clock frequency is
coprocessor, as we already calculated, will be equal to 1520640 Hz.
By changing it as described in the previous section, you will be able to play
in other keys, using the same keys as, in my
looks very convenient. It is possible, however, for each keystore your copy of the editor with the appropriate ones shifted
way in tables.
Yes, by the way: to change the clock frequency of the coprocessor when
working PT, obviously, you will have to either use manual
switch, or, in the case of changing the frequency by recording
values to the port, modify PT so that this function is included in it
implemented.
Procedure for constructing a frequency table
──────────────────────────────────────
The frequencies of notes in each subsequent octave are twice as high as in
the previous one, and the division coefficients are, accordingly, halved
less. Thus, if the values of the coefficients for
notes of the lowest octave, dividing by two is easy to get them
values for the next octaves. This can be used to
in order not to store the frequency table in the program, but to build it with
using an assembler procedure. In this case we will get a noticeable
the gain in program length due to the fact that the construction procedure
tables and source data for it will take up less space,
than the table itself.
Below is the text of this procedure. Input parameters: in HL
indicate the address where the coefficients for the notes are located
lower octave (they are stored in a special format with a higher
accuracy - see below for more details), and DE indicates the address according to
where the constructed table will be located. Length
procedures - 40 bytes, length of source data - 12*2=24 bytes. Byсравнению с длиной частотной таблицы (192 байта) это весьма
not enough.
MAKE_FT LD B,12
M1 PUSH BC
LD C,(HL)
INC HL
PUSH HL
LD B,(HL)
PUSH DE
EX DE,HL
LD DE,23
LD XH,8
M2 SRL B
RR C
LD A,C
ADC A,D ;=ADC 0
LD(HL),A
INC HL
LD A,B
ADC A,D ;=ADC 0
LD(HL),A
ADD HL,DE
DEC XH
JR NZ,M2
POP DE
INC DE
INC DE
POP HL
INC HL
POP B.C.
DJNZ M1
RET
Обратите внимание на то, как осуществляется деление на два.
Если делать его простым сдвигом, отбрасывая выдвинутый разряд,
процедуру можно было бы сильно упростить. But absolute
погрешность при этом достигала бы единицы младшего разряда.
Чтобы минимизировать погрешность, деление производится с
округлением: если выдвинутый при сдвиге бит равен единице (а
значит, дробная часть результата больше или равна 0,5), к
результату прибавляется единица; if the extended bit was
равен нулю (дробная часть меньше 0,5), результат остается каким
was. Как видим, в этом случае абсолютная погрешность не будет
превосходить половины младшего разряда, т.е. will be half as much.Rounding is done directly during recording
result into memory. Participates in subsequent divisions by two
unrounded value to avoid accumulation of errors.
The coefficient values for the lower octave are stored with
increased accuracy - with one additional digit: if
the exact value of the coefficient is k1, then the value [k1*2] is stored.
The frequency table constructed using this procedure
will completely coincide with the best possible approximation to
theoretically calculated values of division coefficients.
════════════════════════ ════════════════════════
Best regards, Ivan Roshchin.
From
Ivan Roshin
→
To
All
1 August 2001
Hello, All!
═══════════════════ 7 .W ══════════════════
Let's look at the use of this procedure using an example:
let's try to create a frequency table for the natural scale
at a coprocessor clock frequency of 1.75 MHz. As we remember, the most
low octave in PT is counter octave; Let's calculate the frequencies of the notes
octaves, given that they are eight times less than the frequencies
the corresponding notes of the first octave and sixteen times less,
than the frequencies of the notes of the second octave - and we will take their values from
table 1.
F(c) = 528/16 = 33 Hz
F(d) = 594/16 = 37.125 Hz
F(e) = 660/16 = 41.25 Hz
F(f) = 704/16 = 44 Hz
F(g) = 792/16 = 49.5 Hz
F(a) = 440/8 = 55 Hz
F(b) = 495/8 = 61.875 Hz
Now, using formula (**), we calculate the corresponding notes
values of the coefficients, but we will not perform rounding.
k(c) = 3314.3939
k(d) = 2946.1279
k(e) = 2651.5152
k(f) = 2485.7955
k(g) = 2209.596
k(a) = 1988.6364
k(b) = 1767.6768
Source data for the table construction procedure is convenient
obtained by multiplying the integer part of these coefficients by two andadding 1 if the fractional part is greater than or equal to 0.5:
TABL_TEST DW 3314*2+0
DW 0
DW 2946*2+0
DW 0
DW 2651*2+1
DW 2485*2+1
DW 0
DW 2209*2+1
DW 0
DW 1988*2+1
DW 0
DW 1767*2+1
Well, the construction itself will be carried out with the following commands
(assuming that the table will be created from the address
#8000):
LD HL,TABL_TEST
LD DE,#8000
CALL MAKE_FT
If you want to use this frequency table when
writing music in PT, then you will also need to calculate the table
envelopes. Here's how to do it at the lowest cost
time. If you replace the command LD XH,8 in the MAKE_FT procedure with
LD XH,11, then 96 values will be generated from the address (DE+72)
coefficients for the envelope table. True, after that there are still more of them
it is necessary to “compact”, because, as already mentioned in the previous
section, each coefficient must be stored in one byte, and
values greater than 255 should be replaced by 255. This is convenient
done using the procedure below. Input
parameters: HL - frequency table address, increased by 72; DE-
the address at which the envelope table will be generated.
LD B.96
M1 LD A,(HL)
INC HL
INC(HL)
DEC (HL)
JR Z,M2
LD A,#FFM2 LD (DE),A
INC HL
INC DE
DJNZ M1
RET
Между прочим, в [1] приводится мнение, что "электронный"
the shade of computer music is largely due to the strict
temperament that any instrument goes through in a computer.
Попробуйте проверить, так ли это. Напишите модуль с использова-
нием полученной таблицы, а потом запишите его в двух вариантах -
откомпилированным с плеером и без плеера. When playing in
BestView модуля, откомпилированного без плеера, будет использо-
вана стандартная темперированная частотная таблица, а при
playing a module compiled with the player will
a table taken directly from the module was used. Both
таблицы рассчитаны для одной и той же тактовой частоты
сопроцессора (1,75 МГц), что обеспечит подходящие условия для
sound comparisons.
Literature
──────────
1. A. Shipilov. "Хорошо темперированный PC". "Computerra"
46/1997.
2. S. Ghazaryan. "В мире музыкальных инструментов". Moscow,
"Enlightenment", 1985.
3. L.I. Filippov. "Основы теории музыки в современном изложении".
Москва, Издательство МЭИ, 1999.
4. S. Ryumik. "Правильные" и "неправильные" CLK музыкального
сопроцессора". "Радиолюбитель. Your computer" 11/2000.
════════════════════════ ════════════════════════
Best regards, Ivan Roshchin.