void init(int _channels, double _sampleRate) override {
        AKSoundpipeKernel::init(_channels, _sampleRate);

        sp_bitcrush_create(&bitcrush0);
        sp_bitcrush_create(&bitcrush1);
        sp_bitcrush_init(sp, bitcrush0);
        sp_bitcrush_init(sp, bitcrush1);
        bitcrush0->bitdepth = 8;
        bitcrush1->bitdepth = 8;
        bitcrush0->srate = 10000;
        bitcrush1->srate = 10000;

        bitDepthRamper.init();
        sampleRateRamper.init();
    }
Пример #2
0
    void init(int channelCount, double inSampleRate) {
        channels = channelCount;

        globalSampleRate = float(inSampleRate);

        sp_create(&sp);
        sp->sr = globalSampleRate;
        sp->nchan = channels;
        sp_bitcrush_create(&bitcrush);
        sp_bitcrush_init(sp, bitcrush);
        bitcrush->bitdepth = 8;
        bitcrush->srate = 10000;
    }
Пример #3
0
int sporth_bitcrush(sporth_stack *stack, void *ud)
{
    plumber_data *pd = ud;
    SPFLOAT input;
    SPFLOAT out;
    SPFLOAT bitdepth;
    SPFLOAT srate;
    sp_bitcrush *bitcrush;

    switch(pd->mode) {
        case PLUMBER_CREATE:

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

            sp_bitcrush_create(&bitcrush);
            plumber_add_module(pd, SPORTH_BITCRUSH, sizeof(sp_bitcrush), bitcrush);
            break;
        case PLUMBER_INIT:

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

            if(sporth_check_args(stack, "ff") != SPORTH_OK) {
                fprintf(stderr,"Not enough arguments for bitcrush\n");
                stack->error++;
                return PLUMBER_NOTOK;
            }
            srate = sporth_stack_pop_float(stack);
            bitdepth = sporth_stack_pop_float(stack);
            input = sporth_stack_pop_float(stack);
            bitcrush = pd->last->ud;
            sp_bitcrush_init(pd->sp, bitcrush);
            sporth_stack_push_float(stack, 0);
            break;
        case PLUMBER_COMPUTE:
            if(sporth_check_args(stack, "ff") != SPORTH_OK) {
                fprintf(stderr,"Not enough arguments for bitcrush\n");
                stack->error++;
                return PLUMBER_NOTOK;
            }
            srate = sporth_stack_pop_float(stack);
            bitdepth = sporth_stack_pop_float(stack);
            input = sporth_stack_pop_float(stack);
            bitcrush = pd->last->ud;
            bitcrush->bitdepth = bitdepth;
            bitcrush->srate = srate;
            sp_bitcrush_compute(pd->sp, bitcrush, &input, &out);
            sporth_stack_push_float(stack, out);
            break;
        case PLUMBER_DESTROY:
            bitcrush = pd->last->ud;
            sp_bitcrush_destroy(&bitcrush);
            break;
        default:
            fprintf(stderr, "bitcrush: Uknown mode!\n");
            break;
    }
    return PLUMBER_OK;
}