Skip to content

Instantly share code, notes, and snippets.

@jacobjoaquin
Created September 22, 2010 16:07
Show Gist options
  • Save jacobjoaquin/591985 to your computer and use it in GitHub Desktop.
Save jacobjoaquin/591985 to your computer and use it in GitHub Desktop.
Four ways for doing Twelve-tone Equal Temperament
Jacob Joaquin
September 22, 2010
[email protected]
csoundblog.com
<CsoundSynthesizer>
<CsInstruments>
sr = 44100
kr = 4410
ksmps = 10
nchnls = 1
0dbfs = 1
gisine ftgen 1, 0, 8192, 10, 1
; Hertz
instr 1
ifreq = p4
a1 foscil 0.707, ifreq, 1, 1, 1, gisine
out a1
endin
; cpspch
instr 2
ipch = cpspch(p4)
a1 foscil 0.707, ipch, 1, 1, 1, 1
out a1
endin
; Half step (relative to A440)
instr 3
ihalf_step = 440 * 2 ^ (p4 / 12)
a1 foscil 0.707, ihalf_step, 1, 1, 1, 1
out a1
endin
; MIDI note
instr 4
imidi_note = 440 * 2 ^ ((p4 - 69) / 12)
a1 foscil 0.707, imidi_note, 1, 1, 1, 1
out a1
endin
</CsInstruments>
<CsScore>
t 0 120
; Hertz
i 1 0 0.5 440
i 1 + . 880
i 1 + . 783.946655
i 1 + . 698.436707
i 1 + . 659.217957
i 1 + . 587.312988
i 1 + . 554.333984
i 1 + . 466.137451
; cpspch
i 2 4 0.5 8.09
i 2 + . 9.09
i 2 + . 9.07
i 2 + . 9.05
i 2 + . 9.04
i 2 + . 9.02
i 2 + . 9.01
i 2 + . 8.10
; Half step (relative to A440)
i 3 8 0.5 0
i 3 + . 12
i 3 + . 10
i 3 + . 8
i 3 + . 7
i 3 + . 5
i 3 + . 4
i 3 + . 1
; MIDI note
i 4 12 0.5 69
i 4 + . 81
i 4 + . 79
i 4 + . 77
i 4 + . 76
i 4 + . 74
i 4 + . 73
i 4 + . 70
</CsScore>
</CsoundSynthesizer>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment