cpstun
Prev | Orchestra Opcodes and Operators | Next

## cpstun

cpstun — Returns micro-tuning values at k-rate.

## Description

Returns micro-tuning values at k-rate.

## Syntax

    kcps cpstun ktrig, kindex, kfn

## Performance

kcps -- Return value in cycles per second.

ktrig -- A trigger signal used to trigger the evaluation.

kindex -- An integer number denoting an index of scale.

kfn -- Function table containing the parameters (numgrades, interval, basefreq, basekeymidi) and the tuning ratios.

These opcodes are similar to cpstmid, but work without necessity of MIDI.

cpstun works at k-rate. It allows fully customized micro-tuning scales. It requires a function table number containing the tuning ratios, and some other parameters stored in the function table itself.

kindex arguments should be filled with integer numbers expressing the grade of given scale to be converted in cps. In cpstun, a new value is evaluated only when ktrig contains a non-zero value. The function table kfn should be generated by GEN02 and the first four values stored in this function are parameters that express:

- numgrades -- The number of grades of the micro-tuning scale.

- interval -- The frequency range covered before repeating the grade ratios, for example 2 for one octave, 1.5 for a fifth etcetera.

- basefreq -- The base frequency of the scale in cycles per second.

- basekey -- The integer index of the scale to which to assign basefreq unmodified.

After these four values, the user can begin to insert the tuning ratios. For example, for a standard 12-grade scale with the base-frequency of 261 cps assigned to the key-number 60, the corresponding f-statement in the score to generate the table should be:

    ;           numgrades    basefreq     tuning-ratios (eq.temp) .......
    ;                  interval    basekey
    f1 0 64 -2  12     2     261   60     1   1.059463 1.12246 1.18920 ..etc...

Another example with a 24-grade scale with a base frequency of 440 assigned to the key-number 48, and a repetition interval of 1.5:

    ;                  numgrades       basefreq      tuning-ratios .......
    ;                          interval       basekey
    f1 0 64 -2         24      1.5     440    48     1   1.01  1.02  1.03   ..etc...

## Examples

Here is an example of the cpstun opcode. It uses the file cpstun.csd.

Example 182. Example of the cpstun opcode.

See the sections Real-time Audio and Command Line Flags for more information on using command line flags.

    <CsoundSynthesizer>
    <CsOptions>
    ; Select audio/midi flags here according to platform
    ; Audio out   Audio in
    -odac           -iadc    ;;;RT audio I/O
    ; For Non-realtime ouput leave only the line below:
    ; -o cpstun.wav -W ;;; for file output any platform
    </CsOptions>
    <CsInstruments>

    ; Initialize the global variables.
    sr = 44100
    kr = 4410
    ksmps = 10
    nchnls = 1

    ; Table #1, a normal 12-tone equal temperament scale.
    ; numgrades = 12 (twelve tones)
    ; interval = 2 (one octave)
    ; basefreq = 261.659 (Middle C)
    ; basekeymidi = 60 (Middle C)
    gitemp ftgen 1, 0, 64, -2, 12, 2, 261.659, 60, 1.00, \
                 1.059, 1.122, 1.189, 1.260, 1.335, 1.414, \
                 1.498, 1.588, 1.682, 1.782, 1.888, 2.000

    ; Instrument #1.
    instr 1
      ; Set the trigger.
      ktrig init 1

      ; Use Table #1.
      kfn init 1

      ; If the base key (note #60) is C, then 9 notes
      ; above it (note #60 + 9 = note #69) should be A.
      kindex init 69

      k1 cpstun ktrig, kindex, kfn

      printk2 k1
    endin

    </CsInstruments>
    <CsScore>

    ; Play Instrument #1 for one second.
    i 1 0 1
    e

    </CsScore>
    </CsoundSynthesizer>

Its output should include lines like this:

    i1   440.11044

## See also

Pitch Converters: Tuning Opcodes

## Credits

Example written by Kevin Conder.

Prev | Up | Next
cpstmid | Home | cpstuni