コード例 #1
0
ファイル: DSP_freeverb.c プロジェクト: cyberixae/kunquat
static Device_state* DSP_freeverb_create_state(
        const Device* device,
        int32_t audio_rate,
        int32_t audio_buffer_size)
{
    assert(device != NULL);
    assert(audio_rate > 0);
    assert(audio_buffer_size >= 0);

    DSP_freeverb* freeverb = (DSP_freeverb*)device->dimpl;

    Freeverb_state* fstate = memory_alloc_item(Freeverb_state);
    if (fstate == NULL)
        return NULL;

    DSP_state_init(&fstate->parent, device, audio_rate, audio_buffer_size);
    fstate->parent.parent.destroy = del_Freeverb_state;

    for (int i = 0; i < FREEVERB_COMBS; ++i)
    {
        fstate->comb_left[i] = NULL;
        fstate->comb_right[i] = NULL;
    }
    for (int i = 0; i < FREEVERB_ALLPASSES; ++i)
    {
        fstate->allpass_left[i] = NULL;
        fstate->allpass_right[i] = NULL;
    }

    for (int i = 0; i < FREEVERB_COMBS; ++i)
    {
        const uint32_t left_size = max(1, comb_tuning[i] * audio_rate);

        fstate->comb_left[i] = new_Freeverb_comb(left_size);
        if (fstate->comb_left[i] == NULL)
        {
            del_Freeverb_state(&fstate->parent.parent);
            return NULL;
        }

        const uint32_t right_size = max(
                1, (comb_tuning[i] + stereo_spread) * audio_rate);

        fstate->comb_right[i] = new_Freeverb_comb(right_size);
        if (fstate->comb_right[i] == NULL)
        {
            del_Freeverb_state(&fstate->parent.parent);
            return NULL;
        }
    }

    for (int i = 0; i < FREEVERB_ALLPASSES; ++i)
    {
        const uint32_t left_size = max(1, allpass_tuning[i] * audio_rate);

        if (fstate->allpass_left[i] == NULL)
        {
            fstate->allpass_left[i] = new_Freeverb_allpass(left_size);
            if (fstate->allpass_left[i] == NULL)
            {
                del_Freeverb_state(&fstate->parent.parent);
                return NULL;
            }
        }

        const uint32_t right_size = max(
                1, (allpass_tuning[i] + stereo_spread) * audio_rate);

        if (fstate->allpass_right[i] == NULL)
        {
            fstate->allpass_right[i] = new_Freeverb_allpass(right_size);
            if (fstate->allpass_right[i] == NULL)
            {
                del_Freeverb_state(&fstate->parent.parent);
                return NULL;
            }
        }
    }

    Freeverb_state_reset(fstate, freeverb);

    return &fstate->parent.parent;
}
コード例 #2
0
ファイル: Freeverb_state.c プロジェクト: EdwardBetts/kunquat
Device_state* new_Freeverb_pstate(
        const Device* device, int32_t audio_rate, int32_t audio_buffer_size)
{
    assert(device != NULL);
    assert(audio_rate > 0);
    assert(audio_buffer_size >= 0);

    Freeverb_pstate* fpstate = memory_alloc_item(Freeverb_pstate);
    if (fpstate == NULL)
        return NULL;

    if (!Proc_state_init(&fpstate->parent, device, audio_rate, audio_buffer_size))
    {
        memory_free(fpstate);
        return NULL;
    }

    fpstate->parent.destroy = del_Freeverb_pstate;
    fpstate->parent.set_audio_rate = Freeverb_pstate_set_audio_rate;
    fpstate->parent.reset = Freeverb_pstate_reset;
    fpstate->parent.render_mixed = Freeverb_pstate_render_mixed;
    fpstate->parent.clear_history = Freeverb_pstate_clear_history;

    for (int ch = 0; ch < 2; ++ch)
    {
        for (int i = 0; i < FREEVERB_COMBS; ++i)
            fpstate->combs[ch][i] = NULL;

        for (int i = 0; i < FREEVERB_ALLPASSES; ++i)
            fpstate->allpasses[ch][i] = NULL;
    }

    for (int i = 0; i < FREEVERB_COMBS; ++i)
    {
        const uint32_t left_size = max(1, comb_tuning[i] * audio_rate);

        fpstate->combs[0][i] = new_Freeverb_comb(left_size);
        if (fpstate->combs[0][i] == NULL)
        {
            del_Device_state(&fpstate->parent.parent);
            return NULL;
        }

        const uint32_t right_size = max(
                1, (comb_tuning[i] + stereo_spread) * audio_rate);

        fpstate->combs[1][i] = new_Freeverb_comb(right_size);
        if (fpstate->combs[1][i] == NULL)
        {
            del_Device_state(&fpstate->parent.parent);
            return NULL;
        }
    }

    for (int i = 0; i < FREEVERB_ALLPASSES; ++i)
    {
        const uint32_t left_size = max(1, allpass_tuning[i] * audio_rate);

        if (fpstate->allpasses[0][i] == NULL)
        {
            fpstate->allpasses[0][i] = new_Freeverb_allpass(left_size);
            if (fpstate->allpasses[0][i] == NULL)
            {
                del_Device_state(&fpstate->parent.parent);
                return NULL;
            }
        }

        const uint32_t right_size = max(
                1, (allpass_tuning[i] + stereo_spread) * audio_rate);

        if (fpstate->allpasses[1][i] == NULL)
        {
            fpstate->allpasses[1][i] = new_Freeverb_allpass(right_size);
            if (fpstate->allpasses[1][i] == NULL)
            {
                del_Device_state(&fpstate->parent.parent);
                return NULL;
            }
        }
    }

    return &fpstate->parent.parent;
}