static int oss_run_out (HWVoiceOut *hw)

{

    OSSVoiceOut *oss = (OSSVoiceOut *) hw;

    int err, rpos, live, decr;

    int samples;

    uint8_t *dst;

    st_sample_t *src;

    struct audio_buf_info abinfo;

    struct count_info cntinfo;

    int bufsize;



    live = audio_pcm_hw_get_live_out (hw);

    if (!live) {

        return 0;

    }



    bufsize = hw->samples << hw->info.shift;



    if (oss->mmapped) {

        int bytes;



        err = ioctl (oss->fd, SNDCTL_DSP_GETOPTR, &cntinfo);

        if (err < 0) {

            oss_logerr (errno, "SNDCTL_DSP_GETOPTR failed\n");

            return 0;

        }



        if (cntinfo.ptr == oss->old_optr) {

            if (abs (hw->samples - live) < 64) {

                dolog ("warning: Overrun\n");

            }

            return 0;

        }



        if (cntinfo.ptr > oss->old_optr) {

            bytes = cntinfo.ptr - oss->old_optr;

        }

        else {

            bytes = bufsize + cntinfo.ptr - oss->old_optr;

        }



        decr = audio_MIN (bytes >> hw->info.shift, live);

    }

    else {

        err = ioctl (oss->fd, SNDCTL_DSP_GETOSPACE, &abinfo);

        if (err < 0) {

            oss_logerr (errno, "SNDCTL_DSP_GETOPTR failed\n");

            return 0;

        }



        if (abinfo.bytes > bufsize) {

            if (conf.debug) {

                dolog ("warning: Invalid available size, size=%d bufsize=%d\n"

                       "please report your OS/audio hw to malc@pulsesoft.com\n",

                       abinfo.bytes, bufsize);

            }

            abinfo.bytes = bufsize;

        }



        if (abinfo.bytes < 0) {

            if (conf.debug) {

                dolog ("warning: Invalid available size, size=%d bufsize=%d\n",

                       abinfo.bytes, bufsize);

            }

            return 0;

        }



        decr = audio_MIN (abinfo.bytes >> hw->info.shift, live);

        if (!decr) {

            return 0;

        }

    }



    samples = decr;

    rpos = hw->rpos;

    while (samples) {

        int left_till_end_samples = hw->samples - rpos;

        int convert_samples = audio_MIN (samples, left_till_end_samples);



        src = hw->mix_buf + rpos;

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



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

        if (!oss->mmapped) {

            int written;



            written = write (oss->fd, dst, convert_samples << hw->info.shift);

            /* XXX: follow errno recommendations ? */

            if (written == -1) {

                oss_logerr (

                    errno,

                    "Failed to write %d bytes of audio data from %p\n",

                    convert_samples << hw->info.shift,

                    dst

                    );

                continue;

            }



            if (written != convert_samples << hw->info.shift) {

                int wsamples = written >> hw->info.shift;

                int wbytes = wsamples << hw->info.shift;

                if (wbytes != written) {

                    dolog ("warning: Misaligned write %d (requested %d), "

                           "alignment %d\n",

                           wbytes, written, hw->info.align + 1);

                }

                decr -= wsamples;

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

                break;

            }

        }



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

        samples -= convert_samples;

    }

    if (oss->mmapped) {

        oss->old_optr = cntinfo.ptr;

    }



    hw->rpos = rpos;

    return decr;

}

static int oss_run_out (HWVoiceOut *hw)

