~hecanjog/pippi

2f1dd5ffa401bdedde36fe901d3a3dcd3d0c80f3 — Erik Schoster 1 year, 2 months ago 5d71a66
Trim output buffer for variable speed playback on libpippi buffers
4 files changed, 12 insertions(+), 8 deletions(-)

M REFACTOR
M libpippi/src/pippicore.c
M pippi/buffers.pyx
M tests/test_newbuffer.py
M REFACTOR => REFACTOR +2 -2
@@ 53,8 53,8 @@ Just some refactoring notes...
- [x] reversed
- [x] remix
- [x] softclip -- fx.softclip
- [ ] speed
- [ ] vspeed
- [x] speed
- [x] vspeed
- [x] taper
- [x] trim
- [x] write

M libpippi/src/pippicore.c => libpippi/src/pippicore.c +1 -3
@@ 536,7 536,6 @@ lpbuffer_t * varispeed_buffer(lpbuffer_t * buf, lpbuffer_t * speed) {

    out = create_buffer(length, buf->channels, buf->samplerate);
    for(i=0; i < length; i++) {
        //pos = phase/buf->length;
        pos = (lpfloat_t)i / length;

        for(c=0; c < buf->channels; c++) {


@@ 545,11 544,10 @@ lpbuffer_t * varispeed_buffer(lpbuffer_t * buf, lpbuffer_t * speed) {

        _speed = interpolate_linear_pos(speed, pos);
        phase += phase_inc * _speed;
        if(phase >= buf->length) break;
    }

    printf("length: %d last i: %d\n", (int)length, (int)i);
    trimmed = cut_buffer(out, 0, i);
    //trimmed = trim_buffer(out, 0, 1, 0, 4);
    free(out);
    return trimmed;
}

M pippi/buffers.pyx => pippi/buffers.pyx +6 -0
@@ 860,6 860,8 @@ cdef class SoundBuffer:
        cdef lpbuffer_t * out
        #cdef int interpolation_scheme

        # TODO would be cool to be able to select the interpolator 
        # like some pippi oscs allow.
        #if interpolation is None:
        #    interpolation = 'linear'
        #interpolation_scheme = to_interpolation_scheme(interpolation)


@@ 869,6 871,10 @@ cdef class SoundBuffer:
        out = LPBuffer.varispeed(self.buffer, _speed);
        return SoundBuffer.fromlpbuffer(out)

    def vspeed(SoundBuffer self, object speed, str interpolation=None):
        logger.warning('DEPRECATED: SoundBuffer.vspeed() is deprecated. Please just use SoundBuffer.speed()')
        return self.speed(speed, interpolation)

    def taper(self, double start, double end=-1):
        cdef lpbuffer_t * out


M tests/test_newbuffer.py => tests/test_newbuffer.py +3 -3
@@ 520,19 520,19 @@ class TestNewBuffer(TestCase):
        self.assertEqual(len(out), int(len(sound) * (1/speed)))

    def test_variable_speed_1(self):
        sound = SoundBuffer(filename='tests/sounds/linux.wav')
        sound = SoundBuffer(filename='tests/sounds/guitar1s.wav')
        speed = SoundBuffer.win('hann', 0.5, 2)
        out = sound.speed(speed)
        out.write('tests/renders/newbuffer_vspeed_0.5_2.wav')

    def test_variable_speed_2(self):
        sound = SoundBuffer(filename='tests/sounds/linux.wav')
        sound = SoundBuffer(filename='tests/sounds/guitar1s.wav')
        speed = SoundBuffer.win('hann', 0.15, 0.5)
        out = sound.speed(speed)
        out.write('tests/renders/newbuffer_vspeed_0.15_0.5.wav')

    def test_variable_speed_3(self):
        sound = SoundBuffer(filename='tests/sounds/linux.wav')
        sound = SoundBuffer(filename='tests/sounds/guitar1s.wav')
        speed = SoundBuffer.win('hann', 5, 50)
        out = sound.speed(speed)
        out.write('tests/renders/newbuffer_vspeed_5_50.wav')