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

    sp_ftbl_loadfile(sp, &ud.wav, "oneart.wav");
    sp_ftbl_create(sp, &ud.win, 1024);
    sp_fog_create(&ud.fog);
    sp_phasor_create(&ud.phs);

    sp_gen_composite(sp, ud.win, "0.5 0.5 270 0.5");

    sp_fog_init(sp, ud.fog, ud.wav, ud.win, 100, 0);
    ud.fog->trans = 0.9;

    sp_phasor_init(sp, ud.phs, 0);
    ud.phs->freq = 0.3 / ((SPFLOAT)ud.wav->size / sp->sr); 

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

    sp_fog_destroy(&ud.fog);
    sp_ftbl_destroy(&ud.wav);
    sp_ftbl_destroy(&ud.win);
    sp_phasor_destroy(&ud.phs);

    sp_destroy(&sp);
    return 0;
}
示例#2
0
文件: fog.c 项目: Ferrick90/AudioKit
int sporth_fog(sporth_stack *stack, void *ud)
{
    plumber_data *pd = ud;
    SPFLOAT out;
    char *wavstr, *winstr;
    sp_ftbl *wav;
    sp_ftbl *win;
    int iolaps;
    SPFLOAT iphs;
    SPFLOAT amp;
    SPFLOAT dense;
    SPFLOAT trans;
    SPFLOAT spd;
    SPFLOAT oct;
    SPFLOAT band;
    SPFLOAT ris;
    SPFLOAT dec;
    SPFLOAT dur;
    sp_fog *fog;

    switch(pd->mode) {
        case PLUMBER_CREATE:

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

            sp_fog_create(&fog);
            plumber_add_ugen(pd, SPORTH_FOG, fog);
            if(sporth_check_args(stack, "fffffffffffss") != SPORTH_OK) {
                fprintf(stderr,"Not enough arguments for fog\n");
                stack->error++;
                return PLUMBER_NOTOK;
            }
            wavstr = sporth_stack_pop_string(stack);
            winstr = sporth_stack_pop_string(stack);
            iolaps = sporth_stack_pop_float(stack);
            iphs = sporth_stack_pop_float(stack);
            dur = sporth_stack_pop_float(stack);
            dec = sporth_stack_pop_float(stack);
            ris = sporth_stack_pop_float(stack);
            band = sporth_stack_pop_float(stack);
            oct = sporth_stack_pop_float(stack);
            spd = sporth_stack_pop_float(stack);
            trans = sporth_stack_pop_float(stack);
            dense = sporth_stack_pop_float(stack);
            amp = sporth_stack_pop_float(stack);
            free(wavstr);
            free(winstr);
            sporth_stack_push_float(stack, 0);
            break;
        case PLUMBER_INIT:

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

            wavstr = sporth_stack_pop_string(stack);
            winstr = sporth_stack_pop_string(stack);
            iolaps = sporth_stack_pop_float(stack);
            iphs = sporth_stack_pop_float(stack);
            dur = sporth_stack_pop_float(stack);
            dec = sporth_stack_pop_float(stack);
            ris = sporth_stack_pop_float(stack);
            band = sporth_stack_pop_float(stack);
            oct = sporth_stack_pop_float(stack);
            spd = sporth_stack_pop_float(stack);
            trans = sporth_stack_pop_float(stack);
            dense = sporth_stack_pop_float(stack);
            amp = sporth_stack_pop_float(stack);
            fog = pd->last->ud;

            if(plumber_ftmap_search(pd, wavstr, &wav) == PLUMBER_NOTOK) {
                free(wavstr);
                free(winstr);
                stack->error++;
                return PLUMBER_NOTOK;
            }

            if(plumber_ftmap_search(pd, winstr, &win) == PLUMBER_NOTOK) {
                free(winstr);
                stack->error++;
                return PLUMBER_NOTOK;
            }

            sp_fog_init(pd->sp, fog, wav, win, iolaps, iphs);

            free(wavstr);
            free(winstr);
            sporth_stack_push_float(stack, 0);
            break;
        case PLUMBER_COMPUTE:
            iolaps = sporth_stack_pop_float(stack);
            iphs = sporth_stack_pop_float(stack);
            dur = sporth_stack_pop_float(stack);
            dec = sporth_stack_pop_float(stack);
            ris = sporth_stack_pop_float(stack);
            band = sporth_stack_pop_float(stack);
            oct = sporth_stack_pop_float(stack);
            spd = sporth_stack_pop_float(stack);
            trans = sporth_stack_pop_float(stack);
            dense = sporth_stack_pop_float(stack);
            amp = sporth_stack_pop_float(stack);
            fog = pd->last->ud;
            fog->amp = amp;
            fog->dens = dense;
            fog->trans = trans;
            fog->spd = spd;
            fog->oct = oct;
            fog->band = band;
            fog->ris = ris;
            fog->dec = dec;
            fog->dur = dur;
            sp_fog_compute(pd->sp, fog, NULL, &out);
            sporth_stack_push_float(stack, out);
            break;
        case PLUMBER_DESTROY:
            fog = pd->last->ud;
            sp_fog_destroy(&fog);
            break;
        default:
            fprintf(stderr, "fog: Unknown mode!\n");
            break;
    }
    return PLUMBER_OK;
}