Tuning Tables

A tuning table is a text representation of a scale that can be interpreted by an external program. This is usually used to tune a synthesizer or other sound source so that the scale can be used in a musical composition.

Some tuning tables – such as that used by Scala – describe the scale in absolute terms, but most need to have a reference defined so that the scale degrees can be mapped to a frequency. For this purpose the PyTuning package has adopted the MIDI standard for note numbers and frequencies.

Octave C C# D D# E F F# G G# A A# B
-2 0 1 2 3 4 5 6 7 8 9 10 11
-1 12 13 14 15 16 17 18 19 20 21 22 23
0 24 25 26 27 28 29 30 31 32 33 34 35
1 36 37 38 39 40 41 42 43 44 45 46 47
2 48 49 50 51 52 53 54 55 56 57 58 59
3 60 61 62 63 64 65 66 67 68 69 70 71
4 72 73 74 75 76 77 78 79 80 81 82 83
5 84 85 86 87 88 89 90 91 92 93 94 95
6 96 97 98 99 100 101 102 103 104 105 106 107
7 108 109 110 111 112 113 114 115 116 117 118 119
8 120 121 122 123 124 125 126 127        

So, for example, note number 69 corresponds to middle A, whereas 60 corresponds to middle C. The frequency standard is 12-EDO, and the note 69 is pegged to 440 Hz. Thus if you passed 69 as the reference note, the 69’th entry in the table would be 440 Hz and this would correspond to the first degree of the scale. 60 would cause the first degree of the scale to be assigned to that note number (with a corresponding frequency of about 261.6 Hz). The timidity soft synth is an example of a synthesizer that needs this reference note and frequency.

In general the table will need to be output to disk so that it can read by the program. This can be done with something like:

from pytuning.tuning_tables import create_timidity_tuning
from pytuning.scales import create_euler_fokker_scale

reference_note = 60
scale = create_euler_fokker_scale([3,5],[3,1])

tuning = create_timidity_tuning(scale, reference_note=reference_note)

with open("timidity.table", "w") as table:
    table.write(tuning)

This will cause the generated scale:

\left [ 1, \quad \frac{135}{128}, \quad \frac{9}{8}, \quad \frac{5}{4},
\quad \frac{45}{32}, \quad \frac{3}{2}, \quad \frac{27}{16},
\quad \frac{15}{8}, \quad 2\right ]

to be written to a disk file, timidity.table, which can be understood by timidity:

timidity -Z timidity.table score.mid

Timidity

pytuning.tuning_tables.create_timidity_tuning(scale, reference_note=60)

Create a Timidity++ tuning table

Parameters:
  • scale – The scale to model (list of frequency ratios)
  • reference_note – The MIDI number of the absolute frequency reference
Returns:

A Timidity tuning table as a String

The default value of reference_note pegs the scale to to the standard concert tuning of middle C (A = 440Hz).

The Timidity table is basically a list of integers for all defined MIDI note numbers, with each entry as 1000 times the note frequency

As a somewhat detailed example, let’s say that the user had a 12-EDO scale constructed, and wanted to pin the tonic note to the standard A440. The following will do this:

from pytuning.scales import create_edo_scale
from pytuning.tuning_tables import create_timidity_tuning

scale = create_edo_scale(12)
tuning_table = create_timidity_tuning(scale, reference_note=69) 

with the first part of the table given by:

# Timidity tuning table created by pytuning,
# call timidity with the -Z option to enable.
# Note reference: 69; Freq reference: 440.000000 Hz
8176
8662
9177
9723
10301
10913
11562
12250
12978

To use the table, one starts Timidity with the -Z option, i.e:

timidity -Z table.name -iA

Scala

The Scala tuning table can be used with the Scala package, but it can also be used to tune the soft synth Zynaddsubfx, as well as its derivative Youshimi. With the soft synths you will need to explicitly set the reference note and frequency in the scale GUI.

pytuning.tuning_tables.create_scala_tuning(scale, name)

Create a Scala scale file

Parameters:
  • scale – The scale (list of frequency ratios)
  • name – The name of the scale
Returns:

A Scala file as a String

The Scala file can be used to tune various things, most germane being Yoshimi. However, keep in mind that the Scala file does not include a base note or frequency, so for tuning purposes those data will need to be captured or input in some other way.

As an example of use, the Scala file for the default Pythagorean tuning can be calculated thus:

from pytuning.scales.pythagorean import create_pythagorean_scale
from pytuning.tuning_tables import create_scala_tuning

scale = create_pythagorean_scale()
table = create_scala_tuning(scale,"Pythagorean Tuning")

which yields:

! Scale produced by pytuning. For tuning yoshimi or zynaddsubfx,
! only include the portion below the final '!'
!
Pythagorean Tuning
12
!
256/243
9/8
32/27
81/64
4/3
1024/729
3/2
128/81
27/16
16/9
243/128
2/1

Note that the Scala file uses exact ratios where possible, otherwise it will convert to a cent value. Thus the code:

from pytuning.scales import create_edo_scale
from pytuning.tuning_tables import create_scala_tuning

