Mercurial > pmdwin
view oss_audio.c @ 4:c8875256b767
Use stdio for console output, update usage, and use sensible exit values.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Tue, 21 May 2013 12:10:27 +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