static void sdl_callback (void *opaque, Uint8 *buf, int len)

{

    SDLVoiceOut *sdl = opaque;

    SDLAudioState *s = &glob_sdl;

    HWVoiceOut *hw = &sdl->hw;

    int samples = len >> hw->info.shift;



    if (s->exit) {

        return;

    }



    while (samples) {

        int to_mix, decr;



        /* dolog ("in callback samples=%d\n", samples); */

        sdl_wait (s, "sdl_callback");

        if (s->exit) {

            return;

        }



        if (sdl_lock (s, "sdl_callback")) {

            return;

        }



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

            dolog ("sdl->live=%d hw->samples=%d\n",

                   sdl->live, hw->samples);

            return;

        }



        if (!sdl->live) {

            goto again;

        }



        /* dolog ("in callback live=%d\n", live); */

        to_mix = audio_MIN (samples, sdl->live);

        decr = to_mix;

        while (to_mix) {

            int chunk = audio_MIN (to_mix, hw->samples - hw->rpos);

            st_sample_t *src = hw->mix_buf + hw->rpos;



            /* dolog ("in callback to_mix %d, chunk %d\n", to_mix, chunk); */

            hw->clip (buf, src, chunk);

            sdl->rpos = (sdl->rpos + chunk) % hw->samples;

            to_mix -= chunk;

            buf += chunk << hw->info.shift;

        }

        samples -= decr;

        sdl->live -= decr;

        sdl->decr += decr;



    again:

        if (sdl_unlock (s, "sdl_callback")) {

            return;

        }

    }

    /* dolog ("done len=%d\n", len); */

}

static void sdl_callback (void *opaque, Uint8 *buf, int len)

{

    SDLVoiceOut *sdl = opaque;

    SDLAudioState *s = &glob_sdl;

    HWVoiceOut *hw = &sdl->hw;

    int samples = len >> hw->info.shift;



    if (s->exit) {

        return;

    }



    while (samples) {

        int to_mix, decr;



        

        sdl_wait (s, "sdl_callback");

        if (s->exit) {

            return;

        }



        if (sdl_lock (s, "sdl_callback")) {

            return;

        }



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

            dolog ("sdl->live=%d hw->samples=%d\n",

                   sdl->live, hw->samples);

            return;

        }



        if (!sdl->live) {

            goto again;

        }



        

        to_mix = audio_MIN (samples, sdl->live);

        decr = to_mix;

        while (to_mix) {

            int chunk = audio_MIN (to_mix, hw->samples - hw->rpos);

            st_sample_t *src = hw->mix_buf + hw->rpos;



            

            hw->clip (buf, src, chunk);

            sdl->rpos = (sdl->rpos + chunk) % hw->samples;

            to_mix -= chunk;

            buf += chunk << hw->info.shift;

        }

        samples -= decr;

        sdl->live -= decr;

        sdl->decr += decr;



    again:

        if (sdl_unlock (s, "sdl_callback")) {

            return;

        }

    }

    

}

static void FUNC_0 (void *VAR_0, Uint8 *VAR_1, int VAR_2)

{

    SDLVoiceOut *sdl = VAR_0;

    SDLAudioState *s = &glob_sdl;

    HWVoiceOut *hw = &sdl->hw;

    int VAR_3 = VAR_2 >> hw->info.shift;



    if (s->exit) {

        return;

    }



    while (VAR_3) {

        int VAR_4, VAR_5;



        

        sdl_wait (s, "FUNC_0");

        if (s->exit) {

            return;

        }



        if (sdl_lock (s, "FUNC_0")) {

            return;

        }



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

            dolog ("sdl->live=%d hw->VAR_3=%d\n",

                   sdl->live, hw->VAR_3);

            return;

        }



        if (!sdl->live) {

            goto again;

        }



        

        VAR_4 = audio_MIN (VAR_3, sdl->live);

        VAR_5 = VAR_4;

        while (VAR_4) {

            int VAR_6 = audio_MIN (VAR_4, hw->VAR_3 - hw->rpos);

            st_sample_t *src = hw->mix_buf + hw->rpos;



            

            hw->clip (VAR_1, src, VAR_6);

            sdl->rpos = (sdl->rpos + VAR_6) % hw->VAR_3;

            VAR_4 -= VAR_6;

            VAR_1 += VAR_6 << hw->info.shift;

        }

        VAR_3 -= VAR_5;

        sdl->live -= VAR_5;

        sdl->VAR_5 += VAR_5;



    again:

        if (sdl_unlock (s, "FUNC_0")) {

            return;

        }

    }

    

}

static void FUNC_0 (void *VAR_0, Uint8 *VAR_1, int VAR_2)
{ SDLVoiceOut *sdl = VAR_0; SDLAudioState *s = &glob_sdl; HWVoiceOut *hw = &sdl->hw; int VAR_3 = VAR_2 >> hw->info.shift; if (s->exit) { return; } while (VAR_3) { int VAR_4, VAR_5; sdl_wait (s, "FUNC_0"); if (s->exit) { return; } if (sdl_lock (s, "FUNC_0")) { return; } if (audio_bug (AUDIO_FUNC, sdl->live < 0 || sdl->live > hw->VAR_3)) { dolog ("sdl->live=%d hw->VAR_3=%d\n",
sdl->live, hw->VAR_3); return; } if (!sdl->live) { goto again; } VAR_4 = audio_MIN (VAR_3, sdl->live); VAR_5 = VAR_4; while (VAR_4) { int VAR_6 = audio_MIN (VAR_4, hw->VAR_3 - hw->rpos); st_sample_t *src = hw->mix_buf + hw->rpos; hw->clip (VAR_1, src, VAR_6); sdl->rpos = (sdl->rpos + VAR_6) % hw->VAR_3; VAR_4 -= VAR_6; VAR_1 += VAR_6 << hw->info.shift; } VAR_3 -= VAR_5; sdl->live -= VAR_5; sdl->VAR_5 += VAR_5; again:
if (sdl_unlock (s, "FUNC_0")) { return; } } }