view oss_audio.c @ 10:e3849cd10ad3 default tip

Build an intermediary fmgen.a archive.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Mon, 08 Sep 2014 17:44:53 +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