#include "audio.h"
-int audio_init(t_audio *audio) {
+int audio_init(t_audio *audio,int outfd) {
- fprintf(stderr,"[audio] initializing audio ...\n");
+ audio->outfd=outfd;
- if((audio->dsp_fd=open(audio->dsp_dev,O_RDWR))==-1) {
- perror("[audio] open call");
+ dprintf(outfd,"[audio] initializing audio ...\n");
+
+ if((audio->dsp_fd=open(audio->dsp_dev,O_RDWR))<0) {
+ dprintf(audio->outfd,"[audio] open call");
return A_ERROR;
}
if(ioctl(audio->dsp_fd,SNDCTL_DSP_GETCAPS,&(audio->dsp_cap))==-1) {
- perror("[audio] ioctl call");
+ dprintf(audio->outfd,"[audio] ioctl call");
return A_ERROR;
}
if(!(audio->dsp_cap&DSP_CAP_DUPLEX)) {
- fprintf(stderr,"[audio] no duplex support\n");
+ dprintf(audio->outfd,"[audio] no duplex support\n");
return A_ERROR;
}
int tmp;
- fprintf(stderr,"[audio] setting up sound device & allocating record/playback buffer\n");
+ dprintf(audio->outfd,"[audio] setting up sound device & allocating record/playback buffer\n");
tmp=audio->fmt;
if(ioctl(audio->dsp_fd,SNDCTL_DSP_SETFMT,&tmp)==-1) {
- perror("[audio] ioctl call (SNDCTL_DSP_SETFMT)");
+ dprintf(audio->outfd,"[audio] ioctl call (SNDCTL_DSP_SETFMT)");
return A_ERROR;
}
if(tmp!=audio->fmt) {
- fprintf(stderr,"[audio] FMT not supported\n");
+ dprintf(audio->outfd,"[audio] fmt (%d) not supported\n",tmp);
return A_ERROR;
}
tmp=audio->speed;
if(ioctl(audio->dsp_fd,SNDCTL_DSP_SPEED,&tmp)==-1) {
- perror("[audio] ioctl call (SNDCTL_DSP_SPEED)");
+ dprintf(audio->outfd,"[audio] ioctl call (SNDCTL_DSP_SPEED)");
return A_ERROR;
}
if(tmp!=audio->speed) {
- fprintf(stderr,"[audio] SPEED not supported\n");
+ dprintf(audio->outfd,"[audio] speed (%d) not supported\n",tmp);
return A_ERROR;
}
if(ioctl(audio->dsp_fd,SNDCTL_DSP_GETBLKSIZE,&(audio->blksize))==-1) {
- perror("[audio] ioctl call (SNDCTL_DSP_GETBLKSIZE)");
+ dprintf(audio->outfd,"[audio] ioctl call (SNDCTL_DSP_GETBLKSIZE)");
return A_ERROR;
}
if((audio->play_data=(unsigned char *)malloc(audio->blksize))==NULL) {
- perror("[audio] malloc call");
+ dprintf(audio->outfd,"[audio] malloc call");
return A_ERROR;
}
if((audio->rec_data=(unsigned char *)malloc(audio->blksize))==NULL) {
- perror("[audio] malloc call");
+ dprintf(audio->outfd,"[audio] malloc call");
return A_ERROR;
}
int audio_shutdown(t_audio *audio) {
- fprintf(stderr,"[audio] shutdown\n");
+ dprintf(audio->outfd,"[audio] shutdown\n");
free(audio->play_data);
free(audio->rec_data);
if(close(audio->dsp_fd)==-1) {
- perror("[audio] close call");
+ dprintf(audio->outfd,"[audio] close call");
return A_ERROR;
}
while(left) {
if((count=write(audio->dsp_fd,audio->play_data+len-left,left))==-1) {
- perror("[audio] write call");
+ dprintf(audio->outfd,"[audio] write call");
return A_ERROR;
}
left-=count;
while(left) {
if((count=read(audio->dsp_fd,audio->rec_data+len-left,left))==-1) {
- perror("[audio] read call");
+ dprintf(audio->outfd,"[audio] read call");
return A_ERROR;
}
left-=count;