The Alternative Csound Reference Manual
Previous |  | Next

# cpsoct

cpsoct -- Converts an octave-point-decimal value to cycles-per-second.

## Description

Converts an octave-point-decimal value to cycles-per-second.

## Syntax

cpsoct (oct) (no rate restriction)

where the argument within the parentheses may be a further expression.

## Performance

These are really value converters with a special function of manipulating pitch data.

Data concerning pitch and frequency can exist in any of the following forms:

Table 1. Pitch and Frequency Values

Name | Abbreviation
--- | ---
octave point pitch-class (8ve.pc) | pch
octave point decimal | oct
cycles per second | cps

The first two forms consist of a whole number, representing octave registration, followed by a specially interpreted fractional part. For pch, the fraction is read as two decimal digits representing the 12 equal-tempered pitch classes from .00 for C to.11 for B. For oct, the fraction is interpreted as a true decimal fractional part of an octave. The two fractional forms are thus related by the factor 100/12. In both forms, the fraction is preceded by a whole number octave index such that 8.00 represents Middle C, 9.00 the C above, etc. Thus A440 can be represented alternatively by 440 (cps),8.09 (pch), or 8.75 (oct). Microtonal divisions of the pch semitone can be encoded by using more than two decimal places.

The mnemonics of the pitch conversion units are derived from morphemes of the forms involved, the second morpheme describing the source and the first morpheme the object (result). Thus cpspch(8.09) will convert the pitch argument 8.09 to its cps (or Hertz) equivalent, giving the value of 440. Since the argument is constant over the duration of the note, this conversion will take place at i-time, before any samples for the current note are produced.

By contrast, the conversion cpsoct(8.75 + k1) which gives the value of A440 transposed by the octave interval k1. The calculation will be repeated every k-period since that is the rate at which k1 varies.

| Note
| The conversion from pch or oct into cps is not a linear operation but involves an exponential process that could be time-consuming when executed repeatedly. Csound now uses a built-in table lookup to do this efficiently, even at audio rates.

## Examples

Here is an example of the cpsoct opcode. It uses the files cpsoct.orc and cpsoct.sco.

Example 1. Example of the cpsoct opcode.

    /* cpsoct.orc */
    ; Initialize the global variables.
    sr = 44100
    kr = 4410
    ksmps = 10
    nchnls = 1

    ; Instrument #1.
    instr 1
      ; Convert an octave-point-decimal value into a
      ; cycles-per-second value.
      ioct = 8.75
      icps = cpsoct(ioct)

      print icps
    endin
    /* cpsoct.orc */

    /* cpsoct.sco */
    ; Play Instrument #1 for one second.
    i 1 0 1
    e
    /* cpsoct.sco */

Its output should include lines like this:

    instr 1:  icps = 440.000

## See Also

cpspch, octcps, octpch, pchoct

## Credits

Example written by Kevin Conder.

Previous | Home | Next
cpsmidib | Up | cpspch