Created
November 24, 2019 15:55
-
-
Save Dagothig/a0d25d95fa6ee313cfe21a32723865d3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: utf-8 | |
""" | |
Miniature sonore à 3 voix | |
------------------------------------ | |
Vous devez créer un courte musique mettant en place 3 types de processus sonores: | |
Une voix mélodique, de type soliste. | |
Une voix de basse. | |
Une voix atmosphérique (large spectre, accord, etc.) | |
La musique doit durer entre 1 et 2 minutes et suivre une évolution temporelle composée. Il ne s'agit | |
pas de faire jouer les 3 sons, sans modifications, pendant 2 minutes. Les différents paramètres des | |
processus doivent évoluer pour créer une musique avec un début, un développement et une fin. | |
Le style musical est entièrement libre (instrumental, électroacoustique, électronique, glitch, | |
noise, « ambient », musique de yoga, etc.). | |
Aucun fichier sonore (de type WAV ou AIFF), tout doit être construit à partir de sources de synthèse | |
(catégorie Signal Generators) et d'effets (catégories Dynamic Management, Special Effects, et | |
Filters). | |
Pour créer les mouvements temporels, explorer la documentation de pyo, en particulier les catégories | |
Control Signals (enveloppes et trajectoires), Event Sequencing (appels de fonctions), Random | |
generators (générateurs aléatoires) et Sample Accurate Timing (gestion temporelle à l'aide des | |
triggers). | |
""" | |
from pyo import * | |
import random | |
import math | |
server = Server() | |
server.boot() | |
centralKey = 60 | |
si = 0 | |
scales = [ | |
[0, 2, 4, 7, 9], | |
[9, 11, 0, 4, 7], | |
[2, 4, 6, 9, 0], | |
[7, 9, 11, 2, 5]] | |
transScales = [sorted([i+centralKey+(t*12) for i in scale for t in range(-3, 5)]) for scale in scales] | |
bpm = 120 | |
blen = 60/(4*bpm) | |
dur = blen * 16 * 40 | |
main = Fader(fadein=dur/3, fadeout=dur/3, dur=dur) | |
mainEnv = Fader(fadein=blen*2, fadeout=blen*16*4, dur=dur+blen*16*4) | |
end = Fader(fadein=dur*(2/3), fadeout=blen*16*4, dur=dur+blen*16*8) | |
# Mel | |
melEnvDur = 0.2 | |
melMet = Beat(time=blen, taps=16, w1=0, w2=0, w3=0, poly=math.ceil(melEnvDur/blen)) | |
melEnv = CosTable([(0,0), (256,1), (8191,0)], size=8192) | |
melAmp = TrigEnv(melMet, table=melEnv, dur=melEnvDur, mul=melMet['amp']) | |
melFreq = TrigXnoiseMidi(melMet, dist=12, x1=1, x2=0.1+main*0.3, scale=0, mrange=(72, 92)) | |
melFreqSnap = Snap(melFreq, choice=scales[si], scale=1) | |
def melBeat(): | |
curr = main.get() | |
melMet.setWeights( | |
int(40 + curr * 30), | |
int(10 + curr * 40), | |
int(curr * 20)) | |
melMet.new() | |
melBeat() | |
def melChange(): | |
melFreqSnap.choice = scales[si] | |
if random.randrange(100) < 25: | |
melBeat() | |
melCh = TrigFunc(melMet['end'], melChange) | |
melVib = Sine(freq=[4, 4.89], mul=.02, add=1) | |
melLfo = Blit(freq=melFreqSnap/2, harms=4+main*4, mul=melAmp*(0.15+main*0.05)) | |
melDel = Delay(melLfo, delay=end*blen*3, feedback=end*0.5) | |
# Bas | |
basMet = Metro(blen) | |
basC = Counter(basMet, min=0, max=16) | |
basS = Select(basC, value=14) | |
basPort = VarPort(value = midiToHz(scales[si][0]+centralKey), time=blen*2) | |
basEnv = LinTable([(0,0), (2048,1), (3072, 0.7), (7168, 0.5), (8191,0)], size=8192) | |
basAmp = TrigEnv(basS, table=basEnv, dur=blen*16) | |
def basChange(): | |
global si | |
si = max(0, si + random.choice([-1, 0, 0, 1, 1, 1, 1])) % len(scales) | |
note = scales[si][0] | |
basPort.value = midiToHz(note+centralKey) | |
basCh = TrigFunc(basS, basChange) | |
basTremFreq = FastSine(freq=1/(blen*16), initphase=0.75).range(0.25, 8) | |
basTrem = FastSine(freq=basTremFreq).range(0.97, 1.01) | |
basLfo = Blit( | |
freq=basPort/2*basTrem, | |
harms=3+main*3, | |
mul=0.05+basAmp*0.05) | |
# atm | |
atmEnvDur = blen * 32 | |
atmMet = Beat(time=blen*2, taps=8, w1=0, w2=0, w3=0) | |
atmEnv = LinTable([(0,1), (2048,1), (2049,0), (8191,0)], size=8192) | |
atmAmp = TrigEnv(atmMet, table=atmEnv, dur=atmEnvDur) | |
atmAmpPort = Port(atmAmp, risetime=atmEnvDur/4, falltime=atmEnvDur/4) | |
atmFreq = VarPort(value=[0]*3, time=0.05) | |
atmLfo = Sine(atmFreq, mul=0.2*atmAmpPort) | |
clampedScales = [list(filter(lambda x: x >= 56 and x <= 74, scale)) for scale in transScales] | |
def atmTap(): | |
scale = clampedScales[si] | |
l = len(scale) | |
i1 = random.randrange(l) | |
i2 = (i1 + random.randint(1, 3)) % l | |
i3 = (i1 - random.randint(1, 3) + l) % l | |
atmFreq[0].setValue(midiToHz(scale[i1])) | |
atmFreq[1].setValue(midiToHz(scale[i2])) | |
atmFreq[2].setValue(midiToHz(scale[i3])) | |
atmTap = TrigFunc(atmMet, atmTap) | |
atmCount = 0 | |
def atmChange(): | |
global atmCount | |
atmCount += 1 | |
if atmCount == 8: | |
atmMet.setWeights(30, 20, 0) | |
atmMet.new() | |
if atmCount == 16: | |
atmMet.setWeights(70, 40, 10) | |
atmMet.new() | |
if random.randrange(100) < 25: | |
atmMet.new() | |
atmCh = TrigFunc(atmMet['end'], atmChange) | |
# Final mix | |
prevRev = Mix(melDel + basLfo + atmLfo) | |
rev = WGVerb(prevRev, feedback=0.8-main*0.4) | |
mix = Mix(rev, voices=2, mul=mainEnv*0.5).out() | |
main.play() | |
end.play() | |
mainEnv.play() | |
melMet.play() | |
atmMet.play() | |
basMet.play() | |
server.gui(locals()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment