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 420. 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
; Audio out   Audio in
-odac           -iadc    ;;;RT audio I/O
; For Non-realtime ouput leave only the line below:
; -o semitone.wav -W ;;; for file output any platform
</CsOptions>
<CsInstruments>

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

; Instrument #1.
instr 1
  ; The root note is A above middle-C (440 Hz)
  iroot = 440

  ; Raise the root note by three semitones to C.
  isemitone = 3

  ; Calculate the new note.
  ifactor = semitone(isemitone)
  inew = iroot * ifactor

  ; Print out all of the values.
  print iroot
  print ifactor
  print inew
endin


</CsInstruments>
<CsScore>

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


</CsScore>
</CsoundSynthesizer>


Its output should include lines like:

instr 1:  iroot = 440.000
instr 1:  ifactor = 1.189
instr 1:  inew = 523.229

See Also

cent, db, octave

Credits

Example written by Kevin Conder.

New in version 4.16