Exemple #1
0
int main() {
    UserData ud;
    sp_data *sp;
    sp_create(&sp);
    sp_clip_create(&ud.clp);
    sp_osc_create(&ud.osc);
    sp_ftbl_create(sp, &ud.ft, 4096);
    sp_moogladder_create(&ud.filt);

    sp_gen_line(sp, ud.ft, "0 1 4096 -1");
    sp_osc_init(sp, ud.osc, ud.ft, 0);
    ud.osc->freq = sp_midi2cps(48);
    sp_clip_init(sp, ud.clp);
    sp_moogladder_init(sp, ud.filt);
    ud.filt->freq = 1000; 
    ud.filt->res = 0.8;
    sp->len = 44100 * 5;
    sp_process(sp, &ud, write_clip);

    sp_osc_destroy(&ud.osc);
    sp_clip_destroy(&ud.clp);
    sp_ftbl_destroy(&ud.ft);
    sp_moogladder_destroy(&ud.filt);

    sp_destroy(&sp);
    return 0;
}
Exemple #2
0
int sporth_gen_line(sporth_stack *stack, void *ud)
{
    plumber_data *pd = ud;

    int size;
    sp_ftbl *ft;
    char *str;
    char *args;

    switch(pd->mode){
        case PLUMBER_CREATE:
#ifdef DEBUG_MODE
            fprintf(stderr, "gen_line: create mode\n");
#endif
            plumber_add_ugen(pd, SPORTH_GEN_LINE, NULL);
            if(sporth_check_args(stack, "sfs") != SPORTH_OK) {
                fprintf(stderr, "Init: not enough arguments for gen_line\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 line table %s of size %d\n", str, size);
#endif
            sp_ftbl_create(pd->sp, &ft, size);
            if(sp_gen_line(pd->sp, ft, args) == SP_NOT_OK) {
                fprintf(stderr, "There was an issue creating the line ftable \"%s\".\n", str);
                stack->error++;
                return PLUMBER_NOTOK;
            }
            plumber_ftmap_add(pd, str, ft);
            break;

        case PLUMBER_INIT:

            args = sporth_stack_pop_string(stack);
            size = (int)sporth_stack_pop_float(stack);
            str = 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;
}
int main() {
    sp_data *sp;
    sp_create(&sp);
    sp_ftbl *ft;
    sp_ftbl_create(sp, &ft, 4096);
    sp_gen_line(sp, ft, "0 -1 2048 1 4096 -1");
    int i;
    FILE *fp= fopen("plot.dat", "w");
    for(i = 0; i < ft->size; i++) {
        fprintf(fp, "%d %g\n", i, ft->tbl[i]);
    }
    printf("%d plot points written to plot.dat. Run write_plot.sh to see the result.\n", ft->size); 
    fclose(fp);
    sp_ftbl_destroy(&ft);
    sp_destroy(&sp);
    return 0;
}
Exemple #4
0
int main() {
    srand(time(NULL));
    int i;
    UserData ud;
    sp_data *sp;
    sp_create(&sp);
    sp_ftbl_create(sp, &ud.ft, 4096);
    for(i = 0; i < 3; i++) sp_osc_create(&ud.osc[i]);
    sp_lpf18_create(&ud.lpf);
    sp_osc_create(&ud.lfo);
    sp_ftbl_create(sp, &ud.sine_ft, 4096);
    sp_gen_sine(sp, ud.sine_ft);

    sp_gen_line(sp, ud.ft, "0 1 4096 -1");
    sp_osc_init(sp, ud.osc[0], ud.ft);
    ud.osc[0]->freq = sp_midi2cps(40 - 0.05);
    sp_osc_init(sp, ud.osc[1], ud.ft);
    ud.osc[1]->freq = sp_midi2cps(40 - 12);
    sp_osc_init(sp, ud.osc[2], ud.ft);
    ud.osc[2]->freq = sp_midi2cps(40 + 0.05);
    sp_lpf18_init(sp, ud.lpf);
    sp_osc_init(sp, ud.lfo, ud.sine_ft);
    ud.lfo->freq = 0.4;

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

    sp_ftbl_destroy(&ud.ft);
    for(i = 0; i < 3; i++) sp_osc_destroy(&ud.osc[i]);
    sp_lpf18_destroy(&ud.lpf);
    sp_osc_destroy(&ud.lfo);
    sp_ftbl_destroy(&ud.sine_ft);

    sp_destroy(&sp);
    return 0;
}