static int alsa_run_out (HWVoiceOut *hw)

{

    ALSAVoiceOut *alsa = (ALSAVoiceOut *) hw;

    int rpos, live, decr;

    int samples;

    uint8_t *dst;

    st_sample_t *src;

    snd_pcm_sframes_t avail;



    live = audio_pcm_hw_get_live_out (hw);

    if (!live) {

        return 0;

    }



    avail = alsa_get_avail (alsa->handle);

    if (avail < 0) {

        dolog ("Could not get number of available playback frames\n");

        return 0;

    }



    decr = audio_MIN (live, avail);

    samples = decr;

    rpos = hw->rpos;

    while (samples) {

        int left_till_end_samples = hw->samples - rpos;

        int len = audio_MIN (samples, left_till_end_samples);

        snd_pcm_sframes_t written;



        src = hw->mix_buf + rpos;

        dst = advance (alsa->pcm_buf, rpos << hw->info.shift);



        hw->clip (dst, src, len);



        while (len) {

            written = snd_pcm_writei (alsa->handle, dst, len);



            if (written <= 0) {

                switch (written) {

                case 0:

                    if (conf.verbose) {

                        dolog ("Failed to write %d frames (wrote zero)\n", len);

                    }

                    goto exit;



                case -EPIPE:

                    if (alsa_recover (alsa->handle)) {

                        alsa_logerr (written, "Failed to write %d frames\n",

                                     len);

                        goto exit;

                    }

                    if (conf.verbose) {

                        dolog ("Recovering from playback xrun\n");

                    }

                    continue;



                case -EAGAIN:

                    goto exit;



                default:

                    alsa_logerr (written, "Failed to write %d frames to %p\n",

                                 len, dst);

                    goto exit;

                }

            }



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

            samples -= written;

            len -= written;

            dst = advance (dst, written << hw->info.shift);

            src += written;

        }

    }



 exit:

    hw->rpos = rpos;

    return decr;

}

static int alsa_run_out (HWVoiceOut *hw)

{

    ALSAVoiceOut *alsa = (ALSAVoiceOut *) hw;

    int rpos, live, decr;

    int samples;

    uint8_t *dst;

    st_sample_t *src;

    snd_pcm_sframes_t avail;



    live = audio_pcm_hw_get_live_out (hw);

    if (!live) {

        return 0;

    }



    avail = alsa_get_avail (alsa->handle);

    if (avail < 0) {

        dolog ("Could not get number of available playback frames\n");

        return 0;

    }



    decr = audio_MIN (live, avail);

    samples = decr;

    rpos = hw->rpos;

    while (samples) {

        int left_till_end_samples = hw->samples - rpos;

        int len = audio_MIN (samples, left_till_end_samples);

        snd_pcm_sframes_t written;



        src = hw->mix_buf + rpos;

        dst = advance (alsa->pcm_buf, rpos << hw->info.shift);



        hw->clip (dst, src, len);



        while (len) {

            written = snd_pcm_writei (alsa->handle, dst, len);



            if (written <= 0) {

                switch (written) {

                case 0:

                    if (conf.verbose) {

                        dolog ("Failed to write %d frames (wrote zero)\n", len);

                    }

                    goto exit;



                case -EPIPE:

                    if (alsa_recover (alsa->handle)) {

                        alsa_logerr (written, "Failed to write %d frames\n",

                                     len);

                        goto exit;

                    }

                    if (conf.verbose) {

                        dolog ("Recovering from playback xrun\n");

                    }

                    continue;



                case -EAGAIN:

                    goto exit;



                default:

                    alsa_logerr (written, "Failed to write %d frames to %p\n",

                                 len, dst);

                    goto exit;

                }

            }



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

            samples -= written;

            len -= written;

            dst = advance (dst, written << hw->info.shift);

            src += written;

        }

    }



 exit:

    hw->rpos = rpos;

    return decr;

}

static int FUNC_0 (HWVoiceOut *VAR_0)

