import random score = open('C:\csound\csds\oscil contest.sco','w') random.seed(1) noteStart = 0.1 noteDur = 0.2 noteVol = 0 noteFstr = 0 noteFend = 0 noteAtt = 0 notePstr = 0 notePend = 0 lowFrqLimit = 40 highFrqLimit = 16000 i = 0 def addNote(nStr,nDur,nVol,nFstr,nFend,nAtt,nPstr,nPend): nFend = int(nFend) note = 'i1\t %f \t %f \t %d \t %d \t %d \t %.3f \t %.3f \t %.3f \n' % (nStr,nDur,nVol,nFstr,nFend,nAtt,nPstr,nPend) score.write(note) # First Section (many grains to descrete notes # score.write('\n;Section 1;\n\n') while i < 150: noteStart *= 1.03 noteDur *= 1.005 noteVol = random.randint(2000,10000) noteFstr = random.randint(lowFrqLimit,highFrqLimit) noteFend = noteFstr * random.random() noteAtt = noteDur * 0.5 notePstr = 0.001 * random.randint(0,1000) notePend = 0.001 * random.randint(0,1000) addNote(noteStart,noteDur,noteVol,noteFstr,noteFend,noteAtt,notePstr,notePend) i += 1 # Second Section Frequency range narrows to 441 score.write('\n;Section 2;\n\n') while lowFrqLimit < highFrqLimit: noteStart += random.random() noteDur *= 1.01 noteVol = random.randint(3000,15000) noteFstr = random.randint(int(lowFrqLimit),int(highFrqLimit)) noteFend = noteFstr noteAtt = noteDur * 0.5 notePstr = 0.001 * random.randint(0,1000) notePend = notePstr addNote(noteStart,noteDur,noteVol,noteFstr,noteFend,noteAtt,notePstr,notePend) lowFrqLimit *= 1.05 highFrqLimit *= 0.93 while lowFrqLimit > highFrqLimit: noteStart += random.random() noteDur *= 1.03 noteVol = random.randint(3000,15000) noteFstr = random.randint(int(highFrqLimit),int(lowFrqLimit)) noteFend = noteFstr noteAtt = noteDur * 0.5 notePstr = 0.001 * random.randint(0,1000) notePend = notePstr addNote(noteStart,noteDur,noteVol,noteFstr,noteFend,noteAtt,notePstr,notePend) lowFrqLimit *= 0.997 highFrqLimit *= 1.003 #Third Section Cloud of harmonics on 441 score.write('\n;Section 3;\n') score.write(';Fundamental\n') i = 0 while i<100: noteStart += random.random() + random.random() if i<50: noteDur *= 1.01 else: noteDur *= 0.99 noteVol = random.randint(3000,8000) noteFstr = 441 noteFend = 441 noteAtt = noteDur * 0.5 notePstr = 0.001 * random.randint(0,1000) notePend = notePstr addNote(noteStart,noteDur,noteVol,noteFstr,noteFend,noteAtt,notePstr,notePend) i += 1 score.write('\n\n;Harmonics\n') noteStart = 42 i = 0 frqList = [55.125,110.25,220.5,882,1323,1764,2205,2646,3087,3528,3969,4410, 4851,5292,5733,6174,6615,7056,7497,7938,8379,8820,9261,9702,10143] while i<90: noteStart += random.randint(0,2) + random.random() if i<12: noteDur = random.randint(0,4) + random.random() elif i<25: noteDur = random.randint(1,5) + random.random() elif i<37: noteDur = random.randint(2,6) + random.random() elif i<50: noteDur = random.randint(3,7) + random.random() else: noteDur = random.randint(4,8) + random.random() noteVol = random.randint(3000,8000) noteFstr = random.choice(frqList) noteFend = noteFstr noteAtt = noteDur * 0.3 notePstr = 0.001 * random.randint(0,1000) notePend = notePstr addNote(noteStart,noteDur,noteVol,noteFstr,noteFend,noteAtt,notePstr,notePend) i += 1 #Fourth Section Growing Grain cloud on harmonics of 441 score.write('\n;Section 4.0\n') i = 0 frqList.append(441) noteStartDecrement = 1 noteStart = 142 noteDur = 1 while i < 250: noteStart = noteStart + noteStartDecrement noteDur *= 0.999 noteVol = random.randint(2000,5000) noteFstr = random.choice(frqList) noteFend = noteFstr noteAtt = noteDur * 0.5 notePstr = 0.001 * random.randint(0,1000) notePend = 0.001 * random.randint(0,1000) addNote(noteStart,noteDur,noteVol,noteFstr,noteFend,noteAtt,notePstr,notePend) i += 1 noteStartDecrement *= 0.98 score.write('\n;Section 4.1\n') noteStartGap = noteStartDecrement while noteDur > 0.21: noteStart = noteStart + noteStartGap noteDur *= 0.999 noteVol = random.randint(2000,5000) noteFstr = random.choice(frqList) noteFend = noteFstr noteAtt = noteDur * 0.5 notePstr = 0.001 * random.randint(0,1000) notePend = 0.001 * random.randint(0,1000) addNote(noteStart,noteDur,noteVol,noteFstr,noteFend,noteAtt,notePstr,notePend) score.write('\n;Section 4.2\n') i = 0 while i < 2000: noteStart = noteStart + noteStartGap if i < 250: noteVol = random.randint(2000,8000) elif i < 500: noteVol = random.randint(2000,7000) elif i < 750: noteVol = random.randint(2000,6000) elif i < 1000: noteVol = random.randint(2000,5000) elif i < 1250: noteVol = random.randint(1500,4000) elif i < 1500: noteVol = random.randint(1000,3000) elif i < 1750: noteVol = random.randint(500,2000) else: noteVol = random.randint(10,1000) noteFstr = random.choice(frqList) noteFend = noteFstr noteAtt = noteDur * 0.5 notePstr = 0.001 * random.randint(0,1000) notePend = 0.001 * random.randint(0,1000) addNote(noteStart,noteDur,noteVol,noteFstr,noteFend,noteAtt,notePstr,notePend) i += 1 score.write('\n\ne\n') score.close()