surge-synthesizer / tuning-library

Micro-tuning format parsing and frequency finding as a header-only C+ library
https://surge-synth-team.org/tuning-library/
MIT License
84 stars 15 forks source link

Support TUNV1 #14

Open baconpaul opened 4 years ago

baconpaul commented 4 years ago

https://www.mark-henning.de/files/am/tuning.zip is the TUN v1 spec

There is a TUN V2 spec. This library https://github.com/zardini123/AnaMark-Tuning-Library supports it.

mkruselj commented 4 years ago

Here's a few .tun files (v1) for testing.

tun mini library.zip

baconpaul commented 4 years ago

TUN.zip

That's @JackyLigon files which match the surge tuning library are all mapped with the 1/1 and Reference Pitch on middle C.60 @ 262 Hz as tun

baconpaul commented 4 years ago

From the Tuning v1 document

Section [Tuning]

This section contains a relative quantized tune in cents given for each MIDI note number from 0 - 127. The parameter name is "note #", whereas # stands for the MIDI note number. The default value for each parameter is (100*MIDI_Note_Number). There is no setting for the absolute frequency of note 0. The tunes are integer numbers and must not contain a '.', nor be written in scientific notation! Each one of the 128 notes has to be set. If a note is missing, this may produce a warning and the note's tuning is set to the default. Example for a valid "[Tuning]" section, which shows the default settings:

    [Tuning]
    note 0 = 0
    note 1 = 100
    note 2 = 200
    ; This has to be continued for each one of the notes
    ; in the range 3-127, including 127

Section [Exact Tuning]

Similar to the section "Tuning". Differences: The optional parameter "basefreq" specifies the absolute frequency of note 0. Its default value is 8.1757989156437073336Hz, which corresponds to the A=440Hz-tuning. ('A' is note 69.) The tunes may be given in integer, floating point oder scientific representation, so they are much more exact. Examples for valid numbers: "583", "-143.23", "0.837e4" Not each MIDI note number has to be given. Note numbers <0 or >127 are generally possible in the future, but must be ignored in the current version of this format (in the following, they are treated as not-existing). If no MIDI note number is given, keep the default tuning (100MIDI_Note_Number). Let H be the highest MIDI note number given, let P be its tune given in the file (called P, because it's the period length). t(x) is the current tune value of the note with the MIDI note number x, which is initially set to the values given in the file. First set the tunes t(x) of all MIDI notes in the range [0; H] which are not given in the file to the default value (100x). Then fill in the values [H;127] according to this algorithm:

if ( H < 127 ) then 
    from i=H to i=127 including 127, stepsize 1 do: 
        Let f(i) = f(i-H) + P 
    end from 
end if

Note, that f(0) is not necessarily set to 0! Example for a valid "[Exact Tuning]" section:

    ; All 'E' should be tuned +12.5 cents compared with
    ; the default scale. All other notes should have the
    ; default tuning.
    [Exact Tuning]
    note 4 = 412.5
    ; To let the period be one octave, we have to set the "periodic point":
    note 12 = 1200