semitone
Prev | Orchestra Opcodes and Operators | Next

## semitone

semitone — Calculates a factor to raise/lower a frequency by a given amount of semitones.

## Description

Calculates a factor to raise/lower a frequency by a given amount of semitones.

## Syntax

    semitone(x)

This function works at a-rate, i-rate, and k-rate.

## Initialization

x -- a value expressed in semitones.

## Performance

The value returned by the semitone function is a factor. You can multiply a frequency by this factor to raise/lower it by the given amount of semitones.

## Examples

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

Example 701. Example of the semitone 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
    -odac      ;;;realtime audio out
    ;-iadc    ;;;uncomment -iadc if realtime audio input is needed too
    ; For Non-realtime ouput leave only the line below:
    ; -o semitone.wav -W ;;; for file output any platform
    </CsOptions>
    <CsInstruments>

    sr = 44100
    ksmps = 32
    nchnls = 2
    0dbfs  = 1

    instr 1

    iroot = 440		; root note is A above middle-C (440 Hz)
    ksem  lfo 12, .5, 5	; generate sawtooth, go from 5 octaves higher to root
    ksm = int(ksem)		; produce only whole numbers
    kfactor = semitone(ksm)	; for semitones
    knew = iroot * kfactor
    printk2 knew
    printk2 kfactor
    asig pluck 1, knew, 1000, 0, 1
    asig dcblock asig	;remove DC
         outs asig, asig

    endin
    </CsInstruments>
    <CsScore>

    i 1 0 5
    e

    </CsScore>
    </CsoundSynthesizer>

Its output should include lines like:

     i1   880.00000
     i1     2.00000
     i1   830.65625
     i1     1.88786
     i1   783.94665
     i1     1.78170
     i1   739.98885
     i1     1.68179
     i1   698.49586
     i1     1.58749
     i1   659.21793
     i1     1.49822
     i1   622.25397
     i1     1.41421
     i1   587.36267
     i1     1.33492
     i1   554.33399
     i1     1.25985
     i1   523.25113
     i1     1.18921
     i1   493.91116
     i1     1.12253
     i1   466.13747
     i1     1.05940
     i1   440.00000
     i1     1.00000
    .......

## See Also

cent, db, octave

## Credits

New in version 4.16

Prev | Up | Next
sekere | Home | sense