X-Git-Url: https://git.artsoft.org/?p=rocksndiamonds.git;a=blobdiff_plain;f=src%2Fsound.c;h=340ec942b8ebc30d25e62107bdf02a28e30498c5;hp=97484309228100bceaadd6772eb192094d76e09c;hb=50c422d96b6da2c0412b6bd3763e9d1a029a6014;hpb=cfd77b3698baacb01dff3853c96d0be117db1d30 diff --git a/src/sound.c b/src/sound.c index 97484309..340ec942 100644 --- a/src/sound.c +++ b/src/sound.c @@ -14,29 +14,41 @@ #include "sound.h" #include "misc.h" -#ifdef MSDOS -extern void sound_handler(struct SoundControl); -#endif - /*** THE STUFF BELOW IS ONLY USED BY THE SOUND SERVER CHILD PROCESS ***/ -#ifndef MSDOS +static int playing_sounds = 0; static struct SoundControl playlist[MAX_SOUNDS_PLAYING]; static struct SoundControl emptySoundControl = { -1,0,0, FALSE,FALSE,FALSE,FALSE,FALSE, 0,0L,0L,NULL }; + +#ifndef MSDOS static int stereo_volume[PSND_MAX_LEFT2RIGHT+1]; static char premix_first_buffer[SND_BLOCKSIZE]; +#ifdef VOXWARE static char premix_left_buffer[SND_BLOCKSIZE]; static char premix_right_buffer[SND_BLOCKSIZE]; static int premix_last_buffer[SND_BLOCKSIZE]; +#endif /* VOXWARE */ static unsigned char playing_buffer[SND_BLOCKSIZE]; -static int playing_sounds = 0; -#else -struct SoundControl playlist[MAX_SOUNDS_PLAYING]; -struct SoundControl emptySoundControl; -int playing_sounds; +#endif /* MSDOS */ + +/* forward declaration of internal functions */ +#ifdef VOXWARE +static void SoundServer_InsertNewSound(struct SoundControl); +#endif +#ifndef VOXWARE +static unsigned char linear_to_ulaw(int); +static int ulaw_to_linear(unsigned char); +#endif +#ifdef HPUX_AUDIO +static void HPUX_Audio_Control(); +#endif +#ifdef MSDOS +static void SoundServer_InsertNewSound(struct SoundControl); +static void SoundServer_StopSound(int); +static void SoundServer_StopAllSounds(); #endif void SoundServer() @@ -66,14 +78,14 @@ void SoundServer() FD_ZERO(&sound_fdset); FD_SET(sound_pipe[0], &sound_fdset); - for(;;) /* wait for calls from PlaySound(), StopSound(), ... */ + while(1) /* wait for sound playing commands from client */ { FD_SET(sound_pipe[0], &sound_fdset); select(sound_pipe[0]+1, &sound_fdset, NULL, NULL, NULL); if (!FD_ISSET(sound_pipe[0], &sound_fdset)) continue; if (read(sound_pipe[0], &snd_ctrl, sizeof(snd_ctrl)) != sizeof(snd_ctrl)) - Error(ERR_EXIT_SOUNDSERVER, "broken pipe - no sounds"); + Error(ERR_EXIT_SOUND_SERVER, "broken pipe - no sounds"); #ifdef VOXWARE @@ -116,9 +128,10 @@ void SoundServer() if (playing_sounds || snd_ctrl.active) { struct timeval delay = { 0, 0 }; - char *sample_ptr; - long sample_size, max_sample_size; - long fragment_size; + byte *sample_ptr; + long sample_size; + static long max_sample_size = 0; + static long fragment_size = 0; boolean stereo; if (playing_sounds || (sound_device=open(sound_device_name,O_WRONLY))>=0) @@ -249,12 +262,12 @@ void SoundServer() } } -#else /* von '#ifdef VOXWARE' */ +#else /* !VOXWARE */ if (snd_ctrl.active && !snd_ctrl.loop) { struct timeval delay = { 0, 0 }; - char *sample_ptr; + byte *sample_ptr; long sample_size, max_sample_size = SND_BLOCKSIZE; long sample_rate = 8000; /* standard "/dev/audio" sampling rate */ int wait_percent = 90; /* wait 90% of the real playing time */ @@ -270,9 +283,9 @@ void SoundServer() FD_SET(sound_pipe[0], &sound_fdset); /* get pointer and size of the actual sound sample */ - sample_ptr = snd_ctrl.data_ptr+snd_ctrl.playingpos; + sample_ptr = snd_ctrl.data_ptr + snd_ctrl.playingpos; sample_size = - MIN(max_sample_size,snd_ctrl.data_len-snd_ctrl.playingpos); + MIN(max_sample_size, snd_ctrl.data_len - snd_ctrl.playingpos); snd_ctrl.playingpos += sample_size; /* fill the first mixing buffer with original sample */ @@ -303,17 +316,70 @@ void SoundServer() } } -#endif /* von '#ifdef VOXWARE' */ +#endif /* !VOXWARE */ } -#endif +#endif /* !MSDOS */ +} + +#ifdef MSDOS +static void sound_handler(struct SoundControl snd_ctrl) +{ + int i; + + if (snd_ctrl.fade_sound) + { + if (!playing_sounds) + return; + + for (i=0; i=1 && snd_ctrl.loop) { for(i=0;i=2) { int longest=0, longest_nr=0; - /* den bereits am längsten gespielten (gleichen) Sound suchen */ + /* look for oldest equal sound */ for(i=0;i longword */ { unsigned char *ptr = (unsigned char *)be; @@ -621,19 +688,23 @@ static unsigned long le2long(unsigned long *be) /* little-endian -> longword */ return(ptr[3]<<24 | ptr[2]<<16 | ptr[1]<<8 | ptr[0]); } +#endif /* !MSDOS */ boolean LoadSound(struct SoundInfo *snd_info) { - FILE *file; char filename[256]; char *sound_ext = "wav"; +#ifndef MSDOS struct SoundHeader_WAV *sound_header; + FILE *file; int i; +#endif sprintf(filename, "%s/%s/%s.%s", options.base_directory, SOUNDS_DIRECTORY, snd_info->name, sound_ext); #ifndef MSDOS + if ((file = fopen(filename, "r")) == NULL) { Error(ERR_WARN, "cannot open sound file '%s' - no sounds", filename); @@ -681,15 +752,15 @@ boolean LoadSound(struct SoundInfo *snd_info) for (i=0; idata_len; i++) snd_info->data_ptr[i] = snd_info->data_ptr[i]^0x80; -#else +#else /* MSDOS */ snd_info->sample_ptr = load_sample(filename); if (!snd_info->sample_ptr) { Error(ERR_WARN, "cannot read sound file '%s' - no sounds", filename); - fclose(file); return(FALSE); } + #endif /* MSDOS */ return(TRUE); @@ -697,15 +768,15 @@ boolean LoadSound(struct SoundInfo *snd_info) boolean LoadSound_8SVX(struct SoundInfo *snd_info) { - FILE *file; char filename[256]; #ifndef MSDOS + struct SoundHeader_8SVX *sound_header; + FILE *file; + char *ptr; char *sound_ext = "8svx"; #else char *sound_ext = "wav"; #endif - struct SoundHeader_8SVX *sound_header; - unsigned char *ptr; sprintf(filename, "%s/%s/%s.%s", options.base_directory, SOUNDS_DIRECTORY, snd_info->name, sound_ext); @@ -754,9 +825,9 @@ boolean LoadSound_8SVX(struct SoundInfo *snd_info) return(FALSE); } - ptr = snd_info->file_ptr + 12; + ptr = (char *)snd_info->file_ptr + 12; - while(ptr < (unsigned char *)(snd_info->file_ptr + snd_info->file_len)) + while(ptr < (char *)(snd_info->file_ptr + snd_info->file_len)) { if (!strncmp(ptr,"VHDR",4)) { @@ -775,7 +846,7 @@ boolean LoadSound_8SVX(struct SoundInfo *snd_info) } else if (!strncmp(ptr,"BODY",4)) { - snd_info->data_ptr = ptr + 8; + snd_info->data_ptr = (byte *)ptr + 8; snd_info->data_len = be2long((unsigned long *)(ptr + 4)); return(TRUE); } @@ -788,16 +859,15 @@ boolean LoadSound_8SVX(struct SoundInfo *snd_info) } return(FALSE); -#else +#else /* MSDOS */ snd_info->sample_ptr = load_sample(filename); if(!snd_info->sample_ptr) { Error(ERR_WARN, "cannot read sound file '%s' - no sounds", filename); - fclose(file); return(FALSE); } return(TRUE); -#endif // von #ifndef MSDOS +#endif /* MSDOS */ } void PlaySound(int nr)