{

    OSSVoiceOut *oss = (OSSVoiceOut *) hw;

    int err, rpos, live, decr;

    int samples;

    uint8_t *dst;

    st_sample_t *src;

    struct audio_buf_info abinfo;

    struct count_info cntinfo;

    int bufsize;



    live = audio_pcm_hw_get_live_out (hw);

    if (!live) {

        return 0;

    }



    bufsize = hw->samples << hw->info.shift;



    if (oss->mmapped) {

        int bytes;



        err = ioctl (oss->fd, SNDCTL_DSP_GETOPTR, &cntinfo);

        if (err < 0) {

            oss_logerr (errno, "SNDCTL_DSP_GETOPTR failed\n");

            return 0;

        }



        if (cntinfo.ptr == oss->old_optr) {

            if (abs (hw->samples - live) < 64) {

                dolog ("warning: Overrun\n");

            }

            return 0;

        }



        if (cntinfo.ptr > oss->old_optr) {

            bytes = cntinfo.ptr - oss->old_optr;

        }

        else {

            bytes = bufsize + cntinfo.ptr - oss->old_optr;

        }



        decr = audio_MIN (bytes >> hw->info.shift, live);

    }

    else {

        err = ioctl (oss->fd, SNDCTL_DSP_GETOSPACE, &abinfo);

        if (err < 0) {

            oss_logerr (errno, "SNDCTL_DSP_GETOPTR failed\n");

            return 0;

        }



        if (abinfo.bytes > bufsize) {

            if (conf.debug) {

                dolog ("warning: Invalid available size, size=%d bufsize=%d\n"

                       "please report your OS/audio hw to malc@pulsesoft.com\n",

                       abinfo.bytes, bufsize);

            }

            abinfo.bytes = bufsize;

        }



        if (abinfo.bytes < 0) {

            if (conf.debug) {

                dolog ("warning: Invalid available size, size=%d bufsize=%d\n",

                       abinfo.bytes, bufsize);

            }

            return 0;

        }



        decr = audio_MIN (abinfo.bytes >> hw->info.shift, live);

        if (!decr) {

            return 0;

        }

    }



    samples = decr;

    rpos = hw->rpos;

    while (samples) {

        int left_till_end_samples = hw->samples - rpos;

        int convert_samples = audio_MIN (samples, left_till_end_samples);



        src = hw->mix_buf + rpos;

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



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

        if (!oss->mmapped) {

            int written;



            written = write (oss->fd, dst, convert_samples << hw->info.shift);

            

            if (written == -1) {

                oss_logerr (

                    errno,

                    "Failed to write %d bytes of audio data from %p\n",

                    convert_samples << hw->info.shift,

                    dst

                    );

                continue;

            }



            if (written != convert_samples << hw->info.shift) {

                int wsamples = written >> hw->info.shift;

                int wbytes = wsamples << hw->info.shift;

                if (wbytes != written) {

                    dolog ("warning: Misaligned write %d (requested %d), "

                           "alignment %d\n",

                           wbytes, written, hw->info.align + 1);

                }

                decr -= wsamples;

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

                break;

            }

        }



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

        samples -= convert_samples;

    }

    if (oss->mmapped) {

        oss->old_optr = cntinfo.ptr;

    }



    hw->rpos = rpos;

    return decr;

}

static int FUNC_0 (HWVoiceOut *VAR_0)

{

    OSSVoiceOut *oss = (OSSVoiceOut *) VAR_0;

    int VAR_1, VAR_2, VAR_3, VAR_4;

    int VAR_5;

    uint8_t *dst;

    st_sample_t *src;

    struct audio_buf_info VAR_6;

    struct count_info VAR_7;

    int VAR_8;



    VAR_3 = audio_pcm_hw_get_live_out (VAR_0);

    if (!VAR_3) {

        return 0;

    }



    VAR_8 = VAR_0->VAR_5 << VAR_0->info.shift;



    if (oss->mmapped) {

        int VAR_9;



        VAR_1 = ioctl (oss->fd, SNDCTL_DSP_GETOPTR, &VAR_7);

        if (VAR_1 < 0) {

            oss_logerr (errno, "SNDCTL_DSP_GETOPTR failed\n");

            return 0;

        }



        if (VAR_7.ptr == oss->old_optr) {

            if (abs (VAR_0->VAR_5 - VAR_3) < 64) {

                dolog ("warning: Overrun\n");

            }

            return 0;

        }



        if (VAR_7.ptr > oss->old_optr) {

            VAR_9 = VAR_7.ptr - oss->old_optr;

        }

        else {

            VAR_9 = VAR_8 + VAR_7.ptr - oss->old_optr;

        }



        VAR_4 = audio_MIN (VAR_9 >> VAR_0->info.shift, VAR_3);

    }

    else {

        VAR_1 = ioctl (oss->fd, SNDCTL_DSP_GETOSPACE, &VAR_6);

        if (VAR_1 < 0) {

            oss_logerr (errno, "SNDCTL_DSP_GETOPTR failed\n");

            return 0;

        }



        if (VAR_6.VAR_9 > VAR_8) {

            if (conf.debug) {

                dolog ("warning: Invalid available size, size=%d VAR_8=%d\n"

                       "please report your OS/audio VAR_0 to malc@pulsesoft.com\n",

                       VAR_6.VAR_9, VAR_8);

            }

            VAR_6.VAR_9 = VAR_8;

        }



        if (VAR_6.VAR_9 < 0) {

            if (conf.debug) {

                dolog ("warning: Invalid available size, size=%d VAR_8=%d\n",

                       VAR_6.VAR_9, VAR_8);

            }

            return 0;

        }



        VAR_4 = audio_MIN (VAR_6.VAR_9 >> VAR_0->info.shift, VAR_3);

        if (!VAR_4) {

            return 0;

        }

    }



    VAR_5 = VAR_4;

    VAR_2 = VAR_0->VAR_2;

    while (VAR_5) {

        int VAR_10 = VAR_0->VAR_5 - VAR_2;

        int VAR_11 = audio_MIN (VAR_5, VAR_10);



        src = VAR_0->mix_buf + VAR_2;

        dst = advance (oss->pcm_buf, VAR_2 << VAR_0->info.shift);



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

        if (!oss->mmapped) {

            int VAR_12;



            VAR_12 = write (oss->fd, dst, VAR_11 << VAR_0->info.shift);

            

            if (VAR_12 == -1) {

                oss_logerr (

                    errno,

                    "Failed to write %d VAR_9 of audio data from %p\n",

                    VAR_11 << VAR_0->info.shift,

                    dst

                    );

                continue;

            }



            if (VAR_12 != VAR_11 << VAR_0->info.shift) {

                int VAR_13 = VAR_12 >> VAR_0->info.shift;

                int VAR_14 = VAR_13 << VAR_0->info.shift;

                if (VAR_14 != VAR_12) {

                    dolog ("warning: Misaligned write %d (requested %d), "

                           "alignment %d\n",

                           VAR_14, VAR_12, VAR_0->info.align + 1);

                }

                VAR_4 -= VAR_13;

                VAR_2 = (VAR_2 + VAR_13) % VAR_0->VAR_5;

                break;

            }

        }



        VAR_2 = (VAR_2 + VAR_11) % VAR_0->VAR_5;

        VAR_5 -= VAR_11;

    }

    if (oss->mmapped) {

        oss->old_optr = VAR_7.ptr;

    }



    VAR_0->VAR_2 = VAR_2;

    return VAR_4;

}

