Stretcher

Stretcher

A modified version of the paulstretch utility found in Soundpipe. It is configured to work as a subprogram.

<<stretcher.c>>=
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "soundpipe.h"
#include "lib/dr_wav/dr_wav.h"

#if 0
/* Bring this back when sp_process is revamped */
static void process(sp_data *sp, void *ud)
{
    SPFLOAT out;
    sp_paulstretch *ps;
    ps = ud;
    sp_paulstretch_compute(sp, ps, NULL, &out);
    sp_out(sp, 0, out);
}
#endif

int sp_paulstretch_wavin(sp_data *sp,
                         sp_paulstretch *p,
                         drwav *wav,
                         SPFLOAT *out);

int stretcher_main(int argc, char *argv[])
{
    sp_data *sp;
    sp_paulstretch *ps;
    sp_wavout *wavout;
    drwav wavin;

    SPFLOAT stretch;
    SPFLOAT window;
    const char *fin;
    const char *fout;
    unsigned long s;

    if(argc < 5) {
        fprintf(stderr,
            "Usage: %s window_size stretch in.wav out.wav\n",
            argv[0]
        );
        return 1;
    }

    sp_create(&sp);

    sp_paulstretch_create(&ps);
    sp_wavout_create(&wavout);

    fin = argv[3];
    fout = argv[4];

    printf("window = %g\n", atof(argv[1]));
    window = atof(argv[1]);
    printf("stretch = %g\n", atof(argv[2]));
    stretch = atof(argv[2]);

    drwav_init_file(&wavin, fin);
    sp->len = wavin.totalSampleCount * stretch;

    printf("total dur = %gs\n", (SPFLOAT)sp->len / sp->sr);
    printf("input = %s\n", fin);
    printf("output = %s\n", fout);

    strncpy(sp->filename, fout, 60);

    sp_paulstretch_init(sp, ps, NULL, window, stretch);
    sp_wavout_init(sp, wavout, fout);

    ps->wrap = 0;

    for (s = 0; s < sp->len; s++) {
        SPFLOAT p, w;
        sp_paulstretch_wavin(sp, ps, &wavin, &p);
        sp_wavout_compute(sp, wavout, &p, &w);
    }

    drwav_uninit(&wavin);
    sp_paulstretch_destroy(&ps);
    sp_wavout_destroy(&wavout);
    sp_destroy(&sp);
    return 0;
}



prev | home | next