Mercurial > pmdwin
diff oss_audio.c @ 0:c55ea9478c80
Hello Gensokyo!
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Tue, 21 May 2013 10:29:21 +0200 |
parents | |
children |
line wrap: on
line diff
new file mode 100644 --- /dev/null +++ b/oss_audio.c @@ -0,0 +1,46 @@ +#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 +