Esempio n. 1
0
int t_butbp(sp_test *tst, sp_data *sp, const char *hash) 
{
    sp_srand(sp, 0); 
    uint32_t n;
    int fail = 0;
    SPFLOAT in = 0;
    SPFLOAT out = 0;
    UserData ud;
    ud.counter = 0;
    sp_noise_create(&ud.ns);
    sp_butbp_create(&ud.butbp);
    sp_noise_init(sp, ud.ns);
    sp_butbp_init(sp, ud.butbp);

    for(n = 0; n < tst->size; n++) {
        in = 0;
        out = 0;
        if(ud.counter == 0) {
            ud.butbp->freq= 500 + sp_rand(sp) % 4000;
        }
        sp_noise_compute(sp, ud.ns, NULL, &in);
        sp_butbp_compute(sp, ud.butbp, &in, &out); 
        ud.counter = (ud.counter + 1) % 5000;
        sp_test_add_sample(tst, out);
    }

    fail = sp_test_verify(tst, hash);
    
    sp_noise_destroy(&ud.ns);
    sp_butbp_destroy(&ud.butbp);
     
    if(fail) return SP_NOT_OK;
    else return SP_OK;
}
Esempio n. 2
0
int t_pluck(sp_test *tst, sp_data *sp, const char *hash) 
{
    uint32_t n;
    int fail = 0;

    UserData ud;
    sp_srand(sp, 1337); 
    SPFLOAT pluck = 0, met = 0;
    SPFLOAT notes[] = {60, 63, 67, 70, 74};

    sp_pluck_create(&ud.pluck);
    sp_metro_create(&ud.met);

    sp_pluck_init(sp, ud.pluck, 400);
    sp_metro_init(sp, ud.met);
    ud.met->freq = 4;

    for(n = 0; n < tst->size; n++) {
        pluck = 0, met = 0;
        sp_metro_compute(sp, ud.met, NULL, &met);
        if(met) {
            ud.pluck->freq = sp_midi2cps(notes[sp_rand(sp) % 5]);
        }
        sp_pluck_compute(sp, ud.pluck, &met, &pluck);
        sp_test_add_sample(tst, pluck);
    }
    
    fail = sp_test_verify(tst, hash);

    sp_pluck_destroy(&ud.pluck);
    sp_metro_destroy(&ud.met);

    if(fail) return SP_NOT_OK;
    else return SP_OK;
}
Esempio n. 3
0
static void sp_pluck_reinit(sp_data *sp, sp_pluck *p)
{
    int n;
    SPFLOAT val = 0;
    SPFLOAT *ap = (SPFLOAT *)p->auxch.ptr;
    for (n=p->npts; n--; ) {   
        val = (SPFLOAT) ((SPFLOAT) sp_rand(sp) / SP_RANDMAX);
        *ap++ = (val * 2) - 1;
    }
    p->phs256 = 0;
}
Esempio n. 4
0
int sp_tseq_compute(sp_data *sp, sp_tseq *p, SPFLOAT *trig, SPFLOAT *val)
{
    if(*trig != 0){
        if(p->shuf) {
            p->pos = sp_rand(sp) % p->ft->size;
        } else {
            p->pos = (p->pos + 1) % p->ft->size;
        }
        p->val = p->ft->tbl[p->pos];
    }
    *val = p->val;
    return SP_OK;
}
Esempio n. 5
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;
}
Esempio n. 6
0
int sporth_slick(sporth_stack *stack, void *ud)
{
    plumber_data *pd = ud;

    char *ftname;
    uint32_t index = 0;
    slist_d *sl;
    char **str = NULL;
    switch(pd->mode){
        case PLUMBER_CREATE:
            str = malloc(sizeof(char *));
            plumber_add_ugen(pd, SPORTH_SLICK, str);

            if(sporth_check_args(stack, "s") != SPORTH_OK) {
               plumber_print(pd,"Not enough arguments for slick\n");
                return PLUMBER_NOTOK;
            }

            ftname = sporth_stack_pop_string(stack);
            if(plumber_ftmap_search_userdata(pd,ftname, (void *)&sl) != 
                    PLUMBER_OK) {
                plumber_print(pd, "Could not find ftable %s\n", ftname);
                return PLUMBER_NOTOK;
            }
            index = (uint32_t)(((SPFLOAT)sp_rand(pd->sp) / SP_RANDMAX) * sl->len);
            *str = sl->list[index];
            sporth_stack_push_string(stack, &sl->list[index]);
            break;

        case PLUMBER_INIT:
            str = pd->last->ud;
            sporth_stack_pop_string(stack);
            sporth_stack_push_string(stack, str);
            break;

        case PLUMBER_COMPUTE:
            break;

        case PLUMBER_DESTROY:
            str = pd->last->ud;
            free(str);
            break;

        default:
            plumber_print(pd,"Error: Unknown mode!");
            break;
    }
    return PLUMBER_OK;
}
Esempio n. 7
0
static SPFLOAT glottis_compute(sp_data *sp, glottis *glot, SPFLOAT lambda)
{
    SPFLOAT out;
    SPFLOAT aspiration;
    SPFLOAT noise;
    SPFLOAT t;
    SPFLOAT intensity;

    out = 0;
    intensity = 1.0;
    glot->time_in_waveform += glot->T;

    if(glot->time_in_waveform > glot->waveform_length) {
        glot->time_in_waveform -= glot->waveform_length;
        glottis_setup_waveform(glot, lambda);

    }

    t = (glot->time_in_waveform / glot->waveform_length);

    if(t > glot->Te) {
        out = (-exp(-glot->epsilon * (t-glot->Te)) + glot->shift) / glot->delta;
    } else {
        out = glot->E0 * exp(glot->alpha * t) * sin(glot->omega * t);
    }




    noise = 2.0 * ((SPFLOAT) sp_rand(sp) / SP_RANDMAX) - 1;


    aspiration = intensity * (1 - sqrt(glot->tenseness)) * 0.3 * noise;

    aspiration *= 0.2;

    out += aspiration;

    return out;
}
Esempio n. 8
0
int t_butlp(sp_test *tst, sp_data *sp, const char *hash) 
{
    uint32_t n;
    int fail = 0;

    SPFLOAT in = 0;
    SPFLOAT out = 0;
    
    udata ud;
    ud.counter = 0;
    sp_noise_create(&ud.ns);
    sp_butlp_create(&ud.butlp);
    sp_noise_init(sp, ud.ns);
    sp_butlp_init(sp, ud.butlp);

    for(n = 0; n < tst->size; n++) {
        in = 0;
        out = 0;
        if(ud.counter == 0) {
            ud.butlp->freq= 500 + sp_rand(sp) % 4000;
        }
        sp_noise_compute(sp, ud.ns, NULL, &in);
        sp_butlp_compute(sp, ud.butlp, &in, &out); 
        ud.counter = (ud.counter + 1) % 5000;
        sp_test_add_sample(tst, out);
    }

    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;
    }
    
    sp_noise_destroy(&ud.ns);
    sp_butlp_destroy(&ud.butlp);
     
    if(fail) return SP_NOT_OK;
    else return SP_OK;
}
Esempio n. 9
0
static SPFLOAT noise_tick(sp_data *sp)
{
    SPFLOAT temp;
    temp = 1.0 * sp_rand(sp) - 1073741823.5;
    return temp * (1.0 / 1073741823.0);
}
Esempio n. 10
0
static int my_random(sp_data *sp, int max)
{
    return (sp_rand(sp) % (max + 1));
}