Exemple #1
0
def stretch(snd, length=None, speed=None, grain_size=20):
    """ Crude granular time stretching and pitch shifting """

    original_length = dsp.flen(snd)

    if speed is not None:
        snd = dsp.transpose(snd, speed)

    current_length = dsp.flen(snd)

    if original_length != current_length or length is not None:
        grain_size = dsp.mstf(grain_size)

        numgrains = length / (grain_size / 2)
        numgrains = numgrains if numgrains > 0 else 1

        block_size = current_length / numgrains

        grains = []
        original_position = 0
        count = 0

        while count <= numgrains:
            grain = dsp.cut(snd, original_position, grain_size)

            grains += [grain]

            original_position += block_size
            count += 1

        snd = dsp.cross(grains, dsp.ftms(grain_size / 2))

    return snd
Exemple #2
0
def stretch(snd, length=None, speed=None, grain_size=20):
    """ Crude granular time stretching and pitch shifting """

    original_length = dsp.flen(snd)

    if speed is not None:
        snd = dsp.transpose(snd, speed)

    current_length = dsp.flen(snd)

    if original_length != current_length or length is not None:
        grain_size = dsp.mstf(grain_size)

        numgrains = length / (grain_size / 2)
        numgrains = numgrains if numgrains > 0 else 1

        block_size = current_length / numgrains

        grains = []
        original_position = 0
        count = 0

        while count <= numgrains:
            grain = dsp.cut(snd, original_position, grain_size)

            grains += [ grain ]

            original_position += block_size
            count += 1

        snd = dsp.cross(grains, dsp.ftms(grain_size / 2))

    return snd
Exemple #3
0
    def impulse(self, amp, width, pan, hz):
        width = int(dsp.htf(hz) * math.fabs(width))

        snd = dsp.cycle(dsp.fth(width))
        snd = dsp.amp(snd, amp)
        snd = dsp.pan(snd, pan)
        snd = dsp.pad(snd, 0, dsp.htf(hz) - dsp.flen(snd))

        return snd
Exemple #4
0
def play(args):
    length = dsp.stf(20)
    volume = 0.1 
    octave = 4 
    note = 'd'
    quality = tune.major
    m = 1
    width = 0
    waveform = 'sine'

    harmonics = [1,2]
    scale = [1,5,8]
    wtypes = ['sine', 'phasor', 'line', 'saw']
    ratios = tune.terry

    for arg in args:
        a = arg.split(':')

        if a[0] == 't':
            length = dsp.stf(float(a[1]))

        if a[0] == 'v':
            volume = float(a[1]) / 100.0

        if a[0] == 'o':
            octave = int(a[1])

        if a[0] == 'n':
            note = a[1]

        if a[0] == 'm':
            m = float(a[1])

        if a[0] == 'w':
            width = dsp.mstf(float(a[1]))

        if a[0] == 'q':
            if a[1] == 'M':
                quality = tune.major
            elif a[1] == 'm':
                quality = tune.minor
            else:
                quality = tune.major

        if a[0] == 'h':
            harmonics = [int(s) for s in a[1].split('.')]

        if a[0] == 'g':
            glitch = True

        if a[0] == 'wf':
            waveform = a[1]

        if a[0] == 'tr':
            if a[1] == 'young':
                ratios = tune.young
            elif a[1] == 'terry':
                ratios = tune.terry


    tones = []
    m *= 1.0
    for i in range(dsp.randint(2,4)):
        freq = tune.step(i, note, octave, dsp.randshuffle(scale), quality, ratios)

        snds = [ dsp.tone(length, freq * h, waveform) for h in harmonics ]
        for snd in snds:
            snd = dsp.vsplit(snd, dsp.mstf(10 * m), dsp.mstf(100 * m))
            if width != 0:
                for ii, s in enumerate(snd):
                    olen = dsp.flen(s)
                    s = dsp.cut(s, 0, width)
                    s = dsp.pad(s, 0, olen - dsp.flen(s)) 
                    snd[ii] = s

            snd = [ dsp.env(s, dsp.randchoose(wtypes)) for s in snd ]
            snd = [ dsp.pan(s, dsp.rand()) for s in snd ]
            snd = [ dsp.amp(s, dsp.rand()) for s in snd ]
            snd = ''.join(snd)

            tones += [ snd ]

    out = dsp.mix(tones)
    out = dsp.env(out, 'gauss')

    return dsp.cache(dsp.amp(out, volume))
