int audio_pcm_sw_read (SWVoiceIn *sw, void *buf, int size)

{

    HWVoiceIn *hw = sw->hw;

    int samples, live, ret = 0, swlim, isamp, osamp, rpos, total = 0;

    st_sample_t *src, *dst = sw->buf;



    rpos = audio_pcm_sw_get_rpos_in (sw) % hw->samples;



    live = hw->total_samples_captured - sw->total_hw_samples_acquired;

    if (audio_bug (AUDIO_FUNC, live < 0 || live > hw->samples)) {

        dolog ("live_in=%d hw->samples=%d\n", live, hw->samples);

        return 0;

    }



    samples = size >> sw->info.shift;

    if (!live) {

        return 0;

    }



    swlim = (live * sw->ratio) >> 32;

    swlim = audio_MIN (swlim, samples);



    while (swlim) {

        src = hw->conv_buf + rpos;

        isamp = hw->wpos - rpos;

        /* XXX: <= ? */

        if (isamp <= 0) {

            isamp = hw->samples - rpos;

        }



        if (!isamp) {

            break;

        }

        osamp = swlim;



        if (audio_bug (AUDIO_FUNC, osamp < 0)) {

            dolog ("osamp=%d\n", osamp);

            return 0;

        }



        st_rate_flow (sw->rate, src, dst, &isamp, &osamp);

        swlim -= osamp;

        rpos = (rpos + isamp) % hw->samples;

        dst += osamp;

        ret += osamp;

        total += isamp;

    }



    sw->clip (buf, sw->buf, ret);

    sw->total_hw_samples_acquired += total;

    return ret << sw->info.shift;

}

int audio_pcm_sw_read (SWVoiceIn *sw, void *buf, int size)

{

    HWVoiceIn *hw = sw->hw;

    int samples, live, ret = 0, swlim, isamp, osamp, rpos, total = 0;

    st_sample_t *src, *dst = sw->buf;



    rpos = audio_pcm_sw_get_rpos_in (sw) % hw->samples;



    live = hw->total_samples_captured - sw->total_hw_samples_acquired;

    if (audio_bug (AUDIO_FUNC, live < 0 || live > hw->samples)) {

        dolog ("live_in=%d hw->samples=%d\n", live, hw->samples);

        return 0;

    }



    samples = size >> sw->info.shift;

    if (!live) {

        return 0;

    }



    swlim = (live * sw->ratio) >> 32;

    swlim = audio_MIN (swlim, samples);



    while (swlim) {

        src = hw->conv_buf + rpos;

        isamp = hw->wpos - rpos;

        

        if (isamp <= 0) {

            isamp = hw->samples - rpos;

        }



        if (!isamp) {

            break;

        }

        osamp = swlim;



        if (audio_bug (AUDIO_FUNC, osamp < 0)) {

            dolog ("osamp=%d\n", osamp);

            return 0;

        }



        st_rate_flow (sw->rate, src, dst, &isamp, &osamp);

        swlim -= osamp;

        rpos = (rpos + isamp) % hw->samples;

        dst += osamp;

        ret += osamp;

        total += isamp;

    }



    sw->clip (buf, sw->buf, ret);

    sw->total_hw_samples_acquired += total;

    return ret << sw->info.shift;

}

int FUNC_0 (SWVoiceIn *VAR_0, void *VAR_1, int VAR_2)

{

    HWVoiceIn *hw = VAR_0->hw;

    int VAR_3, VAR_4, VAR_5 = 0, VAR_6, VAR_7, VAR_8, VAR_9, VAR_10 = 0;

    st_sample_t *src, *dst = VAR_0->VAR_1;



    VAR_9 = audio_pcm_sw_get_rpos_in (VAR_0) % hw->VAR_3;



    VAR_4 = hw->total_samples_captured - VAR_0->total_hw_samples_acquired;

    if (audio_bug (AUDIO_FUNC, VAR_4 < 0 || VAR_4 > hw->VAR_3)) {

        dolog ("live_in=%d hw->VAR_3=%d\n", VAR_4, hw->VAR_3);

        return 0;

    }



    VAR_3 = VAR_2 >> VAR_0->info.shift;

    if (!VAR_4) {

        return 0;

    }



    VAR_6 = (VAR_4 * VAR_0->ratio) >> 32;

    VAR_6 = audio_MIN (VAR_6, VAR_3);



    while (VAR_6) {

        src = hw->conv_buf + VAR_9;

        VAR_7 = hw->wpos - VAR_9;

        

        if (VAR_7 <= 0) {

            VAR_7 = hw->VAR_3 - VAR_9;

        }



        if (!VAR_7) {

            break;

        }

        VAR_8 = VAR_6;



        if (audio_bug (AUDIO_FUNC, VAR_8 < 0)) {

            dolog ("VAR_8=%d\n", VAR_8);

            return 0;

        }



        st_rate_flow (VAR_0->rate, src, dst, &VAR_7, &VAR_8);

        VAR_6 -= VAR_8;

        VAR_9 = (VAR_9 + VAR_7) % hw->VAR_3;

        dst += VAR_8;

        VAR_5 += VAR_8;

        VAR_10 += VAR_7;

    }



    VAR_0->clip (VAR_1, VAR_0->VAR_1, VAR_5);

    VAR_0->total_hw_samples_acquired += VAR_10;

    return VAR_5 << VAR_0->info.shift;

}

int FUNC_0 (SWVoiceIn *VAR_0, void *VAR_1, int VAR_2)
{ HWVoiceIn *hw = VAR_0->hw; int VAR_3, VAR_4, VAR_5 = 0, VAR_6, VAR_7, VAR_8, VAR_9, VAR_10 = 0; st_sample_t *src, *dst = VAR_0->VAR_1; VAR_9 = audio_pcm_sw_get_rpos_in (VAR_0) % hw->VAR_3; VAR_4 = hw->total_samples_captured - VAR_0->total_hw_samples_acquired; if (audio_bug (AUDIO_FUNC, VAR_4 < 0 || VAR_4 > hw->VAR_3)) { dolog ("live_in=%d hw->VAR_3=%d\n", VAR_4, hw->VAR_3); return 0; } VAR_3 = VAR_2 >> VAR_0->info.shift; if (!VAR_4) { return 0; } VAR_6 = (VAR_4 * VAR_0->ratio) >> 32; VAR_6 = audio_MIN (VAR_6, VAR_3); while (VAR_6) { src = hw->conv_buf + VAR_9; VAR_7 = hw->wpos - VAR_9; if (VAR_7 <= 0) { VAR_7 = hw->VAR_3 - VAR_9; } if (!VAR_7) { break; } VAR_8 = VAR_6; if (audio_bug (AUDIO_FUNC, VAR_8 < 0)) { dolog ("VAR_8=%d\n", VAR_8); return 0; } st_rate_flow (VAR_0->rate, src, dst, &VAR_7, &VAR_8); VAR_6 -= VAR_8; VAR_9 = (VAR_9 + VAR_7) % hw->VAR_3; dst += VAR_8; VAR_5 += VAR_8; VAR_10 += VAR_7; } VAR_0->clip (VAR_1, VAR_0->VAR_1, VAR_5); VAR_0->total_hw_samples_acquired += VAR_10; return VAR_5 << VAR_0->info.shift; }