Esempio n. 1
0
int sporth_delay(sporth_stack *stack, void *ud)
{
    plumber_data *pd = ud;
    SPFLOAT input;
    SPFLOAT out;
    SPFLOAT time;
    SPFLOAT feedback;
    sp_delay *delay;

    switch(pd->mode) {
        case PLUMBER_CREATE:

#ifdef DEBUG_MODE
            fprintf(stderr, "delay: Creating\n");
#endif

            sp_delay_create(&delay);
            plumber_add_ugen(pd, SPORTH_DELAY, delay);
            if(sporth_check_args(stack, "fff") != SPORTH_OK) {
                fprintf(stderr,"Not enough arguments for delay\n");
                stack->error++;
                return PLUMBER_NOTOK;
            }
            time = sporth_stack_pop_float(stack);
            feedback = sporth_stack_pop_float(stack);
            input = sporth_stack_pop_float(stack);
            sporth_stack_push_float(stack, 0);
            break;
        case PLUMBER_INIT:

#ifdef DEBUG_MODE
            fprintf(stderr, "delay: Initialising\n");
#endif

            time = sporth_stack_pop_float(stack);
            feedback = sporth_stack_pop_float(stack);
            input = sporth_stack_pop_float(stack);
            delay = pd->last->ud;
            sp_delay_init(pd->sp, delay, time);
            sporth_stack_push_float(stack, 0);
            break;
        case PLUMBER_COMPUTE:
            time = sporth_stack_pop_float(stack);
            feedback = sporth_stack_pop_float(stack);
            input = sporth_stack_pop_float(stack);
            delay = pd->last->ud;
            delay->feedback = feedback;
            sp_delay_compute(pd->sp, delay, &input, &out);
            sporth_stack_push_float(stack, out);
            break;
        case PLUMBER_DESTROY:
            delay = pd->last->ud;
            sp_delay_destroy(&delay);
            break;
        default:
            fprintf(stderr, "delay: Unknown mode!\n");
            break;
    }
    return PLUMBER_OK;
}
Esempio n. 2
0
void process(sp_data *sp, void *udata) {
    UserData *ud = udata;
    SPFLOAT osc = 0, delay = 0, met = 0, tenv = 0;
    sp_metro_compute(sp, ud->met, NULL, &met);
    sp_tenv_compute(sp, ud->tenv, &met, &tenv);
    if(met) {
        ud->osc->freq = 100 + rand() % 500;
    }
    sp_osc_compute(sp, ud->osc, NULL, &osc);
    osc *= tenv;
    sp_delay_compute(sp, ud->delay, &osc, &delay);
    sp->out[0] = osc + delay;
}
Esempio n. 3
0
int t_delay(sp_test *tst, sp_data *sp, const char *hash)
{
    uint32_t n;
    int fail = 0;
    SPFLOAT osc = 0, delay = 0, met = 0, tenv = 0;
    UserData ud;

    sp_delay_create(&ud.delay);
    sp_osc_create(&ud.osc);
    sp_ftbl_create(sp, &ud.ft, 2048);
    sp_metro_create(&ud.met);
    sp_tenv_create(&ud.tenv);

    sp_delay_init(sp, ud.delay, 0.75 * 0.5);
    ud.delay->feedback = 0.5;
    sp_gen_sine(sp, ud.ft);
    sp_osc_init(sp, ud.osc, ud.ft, 0);
    ud.osc->amp = 0.5;
    sp_metro_init(sp, ud.met);
    ud.met->freq = 1;
    sp_tenv_init(sp, ud.tenv);
    ud.tenv->atk = 0.005;
    ud.tenv->hold = 0.1;
    ud.tenv->rel =  0.1;



    for(n = 0; n < tst->size; n++) {
        osc = 0, delay = 0, met = 0, tenv = 0;
        sp_metro_compute(sp, ud.met, NULL, &met);
        sp_tenv_compute(sp, ud.tenv, &met, &tenv);
        if(met) {
            ud.osc->freq = 100 + sp_rand(sp) % 500;
        }
        sp_osc_compute(sp, ud.osc, NULL, &osc);
        osc *= tenv;
        sp_delay_compute(sp, ud.delay, &osc, &delay);

        sp_test_add_sample(tst, osc + delay);
    }

    if(sp_test_compare(tst, hash) == SP_NOT_OK) {
        printf("Generated hash %s does not match reference hash %s\n",
               tst->md5string, hash);
        fail = 1;
    }

    if(fail) return SP_NOT_OK;
    else return SP_OK;
}