X-Git-Url: http://git.chise.org/gitweb/?p=chise%2Fxemacs-chise.git.1;a=blobdiff_plain;f=src%2Flinuxplay.c;h=4108a19cef661889f241c3d30d975ef9490ae6c7;hp=bf64eac7bcd9939e4af49005c312a14ea0d0ba5c;hb=f7019bf646d0d4e750e0186d6e912ec7a3b9da90;hpb=3e447015251ce6dcde843cbed10d9033d5538622 diff --git a/src/linuxplay.c b/src/linuxplay.c index bf64eac..4108a19 100644 --- a/src/linuxplay.c +++ b/src/linuxplay.c @@ -58,10 +58,11 @@ #endif #include "miscplay.h" +#include "nativesound.h" #include #include -#include SOUNDCARD_H_PATH /* Path computed by configure */ +#include SOUNDCARD_H_FILE /* Path computed by configure */ #include #include #include @@ -277,8 +278,11 @@ static int audio_init(int mixx_fd, int auddio_fd, int fmt, int speed, } /* XEmacs requires code both for playback of pre-loaded data and for playback - from a soundfile; we use one function for both cases */ -static void linux_play_data_or_file(int fd,unsigned char *data, + from a soundfile; we use one function for both cases. + + Returns 1 on succes. 0 otherwise. +*/ +static int linux_play_data_or_file(int fd,unsigned char *data, int length,int volume) { size_t (*parsesndfile)(void **dayta,size_t *sz,void **outbuf); @@ -286,17 +290,18 @@ static void linux_play_data_or_file(int fd,unsigned char *data, fmtType ffmt; int fmt,speed,tracks; unsigned char *pptr,*optr,*cptr,*sptr; - int wrtn,rrtn,crtn,prtn; - unsigned char sndbuf[SNDBUFSZ]; + int wrtn, crtn; + size_t prtn, rrtn; + unsigned char sndbuf[SNDBUFSZ]; /* We need to read at least the header information before we can start doing anything */ if (!data || length < HEADERSZ) { - if (fd < 0) return; + if (fd < 0) return 0; else { length = read(fd,sndbuf,SNDBUFSZ); if (length < HEADERSZ) - return; + return 0; data = sndbuf; length = SNDBUFSZ; } } @@ -305,14 +310,16 @@ static void linux_play_data_or_file(int fd,unsigned char *data, if (ffmt != fmtRaw && ffmt != fmtSunAudio && ffmt != fmtWave) { warn("Unsupported file format (neither RAW, nor Sun/DECAudio, nor WAVE)"); - return; } + return 0; } /* The VoxWare-SDK discourages opening /dev/audio; opening /dev/dsp and properly initializing it via ioctl() is preferred */ if ((audio_fd=open(audio_dev, O_WRONLY | O_NONBLOCK, 0)) < 0) { - perror(audio_dev); + /* JV. Much too verbose. In addition this can crash. See NOTE: in + Fplay_sound + perror(audio_dev); */ if (mix_fd > 0 && mix_fd != audio_fd) { close(mix_fd); mix_fd = -1; } - return; } + return 0; } /* The VoxWare-SDK discourages direct manipulation of the mixer device as this could lead to problems, when multiple sound cards are installed */ @@ -332,9 +339,9 @@ static void linux_play_data_or_file(int fd,unsigned char *data, device; repeat until all data has been processed */ rrtn = length; do { - for (pptr = data; (prtn = parsesndfile((void **)&pptr,(size_t *)&rrtn, + for (pptr = data; (prtn = parsesndfile((void **)&pptr, &rrtn, (void **)&optr)) > 0; ) - for (cptr = optr; (crtn = sndcnv((void **)&cptr,(size_t *) &prtn, + for (cptr = optr; (crtn = sndcnv((void **)&cptr, &prtn, (void **)&sptr)) > 0; ) { for (;;) { if ((wrtn = write(audio_fd,sptr,crtn)) < 0) { @@ -356,7 +363,7 @@ static void linux_play_data_or_file(int fd,unsigned char *data, if (ffmt == fmtWave) parse_wave_complete(); - + END_OF_PLAY: /* Now cleanup all used resources */ @@ -378,12 +385,11 @@ END_OF_PLAY: close(audio_fd); audio_fd = -1; - return; + return 1; } /* Call "linux_play_data_or_file" with the appropriate parameters for playing a soundfile */ -void play_sound_file (char *sound_file, int volume); void play_sound_file (char *sound_file, int volume) { int fd; @@ -398,9 +404,7 @@ void play_sound_file (char *sound_file, int volume) /* Call "linux_play_data_or_file" with the appropriate parameters for playing pre-loaded data */ -void play_sound_data (unsigned char *data, int length, int volume); -void play_sound_data (unsigned char *data, int length, int volume) +int play_sound_data (unsigned char *data, int length, int volume) { - linux_play_data_or_file(-1,data,length,volume); - return; + return linux_play_data_or_file(-1,data,length,volume); }