Exemple #5
0
def play(args):
    snd = False
    reps = 8
    length = dsp.stf(20)
    volume = 0.1 
    octave = 4 
    note = 'd'
    quality = tune.major
    m = 1
    width = 0
    waveform = 'sine'

    scale = [1,5,8]
    wtypes = ['sine', 'phasor', 'line', 'saw']

    for arg in args:
        a = arg.split(':')

        if a[0] == 't':
            length = int(a[1])

        if a[0] == 'v':
            volume = float(a[1]) / 100.0

        if a[0] == 'r':
            reps = int(a[1])

        if a[0] == 'n':
            note = a[1]

        if a[0] == 'm':
            m = float(a[1])

        if a[0] == 'w':
            width = dsp.mstf(float(a[1]))

        if a[0] == 'q':
            if a[1] == 'M':
                quality = tune.major
            elif a[1] == 'm':
                quality = tune.minor
            else:
                quality = tune.major

        if a[0] == 'g':
            glitch = True

        if a[0] == 's':
            if a[1] == 'c':
                snd = dsp.read('sounds/clapshake.wav').data
            elif a[1] == 'h':
                snd = dsp.read('sounds/hihat.wav').data
            elif a[1] == 's':
                snd = dsp.read('sounds/snare.wav').data
            elif a[1] == 'k':
                snd = dsp.read('sounds/kick.wav').data
            else:
                snd = dsp.read('sounds/hihat.wav').data


    out = ''

    if(w <= 11):
        w = 11

    width = dsp.mstf(t)
    for h in range(reps):
        s = dsp.cut(snd, dsp.randint(0, 100), w)
        out += dsp.pad(s, 0, width - dsp.flen(s))
    
    out = dsp.env(out, 'gauss')

    return dsp.cache(dsp.amp(out, volume))
Exemple #6
0
def play(args):
    length = dsp.stf(dsp.rand(5, 10))
    volume = 0.2 
    octave = 2 
    note = 'd'
    quality = tune.major
    reps = dsp.randint(3, 11)
    glitch = False
    superglitch = False
    pulse = False
    ratios = tune.terry

    rhodes = dsp.read('sounds/220rhodes.wav').data

    #scale = [1,3,5,4]
    scale = [1,5,8,6]

    for arg in args:
        a = arg.split(':')

        if a[0] == 't':
            length = dsp.stf(float(a[1]))

        if a[0] == 'v':
            volume = float(a[1]) / 100.0

        if a[0] == 'o':
            octave = int(a[1])

        if a[0] == 'n':
            note = a[1]

        if a[0] == 'q':
            if a[1] == 'M':
                quality = tune.major
            elif a[1] == 'm':
                quality = tune.minor
            else:
                quality = tune.major

        if a[0] == 'r':
            reps = int(a[1])

        if a[0] == 'p':
            pulse = True

        if a[0] == 'g':
            glitch = True

        if a[0] == 'gg':
            glitch = True
            superglitch = True

        if a[0] == 'tr':
            if a[1] == 'young':
                ratios = tune.young
            elif a[1] == 'terry':
                ratios = tune.terry

        if a[0] == 's':
            scale = [int(s) for s in a[1].split('.')]

    out = ''
    for i in range(reps):
        freq = tune.step(i, note, octave, scale, quality, ratios)
        diff = freq / 440.0

        n = dsp.transpose(rhodes, diff)
        n = dsp.fill(n, length)

        o = [dsp.tone(length, freq * i * 0.5) for i in range(4)]
        o = [dsp.env(oo) for oo in o]
        o = [dsp.pan(oo, dsp.rand()) for oo in o]
        o = dsp.mix([dsp.amp(oo, dsp.rand(0.05, 0.1)) for oo in o])
        out += dsp.mix([n, o])

    if glitch == True:
        if superglitch == True:
            mlen = dsp.mstf(100)
        else:
            mlen = dsp.flen(out) / 8

        out = dsp.vsplit(out, dsp.mstf(1), mlen)
        out = [dsp.pan(o, dsp.rand()) for o in out]
        out = ''.join(dsp.randshuffle(out))

    if pulse == True:
        plen = dsp.mstf(dsp.rand(80, 500))
        out = dsp.split(out, plen)
        mpul = len(out) / dsp.randint(4, 8)

        out = [dsp.env(o) * mpul for i, o in enumerate(out) if i % mpul == 0]
        opads = dsp.wavetable('sine', len(out), dsp.rand(plen * 0.25, plen))
        out = [dsp.pad(o, 0, int(opads[i])) for i, o in enumerate(out)]
        out = dsp.env(''.join(out))

    return dsp.cache(dsp.amp(out, volume))
