comparison 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
comparison
equal deleted inserted replaced
-1:000000000000 0:c55ea9478c80
1 #if !defined(WIN32) && !defined(WIN64)
2 #include <stdint.h>
3 #include <fcntl.h>
4 #include <unistd.h>
5 #include <sys/stat.h>
6 #include <sys/soundcard.h>
7 #include <sys/ioctl.h>
8
9 int oss_audio_open(uint32_t oss_audio_rate, uint8_t nchannels)
10 {
11 int afd = -1, tmp = 0;
12
13 /* open the sound device */
14 if ((afd = open("/dev/dsp", O_WRONLY, 0)) == -1)
15 { /* Opening device failed */
16 return(-2);
17 }
18
19 tmp = AFMT_S16_NE;
20 /* set the sound driver audio format for playback */
21 if (ioctl(afd, SNDCTL_DSP_SETFMT, &tmp) == -1)
22 { /* Fatal error */
23 goto err;
24 }
25
26 /* set the sound driver number of channels for playback */
27 tmp = (nchannels-1);
28 if (ioctl(afd, SNDCTL_DSP_STEREO, &tmp) == -1)
29 { /* Fatal error */
30 goto err;
31 }
32
33 /* set the sound driver number playback rate */
34 tmp = oss_audio_rate;
35 if (ioctl(afd, SNDCTL_DSP_SPEED, &tmp) == -1)
36 { /* Fatal error */
37 goto err;
38 }
39
40 return afd;
41 err:
42 close(afd);
43 return(-1);
44 }
45 #endif
46