Mercurial > hg > xemacs-beta
comparison src/linuxplay.c @ 406:b8cc9ab3f761 r21-2-33
Import from CVS: tag r21-2-33
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:17:09 +0200 |
parents | 74fd4e045ea6 |
children | 697ef44129c6 |
comparison
equal
deleted
inserted
replaced
405:0e08f63c74d2 | 406:b8cc9ab3f761 |
---|---|
56 #ifdef HAVE_CONFIG_H | 56 #ifdef HAVE_CONFIG_H |
57 #include <config.h> | 57 #include <config.h> |
58 #endif | 58 #endif |
59 | 59 |
60 #include "miscplay.h" | 60 #include "miscplay.h" |
61 #include "nativesound.h" | |
61 | 62 |
62 #include <errno.h> | 63 #include <errno.h> |
63 #include <fcntl.h> | 64 #include <fcntl.h> |
64 #include SOUNDCARD_H_PATH /* Path computed by configure */ | 65 #include SOUNDCARD_H_FILE /* Path computed by configure */ |
65 #include <stdio.h> | 66 #include <stdio.h> |
66 #include <stdlib.h> | 67 #include <stdlib.h> |
67 #include <string.h> | 68 #include <string.h> |
68 #include <fcntl.h> | 69 #include <fcntl.h> |
69 #include <sys/file.h> | 70 #include <sys/file.h> |
275 | 276 |
276 return(1); | 277 return(1); |
277 } | 278 } |
278 | 279 |
279 /* XEmacs requires code both for playback of pre-loaded data and for playback | 280 /* XEmacs requires code both for playback of pre-loaded data and for playback |
280 from a soundfile; we use one function for both cases */ | 281 from a soundfile; we use one function for both cases. |
281 static void linux_play_data_or_file(int fd,unsigned char *data, | 282 |
283 Returns 1 on succes. 0 otherwise. | |
284 */ | |
285 static int linux_play_data_or_file(int fd,unsigned char *data, | |
282 int length,int volume) | 286 int length,int volume) |
283 { | 287 { |
284 size_t (*parsesndfile)(void **dayta,size_t *sz,void **outbuf); | 288 size_t (*parsesndfile)(void **dayta,size_t *sz,void **outbuf); |
285 size_t (*sndcnv)(void **dayta,size_t *sz,void **); | 289 size_t (*sndcnv)(void **dayta,size_t *sz,void **); |
286 fmtType ffmt; | 290 fmtType ffmt; |
290 unsigned char sndbuf[SNDBUFSZ]; | 294 unsigned char sndbuf[SNDBUFSZ]; |
291 | 295 |
292 /* We need to read at least the header information before we can start | 296 /* We need to read at least the header information before we can start |
293 doing anything */ | 297 doing anything */ |
294 if (!data || length < HEADERSZ) { | 298 if (!data || length < HEADERSZ) { |
295 if (fd < 0) return; | 299 if (fd < 0) return 0; |
296 else { | 300 else { |
297 length = read(fd,sndbuf,SNDBUFSZ); | 301 length = read(fd,sndbuf,SNDBUFSZ); |
298 if (length < HEADERSZ) | 302 if (length < HEADERSZ) |
299 return; | 303 return 0; |
300 data = sndbuf; | 304 data = sndbuf; |
301 length = SNDBUFSZ; } | 305 length = SNDBUFSZ; } |
302 } | 306 } |
303 | 307 |
304 ffmt = analyze_format(data,&fmt,&speed,&tracks,&parsesndfile); | 308 ffmt = analyze_format(data,&fmt,&speed,&tracks,&parsesndfile); |
305 | 309 |
306 if (ffmt != fmtRaw && ffmt != fmtSunAudio && ffmt != fmtWave) { | 310 if (ffmt != fmtRaw && ffmt != fmtSunAudio && ffmt != fmtWave) { |
307 warn("Unsupported file format (neither RAW, nor Sun/DECAudio, nor WAVE)"); | 311 warn("Unsupported file format (neither RAW, nor Sun/DECAudio, nor WAVE)"); |
308 return; } | 312 return 0; } |
309 | 313 |
310 /* The VoxWare-SDK discourages opening /dev/audio; opening /dev/dsp and | 314 /* The VoxWare-SDK discourages opening /dev/audio; opening /dev/dsp and |
311 properly initializing it via ioctl() is preferred */ | 315 properly initializing it via ioctl() is preferred */ |
312 if ((audio_fd=open(audio_dev, O_WRONLY | O_NONBLOCK, 0)) < 0) { | 316 if ((audio_fd=open(audio_dev, O_WRONLY | O_NONBLOCK, 0)) < 0) { |
313 perror(audio_dev); | 317 /* JV. Much too verbose. In addition this can crash. See NOTE: in |
318 Fplay_sound | |
319 perror(audio_dev); */ | |
314 if (mix_fd > 0 && mix_fd != audio_fd) { close(mix_fd); mix_fd = -1; } | 320 if (mix_fd > 0 && mix_fd != audio_fd) { close(mix_fd); mix_fd = -1; } |
315 return; } | 321 return 0; } |
316 | 322 |
317 /* The VoxWare-SDK discourages direct manipulation of the mixer device as | 323 /* The VoxWare-SDK discourages direct manipulation of the mixer device as |
318 this could lead to problems, when multiple sound cards are installed */ | 324 this could lead to problems, when multiple sound cards are installed */ |
319 mix_fd = audio_fd; | 325 mix_fd = audio_fd; |
320 | 326 |
354 break; | 360 break; |
355 } while (rrtn > 0); | 361 } while (rrtn > 0); |
356 | 362 |
357 if (ffmt == fmtWave) | 363 if (ffmt == fmtWave) |
358 parse_wave_complete(); | 364 parse_wave_complete(); |
359 | 365 |
360 | 366 |
361 END_OF_PLAY: | 367 END_OF_PLAY: |
362 /* Now cleanup all used resources */ | 368 /* Now cleanup all used resources */ |
363 | 369 |
364 ioctl(audio_fd,SNDCTL_DSP_SYNC,NULL); | 370 ioctl(audio_fd,SNDCTL_DSP_SYNC,NULL); |
376 mix_fd = -1; } | 382 mix_fd = -1; } |
377 | 383 |
378 close(audio_fd); | 384 close(audio_fd); |
379 audio_fd = -1; | 385 audio_fd = -1; |
380 | 386 |
381 return; | 387 return 1; |
382 } | 388 } |
383 | 389 |
384 /* Call "linux_play_data_or_file" with the appropriate parameters for | 390 /* Call "linux_play_data_or_file" with the appropriate parameters for |
385 playing a soundfile */ | 391 playing a soundfile */ |
386 void play_sound_file (char *sound_file, int volume); | |
387 void play_sound_file (char *sound_file, int volume) | 392 void play_sound_file (char *sound_file, int volume) |
388 { | 393 { |
389 int fd; | 394 int fd; |
390 | 395 |
391 if ((fd=open(sound_file,O_RDONLY,0)) < 0) { | 396 if ((fd=open(sound_file,O_RDONLY,0)) < 0) { |
396 return; | 401 return; |
397 } | 402 } |
398 | 403 |
399 /* Call "linux_play_data_or_file" with the appropriate parameters for | 404 /* Call "linux_play_data_or_file" with the appropriate parameters for |
400 playing pre-loaded data */ | 405 playing pre-loaded data */ |
401 void play_sound_data (unsigned char *data, int length, int volume); | 406 int play_sound_data (unsigned char *data, int length, int volume) |
402 void play_sound_data (unsigned char *data, int length, int volume) | |
403 { | 407 { |
404 linux_play_data_or_file(-1,data,length,volume); | 408 return linux_play_data_or_file(-1,data,length,volume); |
405 return; | |
406 } | 409 } |