Exemple #7
0
 def test_lengths(self):
     freqs = range(1, 20000, 200)
     for freq in freqs:
         self.assertEqual(dsp.flen(dsp.cycle(freq, 'random')), dsp.htf(freq))
Exemple #8
0
def play(args):
    length = dsp.stf(20)
    volume = 0.2 
    octave = 2 
    note = 'd'
    quality = tune.major
    glitch = False
    waveform = 'sine'
    ratios = tune.terry

    harmonics = [1,2]
    scale = [1,8]
    wtypes = ['sine', 'phasor', 'line', 'saw']

    for arg in args:
        a = arg.split(':')

        if a[0] == 't':
            length = dsp.stf(float(a[1]))

        if a[0] == 'v':
            volume = float(a[1]) / 100.0

        if a[0] == 'o':
            octave = int(a[1])

        if a[0] == 'n':
            note = a[1]

        if a[0] == 'q':
            if a[1] == 'M':
                quality = tune.major
            elif a[1] == 'm':
                quality = tune.minor
            else:
                quality = tune.major

        if a[0] == 'tr':
            if a[1] == 'young':
                ratios = tune.young
            elif a[1] == 'terry':
                ratios = tune.terry

        if a[0] == 'h':
            harmonics = [int(s) for s in a[1].split('.')]

        if a[0] == 'g':
            glitch = True

        if a[0] == 'wf':
            waveform = a[1]

    tones = []
    for i in range(dsp.randint(2,4)):
        freq = tune.step(i, note, octave, dsp.randshuffle(scale), quality, ratios)

        snds = [ dsp.tone(length, freq * h, waveform) for h in harmonics ]

        snds = [ dsp.env(s, dsp.randchoose(wtypes), highval=dsp.rand(0.2, 0.4)) for s in snds ]
        snds = [ dsp.pan(s, dsp.rand()) for s in snds ]

        tones += [ dsp.mix(snds) ]

    out = dsp.mix(tones)

    if glitch:
        inlen = dsp.flen(out) * 0.25
        instart = 0

        midlen = dsp.flen(out) * 0.5
        midstart = inlen

        endlen = dsp.flen(out) - (inlen + midlen)
        endstart = inlen + midlen
        
        outin = dsp.cut(out, instart, inlen)
        outmid = dsp.cut(out, midstart, midlen)
        outend = dsp.cut(out, endstart, endlen)

        out = "%s%s%s" % (dsp.env(outin, 'line'), outmid, dsp.env(outend, 'phasor'))
    else:
        out = dsp.env(out, 'gauss')

    return dsp.cache(dsp.amp(out, volume))