aboutsummaryrefslogtreecommitdiff
path: root/doc/examples/SoundRecorder/src/soundcard.c
blob: 14b581b2404e41e3717ccffbe3fd8cbb537233d2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/* by Luis Figueiredo (stdio@netc.pt)
 *
 * file: soundcard.c
 *
 * description: handlers soundcard setup
 *
 * date: 17:00,13-00-2002
 */

#include "soundcard.h"






int soundcard_init(const char *dev, struct soundcard_setup *ss) {
        int ret;
	int soundfd;
	soundfd=open(dev,O_RDWR|O_NONBLOCK);
	if(soundfd <1) {
		perror("open");
		return -1;
	}
        IFDEBUG(fprintf(stderr,"soundcard.c: Setting soundcard:\n"));
        IFDEBUG(fprintf(stderr,"soundcard.c: rate: %d\n",ss->rate));
        ret=ioctl(soundfd,SNDCTL_DSP_SPEED,&ss->rate);
        if(ret==-1) {
                perror("ioctl");
                return-1 ;
        };
        IFDEBUG(fprintf(stderr,"soundcard.c: channels: %d\n",ss->channels));
        ret=ioctl(soundfd,SNDCTL_DSP_CHANNELS,&ss->channels);
        if(ret==-1) {
                perror("ioctl");
                return -1;
        };
        IFDEBUG(fprintf(stderr,"soundcard.c: fmt %d\n",ss->fmt));
        ret=ioctl(soundfd,SNDCTL_DSP_SETFMT,&ss->fmt);
        if(ret==-1) {
                perror("ioctl");
                return -1;
        };
        IFDEBUG(fprintf(stderr,"Sound card setup sucessfull\n"));
	return soundfd;
};