Example #1
0
int main() {
    srand(1234567);
    UserData ud;
    sp_data *sp;
    sp_create(&sp);

    sp_pluck_create(&ud.pluck);
    sp_osc_create(&ud.osc);
    sp_metro_create(&ud.met);
    sp_ftbl_create(sp, &ud.ft, 2048);

    sp_pluck_init(sp, ud.pluck, 110);
    sp_gen_sine(sp, ud.ft);
    sp_metro_init(sp, ud.met, 2);
    sp_osc_init(sp, ud.osc, ud.ft, 0);

    ud.osc->freq = 1;
    ud.osc->amp = 1;

    sp->len = 44100 * 5;
    sp_process(sp, &ud, process);

    sp_pluck_destroy(&ud.pluck);
    sp_ftbl_destroy(&ud.ft);
    sp_osc_destroy(&ud.osc);
    sp_metro_destroy(&ud.met);

    sp_destroy(&sp);
    return 0;
}
Example #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;
}
Example #3
0
int sporth_pluck(sporth_stack *stack, void *ud)
{
    plumber_data *pd = ud;
    sp_pluck *pluck;
    SPFLOAT freq = 0;
    SPFLOAT amp = 0;
    SPFLOAT trig = 0;
    SPFLOAT ifreq = 0;
    SPFLOAT out = 0;
    switch(pd->mode) {
        case PLUMBER_CREATE:

#ifdef DEBUG_MODE
            plumber_print(pd, "pluck: Creating\n");
#endif
            sp_pluck_create(&pluck);
            plumber_add_ugen(pd, SPORTH_PLUCK, pluck);
            if(sporth_check_args(stack, "ffff") != SPORTH_OK) {
                plumber_print(pd,"Not enough arguments for pluck\n");
                stack->error++;
                return PLUMBER_NOTOK;
            }

            ifreq = sporth_stack_pop_float(stack);
            amp = sporth_stack_pop_float(stack);
            freq = sporth_stack_pop_float(stack);
            trig = sporth_stack_pop_float(stack);

            sporth_stack_push_float(stack, 0);
            break;
        case PLUMBER_INIT:

#ifdef DEBUG_MODE
            plumber_print(pd, "pluck: Initialising\n");
#endif

            pluck = pd->last->ud;

            ifreq = sporth_stack_pop_float(stack);
            amp = sporth_stack_pop_float(stack);
            freq = sporth_stack_pop_float(stack);
            trig = sporth_stack_pop_float(stack);

            sp_pluck_init(pd->sp, pluck, ifreq);
            sporth_stack_push_float(stack, 0);
            break;
        case PLUMBER_COMPUTE:
            pluck = pd->last->ud;

            ifreq = sporth_stack_pop_float(stack);
            amp = sporth_stack_pop_float(stack);
            freq = sporth_stack_pop_float(stack);
            trig = sporth_stack_pop_float(stack);

            pluck->freq = freq;
            pluck->amp = amp;

            sp_pluck_compute(pd->sp, pluck, &trig, &out);
            sporth_stack_push_float(stack, out);
            break;
        case PLUMBER_DESTROY:
            pluck = pd->last->ud;
            sp_pluck_destroy(&pluck);
            break;
        default:
            plumber_print(pd, "pluck: Unknown mode!\n");
            break;
    }
    return PLUMBER_OK;
}