示例#1
0
int t_gen_vals(sp_test *tst, sp_data *sp, const char *hash) 
{
    uint32_t n;
    int fail = 0;
    SPFLOAT out = 0;

    sp_ftbl *ft;
    sp_ftbl_create(sp, &ft, 4096);
    sp_gen_sinesum(sp, ft, "1 1.5 -3 5 ");

    for(n = 0; n < tst->size; n++) {
        if(n < ft->size) {
            out = ft->tbl[n];
        } else {
            out = 0;
        }
        sp_test_add_sample(tst, out);
    }

    fail = sp_test_verify(tst, hash);

    sp_ftbl_destroy(&ft);

    if(fail) return SP_NOT_OK;
    else return SP_OK;
}
示例#2
0
int sporth_gen_sinesum(sporth_stack *stack, void *ud)
{
    plumber_data *pd = ud;

    int size;
    SPFLOAT out = 0;
    sp_ftbl *ft;
    char *str;
    char *args;

    switch(pd->mode){
        case PLUMBER_CREATE:
            plumber_add_module(pd, SPORTH_GEN_SINESUM, 0, NULL);
            break;

        case PLUMBER_INIT:
            if(sporth_check_args(stack, "sfs") != SPORTH_OK) {
                fprintf(stderr, "Init: not enough arguments for gen_sinesum\n");
                return PLUMBER_NOTOK;
            }

            args = sporth_stack_pop_string(stack);
            size = (int)sporth_stack_pop_float(stack);
            str = sporth_stack_pop_string(stack);
#ifdef DEBUG_MODE
            fprintf(stderr, "Creating sinesum table %s of size %d\n", str, size);
#endif
            sp_ftbl_create(pd->sp, &ft, size);
            if(sp_gen_sinesum(pd->sp, ft, args) == SP_NOT_OK) {
                fprintf(stderr, "There was an issue creating the sinesume ftable \"%s\".\n", str);
                stack->error++;
                return PLUMBER_NOTOK;
            }
            plumber_ftmap_add(pd, str, ft);
            free(str);
            free(args);
            break;

        case PLUMBER_COMPUTE:
            size = (int)sporth_stack_pop_float(stack);
            break;

        case PLUMBER_DESTROY:
            break;

        default:
           printf("Error: Unknown mode!");
           break;
    }
    return PLUMBER_OK;
}
示例#3
0
int chord_cloud_init(sp_data *sp, chord_cloud *cc, char *notes, SPFLOAT amp)
{
    int i;
    sp_osc *tmposc;
    sp_dust *tmpdust;
    sp_tenv *tmpenv;
    sp_tevent *tmpretrig;

    sp_ftbl_create(sp, &cc->sine, 4096);
    sp_gen_sinesum(sp, cc->sine, "1 0.5 0.3 0.25, 0.1625");
    sp_ftbl_create(sp, &cc->notes, 1);
    sp_gen_vals(sp, cc->notes, notes);
    cc->ampmax= amp;

    cc->grains= malloc(cc->notes->size * sizeof(chord_grain));

    for(i = 0; i < cc->notes->size; i++) {
        chord_grain *grain = &cc->grains[i];
        sp_osc_create(&grain->osc);
        sp_tenv_create(&grain->env);
        sp_dust_create(&grain->dust);
        sp_tevent_create(&grain->retrig);

        tmposc = grain->osc;
        tmpenv = grain->env;
        tmpdust = grain->dust;
        tmpretrig = grain->retrig;

        sp_dust_init(sp, tmpdust, 1, 8);
        sp_osc_init(sp, tmposc, cc->sine, 0);
        tmposc->freq = sp_midi2cps(cc->notes->tbl[i]);
        tmposc->amp = 1.0;
        grain->amp = 1.0;
        sp_tenv_init(sp, tmpenv);
        tmpenv->atk = 0.01;
        tmpenv->hold = 0;
        tmpenv->rel =  0.03;

        sp_tevent_init(sp, tmpretrig, cloud_reinit, cloud_compute, grain);
    }

    return SP_OK;
}
示例#4
0
int main() {
    srand(time(NULL));
    udata ud;
    sp_data *sp;
    sp_create(&sp);
    sp_ftbl_create(sp, &ud.ft, 4096);
    sp_osc_create(&ud.osc);

    sp_gen_sinesum(sp, ud.ft, "1 0 0 1");
    sp_osc_init(sp, ud.osc, ud.ft);
    ud.osc->freq = 500;
    sp->len = 44100 * 5;
    sp_process(sp, &ud, write_osc);

    sp_ftbl_destroy(&ud.ft);
    sp_osc_destroy(&ud.osc);
    sp_destroy(&sp);
    return 0;
}