static int FUNC_0 (HWVoiceOut *VAR_0)
{ OSSVoiceOut *oss = (OSSVoiceOut *) VAR_0; int VAR_1, VAR_2, VAR_3, VAR_4; int VAR_5; uint8_t *dst; st_sample_t *src; struct audio_buf_info VAR_6; struct count_info VAR_7; int VAR_8; VAR_3 = audio_pcm_hw_get_live_out (VAR_0); if (!VAR_3) { return 0; } VAR_8 = VAR_0->VAR_5 << VAR_0->info.shift; if (oss->mmapped) { int VAR_9; VAR_1 = ioctl (oss->fd, SNDCTL_DSP_GETOPTR, &VAR_7); if (VAR_1 < 0) { oss_logerr (errno, "SNDCTL_DSP_GETOPTR failed\n"); return 0; } if (VAR_7.ptr == oss->old_optr) { if (abs (VAR_0->VAR_5 - VAR_3) < 64) { dolog ("warning: Overrun\n"); } return 0; } if (VAR_7.ptr > oss->old_optr) { VAR_9 = VAR_7.ptr - oss->old_optr; } else { VAR_9 = VAR_8 + VAR_7.ptr - oss->old_optr; } VAR_4 = audio_MIN (VAR_9 >> VAR_0->info.shift, VAR_3); } else { VAR_1 = ioctl (oss->fd, SNDCTL_DSP_GETOSPACE, &VAR_6); if (VAR_1 < 0) { oss_logerr (errno, "SNDCTL_DSP_GETOPTR failed\n"); return 0; } if (VAR_6.VAR_9 > VAR_8) { if (conf.debug) { dolog ("warning: Invalid available size, size=%d VAR_8=%d\n"
"please report your OS/audio VAR_0 to malc@pulsesoft.com\n",
VAR_6.VAR_9, VAR_8); } VAR_6.VAR_9 = VAR_8; } if (VAR_6.VAR_9 < 0) { if (conf.debug) { dolog ("warning: Invalid available size, size=%d VAR_8=%d\n",
VAR_6.VAR_9, VAR_8); } return 0; } VAR_4 = audio_MIN (VAR_6.VAR_9 >> VAR_0->info.shift, VAR_3); if (!VAR_4) { return 0; } } VAR_5 = VAR_4; VAR_2 = VAR_0->VAR_2; while (VAR_5) { int VAR_10 = VAR_0->VAR_5 - VAR_2; int VAR_11 = audio_MIN (VAR_5, VAR_10); src = VAR_0->mix_buf + VAR_2; dst = advance (oss->pcm_buf, VAR_2 << VAR_0->info.shift); VAR_0->clip (dst, src, VAR_11); if (!oss->mmapped) { int VAR_12; VAR_12 = write (oss->fd, dst, VAR_11 << VAR_0->info.shift); if (VAR_12 == -1) { oss_logerr (
errno,
"Failed to write %d VAR_9 of audio data from %p\n",
VAR_11 << VAR_0->info.shift,
dst
); continue; } if (VAR_12 != VAR_11 << VAR_0->info.shift) { int VAR_13 = VAR_12 >> VAR_0->info.shift; int VAR_14 = VAR_13 << VAR_0->info.shift; if (VAR_14 != VAR_12) { dolog ("warning: Misaligned write %d (requested %d), "
"alignment %d\n",
VAR_14, VAR_12, VAR_0->info.align + 1); } VAR_4 -= VAR_13; VAR_2 = (VAR_2 + VAR_13) % VAR_0->VAR_5; break; } } VAR_2 = (VAR_2 + VAR_11) % VAR_0->VAR_5; VAR_5 -= VAR_11; } if (oss->mmapped) { oss->old_optr = VAR_7.ptr; } VAR_0->VAR_2 = VAR_2; return VAR_4; }