Exemplo n.º 1
0
int main()
{
    sp_data *sp;
    sp_create(&sp);
    plumber_data pd;
    plumber_register(&pd);
    plumber_init(&pd);
    pd.sp = sp;
    char *str =
    "0 p 0.2 sine "
    "1 p 0.2 sine "
    "add";
    plumber_parse_string(&pd, str);
    plumber_compute(&pd, PLUMBER_INIT);

    /* Set the p values to constants */

    pd.p[0] = 440;
    pd.p[1] = 350;

    sp_process(sp, &pd, process);

    plumber_clean(&pd);
    sp_destroy(&sp);
    return 0;
}
Exemplo n.º 2
0
Arquivo: var.c Projeto: narner/Sporth
int main()
{
    SPFLOAT *freq, *amp;
    sp_data *sp;
    sp_create(&sp);
    plumber_data pd;
    plumber_register(&pd);
    plumber_init(&pd);
    pd.sp = sp;

    plumber_create_var(&pd, "freq", &freq);
    plumber_create_var(&pd, "amp", &amp);

    *freq = 1000;
    *amp = 0.5;

    plumber_parse_string(&pd, "_freq get _amp get sine");
    plumber_show_pipes(&pd);
    plumber_compute(&pd, PLUMBER_INIT);

    sp_process(sp, &pd, process);

    plumber_clean(&pd);
    sp_destroy(&sp);
    return 0;
}
    void init(int _channels, double _sampleRate) override {
        AKSoundpipeKernel::init(_channels, _sampleRate);

        plumber_register(&pd);
        plumber_init(&pd);
        addUgensToFTable(&pd);
        pd.sp = sp;
        if (sporthCode != nil) {
            plumber_parse_string(&pd, sporthCode);
            plumber_compute(&pd, PLUMBER_INIT);
        }
        
    }
    void init(int channelCount, double inSampleRate) {
        channels = channelCount;

        sampleRate = float(inSampleRate);

        sp_create(&sp);
        plumber_register(&pd);
        plumber_init(&pd);
        pd.sp = sp;
        if (sporthCode != nil) {
            plumber_parse_string(&pd, sporthCode);
            plumber_compute(&pd, PLUMBER_INIT);
        }
        
    }
Exemplo n.º 5
0
int main() 
{
    UserData ud;

    /* allocate and initialize */
    sp_create(&ud.sp);
    plumber_register(&ud.pd);
    plumber_init(&ud.pd);

    /* create an ftable with a size 1, which will be expanded with gen_vals */
    sp_ftbl_create(ud.sp, &ud.seq, 1);
    /* Gen_vals will create a table from a string of numbers */
    sp_gen_vals(ud.sp, ud.seq, "60 63 67 72");
    
    /* Sporth code to be parsed, using a ftable generated in c called 'seq' */
    char *str = 
        "0.1 dmetro "
        "0 'seq' tseq "
        "0.01 port mtof "
        "0.5 1 1 1 fm";

    /* Tell plumber that that we will take care of removing the following ftables */
    /* This is needed for persistant ftables that don't get cleaned for 
     * recompilation */
    plumber_ftmap_delete(&ud.pd, 0);
    /* add ftable to plumber and call it "seq" */
    plumber_ftmap_add(&ud.pd, "seq", ud.seq);
    /* Turn automatic deletion back "on" */
    plumber_ftmap_delete(&ud.pd, 1);

    /* make plumber know about the soundpipe instance */
    ud.pd.sp = ud.sp;

    /* parse string and allocate plumbing */
    plumber_parse_string(&ud.pd, str);

    /* initialize the plumbing */
    plumber_compute(&ud.pd, PLUMBER_INIT);
    /* run */
    sp_process(ud.sp, &ud, process);
    /* Cleanup */
    /* Plumber will handle freeing the memory of the ftable we added */
    /* no need to call sp_ftbl_destroy */
    plumber_clean(&ud.pd);
    sp_ftbl_destroy(&ud.seq);
    sp_destroy(&ud.sp);
    return 0;
}
    void init(int channelCount, double sampleRate) override {
        AKSoundpipeKernel::init(channelCount, sampleRate);
        plumber_register(&pd);
        plumber_init(&pd);

        for (auto info : customUgens) {
            plumber_ftmap_add_function(&pd, info.name, info.func, info.userData);
        }

        pd.sp = sp;
        if (sporthCode != nil) {
            plumber_parse_string(&pd, sporthCode);
            plumber_compute(&pd, PLUMBER_INIT);
        }

    }
Exemplo n.º 7
0
int main()
{
    sp_data *sp;
    sp_create(&sp);
    plumber_data pd;
    plumber_register(&pd);
    plumber_init(&pd);
    pd.sp = sp;
    plumber_parse_string(&pd, "440 0.1 sine");
    plumber_show_pipes(&pd);
    plumber_compute(&pd, PLUMBER_INIT);

    sp_process(sp, &pd, process);

    plumber_clean(&pd);
    sp_destroy(&sp);
    return 0;
}
Exemplo n.º 8
0
int sporth_gen_eval(sporth_stack *stack, void *ud)
{
    plumber_data *pd = ud;
    plumber_data my_pd;

    uint32_t size;
    sp_data *sp;
    sp_ftbl *ft;
    char *ftname;
    char *str;
    uint32_t n;

    switch(pd->mode){
        case PLUMBER_CREATE:
            plumber_add_ugen(pd, SPORTH_GEN_EVAL, NULL);

            if(sporth_check_args(stack, "sfs") != SPORTH_OK) {
                plumber_print(pd, "Init: not enough arguments for gen_sine\n");
                return PLUMBER_NOTOK;
            }
            str = sporth_stack_pop_string(stack);
            size = (uint32_t) sporth_stack_pop_float(stack);
            ftname = sporth_stack_pop_string(stack);
            sp_ftbl_create(pd->sp, &ft, size);
            plumber_ftmap_add(pd, ftname, ft);
#ifdef DEBUG_MODE
            plumber_print(pd, "gen_sporth: compiling file %s to table of size %d\n", 
                    filename, size);
#endif
            plumber_register(&my_pd);
            plumber_init(&my_pd);
            sp_create(&sp);
            sp->sr = pd->sp->sr;
            sp_srand(sp, pd->seed);
            my_pd.sp = sp;
            my_pd.sp->len = size;
            if(plumber_parse_string(&my_pd, str) == PLUMBER_OK) {
                plumber_compute(&my_pd, PLUMBER_INIT);
                for(n = 0; n < ft->size; n++) {
                    plumber_compute(&my_pd, PLUMBER_COMPUTE);
                    ft->tbl[n] = sporth_stack_pop_float(&my_pd.sporth.stack);
                }
            }
            plumber_clean(&my_pd);
            sp_destroy(&sp);
            break;

        case PLUMBER_INIT:
            sporth_stack_pop_string(stack);
            sporth_stack_pop_float(stack);
            sporth_stack_pop_string(stack);
            break;

        case PLUMBER_COMPUTE:
            sporth_stack_pop_float(stack);
            break;

        case PLUMBER_DESTROY:
            break;

        default:
           printf("Error: Unknown mode!");
           break;
    }
    return PLUMBER_OK;
}