cpstuni
Prev | Orchestra Opcodes and Operators | Next

## cpstuni

cpstuni — Returns micro-tuning values at init-rate.

## Description

Returns micro-tuning values at init-rate.

## Syntax

    icps cpstuni index, ifn

## Initialization

icps -- Return value in cycles per second.

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

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

## Performance

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

cpstuni works at init-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.

The index argument should be filled with integer numbers expressing the grade of given scale to be converted in cps. The function table ifn 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 cpstuni opcode. It uses the file cpstuni.csd.

Example 179. Example of the cpstuni 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 cpstuni.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
      ; Use Table #1.
      ifn = 1

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

      i1 cpstuni index, ifn

      print i1
    endin

    </CsInstruments>
    <CsScore>

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

    </CsScore>
    </CsoundSynthesizer>

Its output should include lines like this:

    instr 1:  i1 = 440.110

## See Also

cpstmid, cpstun, GEN02

## Credits

Written by Gabriel Maldonado.

Example written by Kevin Conder.

Prev | Up | Next
cpstun | Home | cpsxpch