Esempio n. 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
Esempio n. 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
Esempio n. 3
0
 def test_conversion(self):
     self.assertEqual(dsp.stf(1), dsp.audio_params[2])
     self.assertEqual(dsp.mstf(1000), dsp.stf(1))
     self.assertEqual(dsp.mstf(1000), dsp.audio_params[2])
     self.assertEqual(dsp.ftms(dsp.mstf(1000)), dsp.mstf(dsp.ftms(1000)))