1 /* audio.c -- audio management stuff
3 * author: hackbard@hackdaworld.dyndns.org
9 int audio_init(t_audio *audio,int outfd) {
13 dprintf(outfd,"[audio] initializing audio ...\n");
15 if((audio->dsp_fd=open(audio->dsp_dev,O_RDWR))<0) {
16 dprintf(audio->outfd,"[audio] open call");
20 if(ioctl(audio->dsp_fd,SNDCTL_DSP_GETCAPS,&(audio->dsp_cap))==-1) {
21 dprintf(audio->outfd,"[audio] ioctl call");
25 if(!(audio->dsp_cap&DSP_CAP_DUPLEX)) {
26 dprintf(audio->outfd,"[audio] no duplex support\n");
33 int audio_setup(t_audio *audio) {
37 dprintf(audio->outfd,"[audio] setting up sound device & allocating record/playback buffer\n");
40 if(ioctl(audio->dsp_fd,SNDCTL_DSP_SETFMT,&tmp)==-1) {
41 dprintf(audio->outfd,"[audio] ioctl call (SNDCTL_DSP_SETFMT)");
45 dprintf(audio->outfd,"[audio] fmt (%d) not supported\n",tmp);
50 if(ioctl(audio->dsp_fd,SNDCTL_DSP_SPEED,&tmp)==-1) {
51 dprintf(audio->outfd,"[audio] ioctl call (SNDCTL_DSP_SPEED)");
54 if(tmp!=audio->speed) {
55 dprintf(audio->outfd,"[audio] speed (%d) not supported\n",tmp);
59 if(ioctl(audio->dsp_fd,SNDCTL_DSP_GETBLKSIZE,&(audio->blksize))==-1) {
60 dprintf(audio->outfd,"[audio] ioctl call (SNDCTL_DSP_GETBLKSIZE)");
64 if((audio->play_data=(unsigned char *)malloc(audio->blksize))==NULL) {
65 dprintf(audio->outfd,"[audio] malloc call");
68 if((audio->rec_data=(unsigned char *)malloc(audio->blksize))==NULL) {
69 dprintf(audio->outfd,"[audio] malloc call");
76 int audio_shutdown(t_audio *audio) {
78 dprintf(audio->outfd,"[audio] shutdown\n");
80 free(audio->play_data);
81 free(audio->rec_data);
83 if(close(audio->dsp_fd)==-1) {
84 dprintf(audio->outfd,"[audio] close call");
91 int audio_play(t_audio *audio,int len) {
99 if((count=write(audio->dsp_fd,audio->play_data+len-left,left))==-1) {
100 dprintf(audio->outfd,"[audio] write call");
109 int audio_record(t_audio *audio,int len) {
117 if((count=read(audio->dsp_fd,audio->rec_data+len-left,left))==-1) {
118 dprintf(audio->outfd,"[audio] read call");