From: hackbard Date: Sun, 26 Mar 2006 17:51:53 +0000 (+0000) Subject: small mods to audio api (compatible behaviour ..) X-Git-Url: https://hackdaworld.org/gitweb/?a=commitdiff_plain;h=98c3c077422896a148e9788377803bd968d5288f;p=my-code%2Fapi.git small mods to audio api (compatible behaviour ..) --- diff --git a/audio/audio.c b/audio/audio.c index 7bacdac..8402af5 100644 --- a/audio/audio.c +++ b/audio/audio.c @@ -6,22 +6,24 @@ #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; } @@ -32,39 +34,39 @@ int audio_setup(t_audio *audio) { 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; } @@ -73,13 +75,13 @@ int audio_setup(t_audio *audio) { 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; } @@ -95,7 +97,7 @@ int audio_play(t_audio *audio,int len) { 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; @@ -113,7 +115,7 @@ int audio_record(t_audio *audio,int len) { 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; diff --git a/audio/audio.h b/audio/audio.h index 33e90cb..f0874f0 100644 --- a/audio/audio.h +++ b/audio/audio.h @@ -28,6 +28,7 @@ /* audio specific variables */ typedef struct s_audio { + int outfd; int dsp_fd; int mixer_fd; char dsp_dev[MAX_CHAR_DEVICE]; @@ -44,7 +45,7 @@ typedef struct s_audio { } t_audio; /* function prototypes */ -int audio_init(t_audio *audio); +int audio_init(t_audio *audio,int outfd); int audio_setup(t_audio *audio); int audio_shutdown(t_audio *audio); int audio_play(t_audio *audio,int len);