{

    ALSAVoiceOut *alsa = (ALSAVoiceOut *) VAR_0;

    int VAR_1, VAR_2, VAR_3;

    int VAR_4;

    uint8_t *dst;

    st_sample_t *src;

    snd_pcm_sframes_t avail;



    VAR_2 = audio_pcm_hw_get_live_out (VAR_0);

    if (!VAR_2) {

        return 0;

    }



    avail = alsa_get_avail (alsa->handle);

    if (avail < 0) {

        dolog ("Could not get number of available playback frames\n");

        return 0;

    }



    VAR_3 = audio_MIN (VAR_2, avail);

    VAR_4 = VAR_3;

    VAR_1 = VAR_0->VAR_1;

    while (VAR_4) {

        int VAR_5 = VAR_0->VAR_4 - VAR_1;

        int VAR_6 = audio_MIN (VAR_4, VAR_5);

        snd_pcm_sframes_t written;



        src = VAR_0->mix_buf + VAR_1;

        dst = advance (alsa->pcm_buf, VAR_1 << VAR_0->info.shift);



        VAR_0->clip (dst, src, VAR_6);



        while (VAR_6) {

            written = snd_pcm_writei (alsa->handle, dst, VAR_6);



            if (written <= 0) {

                switch (written) {

                case 0:

                    if (conf.verbose) {

                        dolog ("Failed to write %d frames (wrote zero)\n", VAR_6);

                    }

                    goto exit;



                case -EPIPE:

                    if (alsa_recover (alsa->handle)) {

                        alsa_logerr (written, "Failed to write %d frames\n",

                                     VAR_6);

                        goto exit;

                    }

                    if (conf.verbose) {

                        dolog ("Recovering from playback xrun\n");

                    }

                    continue;



                case -EAGAIN:

                    goto exit;



                default:

                    alsa_logerr (written, "Failed to write %d frames to %p\n",

                                 VAR_6, dst);

                    goto exit;

                }

            }



            VAR_1 = (VAR_1 + written) % VAR_0->VAR_4;

            VAR_4 -= written;

            VAR_6 -= written;

            dst = advance (dst, written << VAR_0->info.shift);

            src += written;

        }

    }



 exit:

    VAR_0->VAR_1 = VAR_1;

    return VAR_3;

}

static int FUNC_0 (HWVoiceOut *VAR_0)
{ ALSAVoiceOut *alsa = (ALSAVoiceOut *) VAR_0; int VAR_1, VAR_2, VAR_3; int VAR_4; uint8_t *dst; st_sample_t *src; snd_pcm_sframes_t avail; VAR_2 = audio_pcm_hw_get_live_out (VAR_0); if (!VAR_2) { return 0; } avail = alsa_get_avail (alsa->handle); if (avail < 0) { dolog ("Could not get number of available playback frames\n"); return 0; } VAR_3 = audio_MIN (VAR_2, avail); VAR_4 = VAR_3; VAR_1 = VAR_0->VAR_1; while (VAR_4) { int VAR_5 = VAR_0->VAR_4 - VAR_1; int VAR_6 = audio_MIN (VAR_4, VAR_5); snd_pcm_sframes_t written; src = VAR_0->mix_buf + VAR_1; dst = advance (alsa->pcm_buf, VAR_1 << VAR_0->info.shift); VAR_0->clip (dst, src, VAR_6); while (VAR_6) { written = snd_pcm_writei (alsa->handle, dst, VAR_6); if (written <= 0) { switch (written) { case 0:
if (conf.verbose) { dolog ("Failed to write %d frames (wrote zero)\n", VAR_6); } goto exit; case -EPIPE:
if (alsa_recover (alsa->handle)) { alsa_logerr (written, "Failed to write %d frames\n",
VAR_6); goto exit; } if (conf.verbose) { dolog ("Recovering from playback xrun\n"); } continue; case -EAGAIN:
goto exit; default:
alsa_logerr (written, "Failed to write %d frames to %p\n",
VAR_6, dst); goto exit; } } VAR_1 = (VAR_1 + written) % VAR_0->VAR_4; VAR_4 -= written; VAR_6 -= written; dst = advance (dst, written << VAR_0->info.shift); src += written; } } exit:
VAR_0->VAR_1 = VAR_1; return VAR_3; }