static void
SUNAUDIO_PlayDevice(_THIS)
{
    /* Write the audio data */
    if (this->hidden->ulaw_only) {
        /* Assuming that this->spec.freq >= 8000 Hz */
        int accum, incr, pos;
        Uint8 *aubuf;

        accum = 0;
        incr = this->spec.freq / 8;
        aubuf = this->hidden->ulaw_buf;
        switch (this->hidden->audio_fmt & 0xFF) {
        case 8:
            {
                Uint8 *sndbuf;

                sndbuf = this->hidden->mixbuf;
                for (pos = 0; pos < this->hidden->fragsize; ++pos) {
                    *aubuf = snd2au((0x80 - *sndbuf) * 64);
                    accum += incr;
                    while (accum > 0) {
                        accum -= 1000;
                        sndbuf += 1;
                    }
                    aubuf += 1;
                }
            }
            break;
        case 16:
            {
                Sint16 *sndbuf;

                sndbuf = (Sint16 *) this->hidden->mixbuf;
                for (pos = 0; pos < this->hidden->fragsize; ++pos) {
                    *aubuf = snd2au(*sndbuf / 4);
                    accum += incr;
                    while (accum > 0) {
                        accum -= 1000;
                        sndbuf += 1;
                    }
                    aubuf += 1;
                }
            }
            break;
        }
#ifdef DEBUG_AUDIO
        CheckUnderflow(this);
#endif
        if (write(this->hidden->audio_fd, this->hidden->ulaw_buf,
            this->hidden->fragsize) < 0) {
            /* Assume fatal error, for now */
            SDL_OpenedAudioDeviceDisconnected(this);
        }
        this->hidden->written += this->hidden->fragsize;
    } else {
#ifdef DEBUG_AUDIO
        CheckUnderflow(this);
#endif
        if (write(this->hidden->audio_fd, this->hidden->mixbuf,
            this->spec.size) < 0) {
            /* Assume fatal error, for now */
            SDL_OpenedAudioDeviceDisconnected(this);
        }
        this->hidden->written += this->hidden->fragsize;
    }
}
Ejemplo n.º 2
0
void
DSP_PlayAudio(_THIS)
{
    /* Write the audio data */
    if (ulaw_only) {
        /* Assuming that this->spec.freq >= 8000 Hz */
        int accum, incr, pos;
        Uint8 *aubuf;

        accum = 0;
        incr = this->spec.freq / 8;
        aubuf = ulaw_buf;
        switch (audio_fmt & 0xFF) {
        case 8:
            {
                Uint8 *sndbuf;

                sndbuf = mixbuf;
                for (pos = 0; pos < fragsize; ++pos) {
                    *aubuf = snd2au((0x80 - *sndbuf) * 64);
                    accum += incr;
                    while (accum > 0) {
                        accum -= 1000;
                        sndbuf += 1;
                    }
                    aubuf += 1;
                }
            }
            break;
        case 16:
            {
                Sint16 *sndbuf;

                sndbuf = (Sint16 *) mixbuf;
                for (pos = 0; pos < fragsize; ++pos) {
                    *aubuf = snd2au(*sndbuf / 4);
                    accum += incr;
                    while (accum > 0) {
                        accum -= 1000;
                        sndbuf += 1;
                    }
                    aubuf += 1;
                }
            }
            break;
        }
#ifdef DEBUG_AUDIO
        CheckUnderflow(this);
#endif
        if (write(audio_fd, ulaw_buf, fragsize) < 0) {
            /* Assume fatal error, for now */
            this->enabled = 0;
        }
        written += fragsize;
    } else {
#ifdef DEBUG_AUDIO
        CheckUnderflow(this);
#endif
        if (write(audio_fd, mixbuf, this->spec.size) < 0) {
            /* Assume fatal error, for now */
            this->enabled = 0;
        }
        written += fragsize;
    }
}