scale = create_edo_scale(12)
table = create_scala_tuning(scale,"12-TET Tuning")

will produce:

! Scale produced by pytuning. For tuning yoshimi or zynaddsubfx,
! only include the portion below the final '!'
12-TET Tuning
12
!
100.00000
200.00000
300.00000
400.00000
500.00000
600.00000
700.00000
800.00000
900.00000
1000.00000
1100.00000
2/1

Fluidsynth

pytuning.tuning_tables.create_fluidsynth_tuning(scale, reference_note=60, chan=[0], bank=0, prog=[0])

Create a Fluidsynth tuning table

Parameters:
  • scale – The scale to model (list of frequency ratios)
  • reference_note – The MIDI number of the absolute frequency reference
  • chan – A list of channels for which to create the table
  • bank – The bank for the tuning table
  • prog – A list of program numbers for the tuning table
Returns:

A Fluidsynth tuning table as a String

The default value of reference_note pegs the scale to to the standard concert tuning of middle C (A = 440Hz).

The Fluidsyny tuning model allows each channel, bank, and program to have a different tuning. Thus, if one, say, wants all programs to be tuned to the scale, the tuning table can get quite large.

As a somewhat detailed example, let’s say that the user had a 12-EDO scale constructed, and wanted to pin the tonic note to the standard A440. The following will do this:

from pytuning.scales import create_edo_scale
from pytuning.tuning_tables import create_timidity_tuning

scale = create_edo_scale(12)
tuning_table = create_fluidsynth_tuning(scale, prog=range(128), reference_note=69)

with the first part of the table given by:

# Fluidsynth Tuning Table created by pytuning
# Note reference: 69; Freq reference: 440.000000 Hz
tuning tuning000 0 0
tune 0 0 0 0.000000
tune 0 0 1 100.000000
tune 0 0 2 200.000000
tune 0 0 3 300.000000
tune 0 0 4 400.000000
tune 0 0 5 500.000000
tune 0 0 6 600.000000
tune 0 0 7 700.000000
tune 0 0 8 800.000000
tune 0 0 9 900.000000

To use the table, one should start fluidsynth with the -f option:

fluidsynth -f table.name

Csound

For use in Csound PyTuning will generate a table of frequencies that can be used as a table lookup, mapped to MIDI note number. As mentioned in the basic concepts, the easiest way to use this is via the table opcode:

inote     init          p4
iveloc    init          p5
ifreq     table         inote, 1
a1        oscil         iveloc, ifreq, 2
          outs          a1, a1
pytuning.tuning_tables.create_csound_tuning(scale, reference_note=60, table_num=1)

Create a CSound tuning table

Parameters:
  • scale – The scale (list of frequency ratios)
  • reference_note – The MIDI number of the absolute frequency reference
  • table_num – The f table number to use

CSound has many ways of generating microtonalities. For pytuning a table lookup keyed on MIDI note number is used.

As an example of use, let’s say that we want to use the 12-EDO scale with the tonic at A440:

from pytuning.scales import create_edo_scale
from pytuning.tuning_tables import create_timidity_tuning

scale = create_edo_scale(12)
table = create_csound_tuning(scale, reference_note=69)

This will produce the following output, which can be included in the CSound score file:

f1 0 256 -2     8.17580     8.66196     9.17702     9.72272    10.30086    10.91338    11.56233    12.24986 \
               12.97827    13.75000    14.56762    15.43385    16.35160    17.32391    18.35405    19.44544 \
               20.60172    21.82676    23.12465    24.49971    25.95654    27.50000    29.13524    30.86771 \
               32.70320    34.64783    36.70810    38.89087    41.20344    43.65353    46.24930    48.99943 \
               51.91309    55.00000    58.27047    61.73541    65.40639    69.29566    73.41619    77.78175 \
               82.40689    87.30706    92.49861    97.99886   103.82617   110.00000   116.54094   123.47083 \
              130.81278   138.59132   146.83238   155.56349   164.81378   174.61412   184.99721   195.99772 \
              207.65235   220.00000   233.08188   246.94165   261.62557   277.18263   293.66477   311.12698 \
              329.62756   349.22823   369.99442   391.99544   415.30470   440.00000   466.16376   493.88330 \
              523.25113   554.36526   587.32954   622.25397   659.25511   698.45646   739.98885   783.99087 \
              830.60940   880.00000   932.32752   987.76660  1046.50226  1108.73052  1174.65907  1244.50793 \
             1318.51023  1396.91293  1479.97769  1567.98174  1661.21879  1760.00000  1864.65505  1975.53321 \
             2093.00452  2217.46105  2349.31814  2489.01587  2637.02046  2793.82585  2959.95538  3135.96349 \
             3322.43758  3520.00000  3729.31009  3951.06641  4186.00904  4434.92210  4698.63629  4978.03174 \
             5274.04091  5587.65170  5919.91076  6271.92698  6644.87516  7040.00000  7458.62018  7902.13282 \
             8372.01809  8869.84419  9397.27257  9956.06348 10548.08182 11175.30341 11839.82153 12543.85395