コード例 #1
0
ファイル: ex_gbuzz.c プロジェクト: aure/Soundpipe
int main() {
    srand(time(NULL));
    udata ud;
    sp_data *sp;
    sp_create(&sp);
    sp_ftbl_create(sp, &ud.ft, 2048);
    sp_gbuzz_create(&ud.buzz);

    sp_gen_sine(sp, ud.ft);
    sp_gbuzz_init(sp, ud.buzz, ud.ft);
    sp->len = 44100 * 5;
    sp_process(sp, &ud, process);

    sp_ftbl_destroy(&ud.ft);
    sp_gbuzz_destroy(&ud.buzz);
    sp_destroy(&sp);
    return 0;
}
コード例 #2
0
ファイル: gbuzz.c プロジェクト: OpenDAWN/Sporth
int sporth_gbuzz(sporth_stack *stack, void *ud)
{
    plumber_data *pd = ud;
    SPFLOAT out;
    SPFLOAT freq;
    SPFLOAT amp;
    SPFLOAT nharm;
    SPFLOAT lharm;
    SPFLOAT mul;
    sporth_gbuzz_d *gbuzz;

    switch(pd->mode) {
        case PLUMBER_CREATE:
#ifdef DEBUG_MODE
            fprintf(stderr, "gbuzz: Creating\n");
#endif
            gbuzz = malloc(sizeof(sporth_gbuzz_d));
            sp_ftbl_create(pd->sp, &gbuzz->ft, 4096);
            sp_gbuzz_create(&gbuzz->gbuzz);
            plumber_add_module(pd, SPORTH_GBUZZ, sizeof(sporth_gbuzz_d), gbuzz);
            break;
        case PLUMBER_INIT:

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

            if(sporth_check_args(stack, "fffff") != SPORTH_OK) {
                fprintf(stderr,"Not enough arguments for gbuzz\n");
                stack->error++;
                return PLUMBER_NOTOK;
            }
            mul = sporth_stack_pop_float(stack);
            lharm = sporth_stack_pop_float(stack);
            nharm = sporth_stack_pop_float(stack);
            amp = sporth_stack_pop_float(stack);
            freq = sporth_stack_pop_float(stack);

            gbuzz = pd->last->ud;
            sp_gen_sine(pd->sp, gbuzz->ft);
            sp_gbuzz_init(pd->sp, gbuzz->gbuzz, gbuzz->ft, 0);
            sporth_stack_push_float(stack, 0);
            break;
        case PLUMBER_COMPUTE:
            if(sporth_check_args(stack, "fffff") != SPORTH_OK) {
                fprintf(stderr,"Not enough arguments for gbuzz\n");
                stack->error++;
                return PLUMBER_NOTOK;
            }
            mul = sporth_stack_pop_float(stack);
            lharm = sporth_stack_pop_float(stack);
            nharm = sporth_stack_pop_float(stack);
            amp = sporth_stack_pop_float(stack);
            freq = sporth_stack_pop_float(stack);

            gbuzz = pd->last->ud;

            gbuzz->gbuzz->freq = freq;
            gbuzz->gbuzz->amp = amp;
            gbuzz->gbuzz->nharm = nharm;
            gbuzz->gbuzz->lharm = lharm;
            gbuzz->gbuzz->mul = mul;
            SPFLOAT dumb = 0;
            sp_gbuzz_compute(pd->sp, gbuzz->gbuzz, &dumb, &out);
            sporth_stack_push_float(stack, out);
            break;
        case PLUMBER_DESTROY:
            gbuzz = pd->last->ud;
            sp_gbuzz_destroy(&gbuzz->gbuzz);
            sp_ftbl_destroy(&gbuzz->ft);
            free(gbuzz);
            break;
        default:
            fprintf(stderr, "gbuzz: Uknown mode!\n");
            break;
    }
    return PLUMBER_OK;
}