示例#1
0
int t_pitchamdf(sp_test *tst, sp_data *sp, const char *hash) 
{
    uint32_t n;
    int fail = 0;
    SPFLOAT freq = 0, amp = 0, blsaw = 0, randh = 0, osc = 0;

    sp_srand(sp, 1234567);
    UserData ud;

    sp_pitchamdf_create(&ud.pitchamdf);
    sp_osc_create(&ud.osc);
    sp_ftbl_create(sp, &ud.ft, 2048);
    sp_blsaw_create(&ud.blsaw);
    sp_randh_create(&ud.randh);

    sp_pitchamdf_init(sp, ud.pitchamdf, 200, 500);
    sp_randh_init(sp, ud.randh);
    ud.randh->max = 500;
    ud.randh->min = 200;
    ud.randh->freq = 6;

    sp_blsaw_init(sp, ud.blsaw);

    sp_gen_sine(sp, ud.ft);
    sp_osc_init(sp, ud.osc, ud.ft, 0);


    for(n = 0; n < tst->size; n++) {
        freq = 0, amp = 0, blsaw = 0, randh = 0, osc = 0;
        sp_randh_compute(sp, ud.randh, NULL, &randh);
        *ud.blsaw->freq = randh;
        sp_blsaw_compute(sp, ud.blsaw, NULL, &blsaw);
        sp_pitchamdf_compute(sp, ud.pitchamdf, &blsaw, &freq, &amp);
        ud.osc->freq = freq;
        sp_osc_compute(sp, ud.osc, NULL, &osc);
        sp_test_add_sample(tst, osc);
    }

    fail = sp_test_verify(tst, hash);

    sp_blsaw_destroy(&ud.blsaw);
    sp_randh_destroy(&ud.randh);
    sp_pitchamdf_destroy(&ud.pitchamdf);
    sp_ftbl_destroy(&ud.ft);
    sp_osc_destroy(&ud.osc);

    if(fail) return SP_NOT_OK;
    else return SP_OK;
}
示例#2
0
文件: randh.c 项目: OpenDAWN/Sporth
int sporth_randh(sporth_stack *stack, void *ud)
{
    plumber_data *pd = ud;
    SPFLOAT out;
    SPFLOAT freq;
    SPFLOAT min;
    SPFLOAT max;
    sp_randh *randh;

    switch(pd->mode) {
        case PLUMBER_CREATE:

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

            sp_randh_create(&randh);
            plumber_add_module(pd, SPORTH_RANDH, sizeof(sp_randh), randh);
            break;
        case PLUMBER_INIT:

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

            if(sporth_check_args(stack, "fff") != SPORTH_OK) {
                fprintf(stderr,"Not enough arguments for randh\n");
                stack->error++;
                return PLUMBER_NOTOK;
            }
            max = sporth_stack_pop_float(stack);
            min = sporth_stack_pop_float(stack);
            freq = sporth_stack_pop_float(stack);
            randh = pd->last->ud;
            sp_randh_init(pd->sp, randh);
            sporth_stack_push_float(stack, 0);
            break;
        case PLUMBER_COMPUTE:
            if(sporth_check_args(stack, "fff") != SPORTH_OK) {
                fprintf(stderr,"Not enough arguments for randh\n");
                stack->error++;
                return PLUMBER_NOTOK;
            }
            max = sporth_stack_pop_float(stack);
            min = sporth_stack_pop_float(stack);
            freq = sporth_stack_pop_float(stack);
            randh = pd->last->ud;
            randh->freq = freq;
            randh->min = min;
            randh->max = max;
            sp_randh_compute(pd->sp, randh, NULL, &out);
            sporth_stack_push_float(stack, out);
            break;
        case PLUMBER_DESTROY:
            randh = pd->last->ud;
            sp_randh_destroy(&randh);
            break;
        default:
            fprintf(stderr, "randh: Uknown mode!\n");
            break;
    }
    return PLUMBER_OK;
}