def test_create_tukey(self): length = 10 shape = dsp.win(shapes.win('sine', length=3), 0, 0.5) chord = tune.chord('i9', octave=2) out = dsp.buffer(length=length) for freq in chord: freq = dsp.wt('sinc', freq, freq*4) l = Tukey(freq=freq, shape=shape).play(length) l = l.pan(dsp.rand()) out.dub(l) out = fx.norm(out, 0.8) out.write('tests/renders/osc_tukey.wav')
def arp(i): cluster = dsp.buffer() length = random.randint(44100, 44100 + 22050) numnotes = random.randint(3, 12) onsets = rhythm.curve(numnotes, dsp.RND, length) chord = chords[i % len(chords)] freqs = tune.chord(chord, octave=random.randint(1, 3)) for i, onset in enumerate(onsets): freq = freqs[i % len(freqs)] note = samp.play(freq) note = note.pan(random.random()) note *= random.triangular(0, 0.125) cluster.dub(note, onset / cluster.samplerate) return cluster
def makeArps(length, beat, cname): freqs = tune.chord(cname, key, dsp.randint(1,4)) tone = Sampler(snds.load('tones/nick.wav'), direction='fw-bw-loop', tails=False) freqs = dsp.randshuffle(freqs) beat = int((beat * 2) / dsp.randchoose([0.5, 1, 2, 3, 1.5])) numbeats = length / beat out = '' for i in range(numbeats): out += tone.play(freqs[i % len(freqs)], beat) out = dsp.fill(out, length) out = fx.penv(out) return out
def makesynths(): out = dsp.buffer(length=1) beat = length // 2 numbeats = 16 * 8 * lenmult pat = rhythm.topattern('x..x....') onsets = rhythm.onsets(pat, beat, numbeats) for i, pos in enumerate(onsets): chord = chords[i % len(chords)] freqs = tune.chord(chord) for freq in freqs: lfo = random.random() * i * 0.5 note = makenote(random.randint(length // 4, length * 3), freq * 0.25 * 2**random.randint(0, 4), lfo, factor=random.randint(1, 10)) note = note.env('phasor') note = note.pan(random.random()) out.dub(note * 0.65, pos) return out
def makeblips(): out = dsp.buffer(length=1) beat = length // 2 numbeats = 16 * 8 * lenmult pat = rhythm.topattern('x..x..x.') onsets = rhythm.onsets(pat, beat, numbeats) for i, pos in enumerate(onsets): chord = chords[i*2 % len(chords)] freqs = tune.chord(chord) lfo = random.random() * 2 freq = freqs[0] * 0.5 if i % 8 == 0: freq *= 2 note = makenote(length, freq, lfo, factor=random.randint(1, 10)) note = note.env('phasor') out.dub(note * 2, pos) return out
def makearps(): out = dsp.buffer(length=1) beat = length // 2 numbeats = 16 * 8 * lenmult pat = rhythm.topattern('xxxxxxxx') onsets = rhythm.onsets(pat, beat, numbeats) osc = oscs.Osc('tri') for i, pos in enumerate(onsets): chord = chords[i//4 % len(chords)] freqs = tune.chord(chord) freq = freqs[i % len(freqs)] amp = random.triangular(0.1, 0.2) pw = random.triangular(0.15, 1) note = osc.play(beat, freq * 2, amp * 0.25, pw) note = note.env('phasor') out.dub(note, pos) return out
def makeSwells(cname, numswells, length, key='e', octave=1): swells = [] freqs = tune.chord(cname, key, octave) root = tune.ntf(key, octave) # Naive pitch wrapping for i, freq in enumerate(freqs): if freq > root * 2.5: freqs[i] = freq * 0.5 for _ in range(numswells): slength = dsp.randint((length / numswells) * 0.85, length / numswells) swell = [ keys.pulsar(freq, slength, drift=dsp.rand(0.001, 0.01), speed=dsp.rand(0.1, 0.5), amp=dsp.rand(0.2, 0.5)) for freq in freqs ] swell = dsp.mix(swell) swell = dsp.env(swell, 'hann') swell = dsp.taper(swell, 30) swells += [ swell ] swells = [ dsp.fill(swell, length / numswells, silence=True) for swell in swells ] return ''.join(swells)
layers += [ kicks ] if canPlay('smashes', section): sm = dsp.fill(smash, dsp.flen(bar)) sm = dsp.mix([ dsp.alias(sm), fx.penv(sm) ]) sm = dsp.amp(sm, dsp.rand(0.5, 2)) sk = dsp.fill(skitter, dsp.flen(bar)) sk = fx.penv(sk) layers += [ sm, sk ] if count % 4 == 0: layers += [ dsp.pad(flam, dsp.flen(bar) - dsp.flen(flam), 0) ] if canPlay('bloops', section): bfreqs = tune.chord(cname, key, 2) bloopp = 'x.x.--------' if dsp.rand() > 0.5 else 'xxx.--------' bloopp = bloopp if dsp.rand() > 0.65 else 'xxx.----' pattern = ctl.parseBeat(bloopp) bloops = ctl.makeBeat(pattern, [ beat / 2 for _ in range(16) ], makeBloop, bfreqs) layers += [ bloops ] if canPlay('arps', section): arpses = dsp.mix([ makeArps(dsp.flen(bar), beat, cname) for _ in range(dsp.randint(2,4)) ]) layers += [ arpses ] if section not in ('intro', 'ending'): rfreqs = tune.chord(cname, key, 2) maxbend = 0.005 if dsp.rand() > 0.3 else 0.05 rhodeses = makeRhodes(dsp.flen(bar), beat, rfreqs, maxbend)
# # xaxis = ny.arange(samples, dtype=ny.float) # ydata = volume * ny.sin(xaxis * omega) # # blanks填充获取numpy数字信号 # signal = ny.resize(ydata, (samples, )) # scipy.io.wavfile.write('test.wav', samplerate, signal) # # ################################################################## #读取test.wav文件 raw = dsp.read('test.wav') ########## 输入原先创建的正弦波,通过pippi创建一个C3调谐 ############## # freqs = tune.chord('I', key='C', octave=3, ratios=tune.just) # original_freq = tune.ntf('A1') # speeds = [new_freq / original_freq for new_freq in freqs] # pos = 0 # beat = 1.5 # out = dsp.buffer() # #参考:https://pippi.world/docs/tutorials/001-soundbuffers/ # for speed in speeds: # # 创建原始输入文件音高偏移副本 # note = raw.speed(speed) # # # 复制到输出缓冲区中 # out.dub(note, pos) # # # 复制高八度副本 # note = raw.speed(speed * 2) #
def get_freqs(count): # mahjong by wayne shorter chords = (['i11', 'VII69'] * 6) + (['VI9', 'VII69'] * 4) + (['VI7', 'vii7', 'III7', 'VI9', 'vi7', 'II7']) + (['i11', 'VII69'] * 6) chords = ['i','i','i','I','I','I69','i','i','i'] return tune.chord(chords[count % len(chords)], octave=2)
def make_wavetable(): wtsize = random.randint(2, random.randint(3, 50)) wavetable = [0] + [random.triangular(-1, 1) for _ in range(wtsize - 2)] + [0] return wavetable out = dsp.buffer() chords = 'ii vi V7 I69' dubhead = 0 for chord in chords.split(' ') * 8: chordlength = random.triangular(2, 3) # in seconds freqs = tune.chord(chord, key='e', octave=2) numnotes = random.randint(3, 6) notes = [] for _ in range(numnotes): notelength = random.triangular(0.1, 2) freq = random.choice(freqs) amp = random.triangular(0.1, 0.25) note = oscs.Osc(wavetable=make_wavetable()).play(notelength, freq, amp) note = note.env(dsp.RND) note = note.taper(0.01) note = note.pan(random.random()) out.dub(note, dubhead + random.triangular(0, 0.1))
def test_get_chord(self): assert tune.chord('I7', key='a', octave=4, ratios=tune.just) == [440.0, 550.0, 660.0, 792.0] assert tune.chord('I7', key='a', octave=3, ratios=tune.just) == [220.0, 275.0, 330.0, 396.0]
def test_getChord(self): assert tune.chord('I7', key='a', octave=4, ratios=tune.just) == [440.0, 550.0, 660.0, 792.0] assert tune.chord('I7', key='a', octave=3, ratios=tune.just) == [220.0, 275.0, 330.0, 396.0]
def get_freqs(count): chords = ['II', 'V9', 'vii*', 'IV7'] return tune.chord(chords[count % len(chords)])
return out for i in range(numbars): bar = dsp.buffer() numlayers = random.randint(3, 6) beat = int(((60000 / 109) / 1000) * 44100) // 4 if i // 4 % 3 == 0: chord = chords2[i % len(chords2)] else: chord = chords[i % len(chords)] freqs = tune.chord(chord, octave=3, key='d') if i > 3: for _ in range(numlayers): pattern = rhythm.pattern(16, random.randint(2, 6), random.randint(0, 3)) onsets = rhythm.onsets(pattern, beat) for onset in onsets: if random.random() > 0.5: osc.freq = random.choice(freqs) osc.wavetable = [0] + [ random.triangular(-1, 1) for _ in range(random.randint(3, 10)) ] + [0] osc.amp = 0.5 snd = osc.play(random.randint(441, 44100))
def test_getChord(): assert tune.chord('I7', key='a', octave=4, ratios=tune.just) == [440.0, 550.0, 660.0, 792.0]
ohats = drums.parsebeat(ohat, 8, beat, length, makeOHat, 0) kicks = drums.parsebeat(kick, 8, beat, length, makeKick, 0) snares = drums.parsebeat(snare, 8, beat, length, makeSnare, 0) lsnares = drums.parsebeat(lsnare, 8, beat, length, makeLSnare, 0) snaresnstuff = dsp.mix([ohats,snares]) snaresnstuff= dsp.split(snaresnstuff, dsp.flen(snaresnstuff) / 32) snaresnstuff = dsp.randshuffle(snaresnstuff) snaresnstuff = [ dsp.env(sns, 'phasor') for sns in snaresnstuff ] snaresnstuff = ''.join(snaresnstuff) snaresnstuff = dsp.amp(snaresnstuff, 0.5) bar = dsp.mix([kicks,lsnares,snares,hats,ohats,snaresnstuff]) #bar = dsp.mix([hats,ohats]) if count % 4 == 0: bar = dsp.mix([ bar, dsp.fill(bksnd, dsp.flen(bar), silence=True) ]) progression = 'ii6 ii69'.split(' ') cname = progression[ count % len(progression) ] rfreqs = tune.chord(cname, key, 2) rhodes = makeRhodes(dsp.flen(bar), beat / 8, rfreqs) out += dsp.mix([ bar, dsp.fill(rhodes, dsp.flen(bar)) ]) #out += bar count += 1 elapsed += dsp.flen(bar) dsp.write(out, '05-bumps_ii')
def test_sub_bass_movements(self): freqs = tune.chord('ii/i', key='a', octave=4, ratios=tune.JUST) self.assertEqual(freqs[0], 440.0)
from pippi import dsp from pippi import tune chord = tune.chord('I', octave=2, key='a', ratios=tune.terry) numsegs = 2222 length = dsp.stf(60) / numsegs numpoints = 7 wfs = [ dsp.breakpoint([dsp.rand(-1, 1) for p in range(numpoints)], 512) for _ in range(numsegs) ] win = dsp.wavetable('tri', 512) mods = [ dsp.breakpoint([dsp.rand(0, 1) for p in range(numpoints)], 512) for _ in range(numsegs) ] modfs = [dsp.rand(0.01, 0.1) for _ in range(numsegs)] modrs = [dsp.rand(0, 0.1) for _ in range(numsegs)] pws = [dsp.rand(0.01, 1) for _ in range(numsegs)] out = [] for wf, mod, modf, modr, pw in zip(wfs, mods, modfs, modrs, pws): layers = [] for freq in chord: layer = dsp.pulsar(freq, length, pw, wf, win, mod, modr, modf, 0.1) layers += [layer]
def pulsars(chord, length=22050, drift=0.01, speed=0.5, amp=0.1, pulsewidth=None, env='flat', key='c', octave=3): freqs = tune.chord(chord, key, octave) return dsp.mix([ pulsar(freq, length, drift, speed, amp, pulsewidth, env) for freq in freqs ])