Skip to content

Instantly share code, notes, and snippets.

@Dagothig
Created October 31, 2019 13:16
Show Gist options
  • Save Dagothig/133cdabb6ce4807bf2c34e8b9ae96a9d to your computer and use it in GitHub Desktop.
Save Dagothig/133cdabb6ce4807bf2c34e8b9ae96a9d to your computer and use it in GitHub Desktop.
SHREKT TON CPU
from pyo import *
import random
import math
server = Server()
server.boot()
play_dur = 0.125
# Instrument de synthèse
note_dur = 0.1
note_fadein = 0.01
note_fadeout = 0.01
req = math.ceil((note_dur + note_fadein + note_fadeout) / play_dur)
src = [Sine(mul=[0,0,0,0]) for _ in range(req)]
fader = [Fader(fadein=note_fadein, fadeout=note_fadeout, dur=note_dur) for _ in range(req)]
for f in fader:
f.exp = 3
shiftFreq = Randi(min=0.125, max=12.0, freq=0.6)
shift = LFO(
type=0,
freq=1/shiftFreq,
add=[0.75, 0.5, 0.0],
mul=[0.5, 1.0, 2.0])
cur_note = 0
def play_note(freq, mul):
global cur_note
fader[cur_note].play()
# === ICI ÇA SHREKT TON CPU === #
src[cur_note].freq = [freq] + freq * shift
src[cur_note].mul = [mul * 0.15 * (i - 4)/4 for i in (range(4))] * fader[cur_note]
cur_note = (cur_note + 1) % req
mix = Mix(src, mul=0.75)
delay = Delay(mix, delay=1)
reverb = WGVerb([mix, delay], mul=0.5, bal=0.4, feedback=0.7, cutoff=3500).out()
# Génération mélodique
ton1 = 60
ton2 = 60 + 9
ton3 = 60 + 2
ton4 = 60 + 7
notes = [
ton1, ton1 + 5, ton1 + 7, ton1 + 11,
ton2, ton2 + 3, ton2 + 6, ton2 + 10,
ton3, ton3 + 3, ton3 + 7, ton3 + 9,
ton4, ton4 + 4, ton4 + 7, ton4 + 10]
freqs = midiToHz(notes)
beat = 0
def play():
global beat
start = beat % len(freqs)
end = (beat + 3) % len(freqs)
sliding = freqs[start:end] if start < end else freqs[0:end] + freqs[start:len(freqs)]
play_note(
freq = random.choice(sliding),
mul = 1.0 if beat % 4 == 0 else 0.25)
beat = beat + 1
pattern = Pattern(play, time=play_dur).play()
server.gui(locals())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment