view oss_audio.c @ 3:8ad174416431

Convert the last EUC-JP file to UTF-8.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Tue, 21 May 2013 10:45:37 +0200
parents c55ea9478c80
children
line wrap: on
line source

#if !defined(WIN32) && !defined(WIN64)
#include <stdint.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/soundcard.h>
#include <sys/ioctl.h>

int oss_audio_open(uint32_t oss_audio_rate, uint8_t nchannels)
{
    int afd = -1, tmp = 0;

    /* open the sound device */
    if ((afd = open("/dev/dsp", O_WRONLY, 0)) == -1)
    {   /* Opening device failed */
        return(-2);
    }

    tmp = AFMT_S16_NE;
    /* set the sound driver audio format for playback */
    if (ioctl(afd, SNDCTL_DSP_SETFMT, &tmp) == -1)
    {   /* Fatal error */
        goto err;
    }

    /* set the sound driver number of channels for playback */
    tmp = (nchannels-1);
    if (ioctl(afd, SNDCTL_DSP_STEREO, &tmp) == -1)
    {   /* Fatal error */
        goto err;
    }

    /* set the sound driver number playback rate */
    tmp = oss_audio_rate;
    if (ioctl(afd, SNDCTL_DSP_SPEED, &tmp) == -1)
    { /* Fatal error */
        goto err;
    }

    return afd;
err:
    close(afd);
    return(-1);
}
#endif