Ejemplo n.º 1
0
    a = tone(hz, t)
    hi = tone(2*hz, t)
    lo = tone(hz/2, t)
    h = superpose(hi, lo, .5, .5)
    return superpose(a, h, .5, .5)

#-----------------------------------------------------------------------

# Read sound samples from standard input, add harmonics, and play
# the resulting the sound to standard audio.

while not stdio.isEmpty():
    pitch = stdio.readInt()
    duration = stdio.readFloat()
    a = note(pitch, duration)
    stdaudio.playArray(a)
stdaudio.wait()

#-----------------------------------------------------------------------

# python playthattunedeluxe.py < ascale.txt

# python playthattunedeluxe.py < elise.txt

# python playthattunedeluxe.py < entertainer.txt

# python playthattunedeluxe.py < firstcut.txt

# python playthattunedeluxe.py < freebird.txt

# python playthattunedeluxe.py < looney.txt
Ejemplo n.º 2
0
# standard audio.

SPS = 44100
CONCERT_A = 440.0
NOTES_ON_SCALE = 12.0

while not stdio.isEmpty():

    pitch = stdio.readInt()
    duration = stdio.readFloat()
    hz = CONCERT_A * (2.0 ** (pitch / NOTES_ON_SCALE))
    n = int(SPS * duration)
    note = stdarray.create1D(n+1, 0.0)
    for i in range(n+1):
        note[i] = math.sin(2.0 * math.pi * i * hz / SPS)
    stdaudio.playArray(note)

stdaudio.wait()

#-----------------------------------------------------------------------

# python playthattune.py < elise.txt

# python playthattune.py < ascale.txt

# python playthattune.py < entertainer.txt

# python playthattune.py < firstcut.txt

# python playthattune.py < freebird.txt