Monday, July 10, 2017

ex1B02. Adding vs ratio

In music frequency ratios are important, such as frequency and 3/2 of that frequency (perfect fifth), and frequency and double the frequency (octave).


# ex1B02.py
# Adding vs ratio

from moduleCsound import *

tags(1)

header(ksmps=32)

# raw string \n and \ passed to csound
# we can also write \\n and \\ and not have r
# but it is eaier to put r""" for every string,
# even those without any \ character

add(r"""
instr 1
        prints  "Playing %d Hertz!\n", p4
asig    oscils  .2, p4, 0
        outs    asig, asig
endin

instr 2
        prints  "Adding %d Hertz to %d Hertz!\n", p5, p4
asig    oscils  .2, p4+p5, 0
        outs    asig, asig
endin

instr 3
        prints  "Applying the ratio of %f (adding %d Hertz) \
                 to %d Hertz!\n", p5, p4*p5, p4
asig    oscils  .2, p4*p5, 0
        outs    asig, asig
endin
""")

tags(2)

# intervals of fifths (3/2 freq) applied on instrument 3

add("""
;adding a certain frequency (instr 2)
i 1 0 1 100
i 2 1 1 100 100
i 1 3 1 400
i 2 4 1 400 100
i 1 6 1 800
i 2 7 1 800 100
;applying a certain ratio (instr 3)
i 1 10 1 100
i 3 11 1 100 [3/2]
i 1 13 1 400
i 3 14 1 400 [3/2]
i 1 16 1 800
i 3 17 1 800 [3/2]
""")

tags(3)

writeRun(__file__)

No comments:

Post a Comment

ex3A05. Audio Vector