depp / libfresample

Fast audio sample rate conversion with simplified BSD license
BSD 2-Clause "Simplified" License
58 stars 10 forks source link

Cannot figure out the API #2

Closed AndrewBelt closed 8 years ago

AndrewBelt commented 8 years ago

This software has promising performance, but I cannot produce anything but a vector of zeros as its output. Here is my attempt at using the library. Do you see anything wrong?


    unsigned dither = 0xc90fdaa2;
    struct lfr_param *param = lfr_param_new();
    assert(param);
    lfr_param_seti(param, LFR_PARAM_QUALITY, LFR_QUALITY_MEDIUM);
    int inrate = 32*44100;
    int outrate = 44100;
    lfr_param_seti(param, LFR_PARAM_INRATE, inrate);
    lfr_param_seti(param, LFR_PARAM_OUTRATE, outrate);
    lfr_fixed_t inv_ratio = 32ll << 32;

    struct lfr_filter *filter;
    lfr_filter_new(&filter, param);
    assert(filter);
    lfr_fixed_t pos = -lfr_filter_delay(filter);

    float input[inrate];
    float output[outrate];
    for (int i = 0; i < inrate; i++) {
        input[i] = 2.0*((float)rand() / RAND_MAX) - 1.0;
    }

    lfr_resample(&pos, inv_ratio, &dither, 1,
        output, LFR_FMT_F32_NATIVE, inrate,
        input, LFR_FMT_F32_NATIVE, outrate,
        filter);

    for (int i = 0; i < outrate; i++) {
        printf("%f\n", output[i]);
    }

pos is not being advanced, making me think that lfr_resample is returning early due to an error.

AndrewBelt commented 8 years ago

Fixed! Seems like only LFR_FMT_S16_NATIVE to LFR_FMT_S16_NATIVE formats are supported.

depp commented 7 years ago

Thanks for your interest! This project could use some love and I'm planning on revisiting it soon.