1 /* audio.c -- audio management stuff
3 * author: hackbard@hackdaworld.dyndns.org
9 int audio_init(t_audio *audio) {
11 fprintf(stderr,"[audio] initializing audio ...\n");
13 if((audio->dsp_fd=open(audio->dsp_dev,O_RDWR))==-1) {
14 perror("[audio] open call");
18 if(ioctl(audio->dsp_fd,SNDCTL_DSP_GETCAPS,&(audio->dsp_cap))==-1) {
19 perror("[audio] ioctl call");
23 if(!(audio->dsp_cap&DSP_CAP_DUPLEX)) {
24 fprintf(stderr,"[audio] no duplex support\n");
31 int audio_setup(t_audio *audio) {
35 fprintf(stderr,"[audio] setting up sound device & allocating record/playback buffer\n");
38 if(ioctl(audio->dsp_fd,SNDCTL_DSP_SETFMT,&tmp)==-1) {
39 perror("[audio] ioctl call (SNDCTL_DSP_SETFMT)");
43 fprintf(stderr,"[audio] FMT not supported\n");
48 if(ioctl(audio->dsp_fd,SNDCTL_DSP_SPEED,&tmp)==-1) {
49 perror("[audio] ioctl call (SNDCTL_DSP_SPEED)");
52 if(tmp!=audio->speed) {
53 fprintf(stderr,"[audio] SPEED not supported\n");
57 if(ioctl(audio->dsp_fd,SNDCTL_DSP_GETBLKSIZE,&(audio->blksize))==-1) {
58 perror("[audio] ioctl call (SNDCTL_DSP_GETBLKSIZE)");
62 if((audio->play_data=(unsigned char *)malloc(audio->blksize))==NULL) {
63 perror("[audio] malloc call");
66 if((audio->rec_data=(unsigned char *)malloc(audio->blksize))==NULL) {
67 perror("[audio] malloc call");
74 int audio_shutdown(t_audio *audio) {
76 fprintf(stderr,"[audio] shutdown\n");
78 free(audio->play_data);
79 free(audio->rec_data);
81 if(close(audio->dsp_fd)==-1) {
82 perror("[audio] close call");
89 int audio_play(t_audio *audio,int len) {
97 if((count=write(audio->dsp_fd,audio->play_data+len-left,left))==-1) {
98 perror("[audio] write call");
107 int audio_record(t_audio *audio,int len) {
115 if((count=read(audio->dsp_fd,audio->rec_data+len-left,left))==-1) {
116 perror("[audio] read call");