From 8c373c85183bd059717b0a53ffb97dd472bd6741 Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Sat, 27 Apr 2002 04:38:27 +0200 Subject: [PATCH] rnd-20020427-3-src --- src/libgame/sound.c | 94 +++++++++++++++++++++++++-------------------- src/libgame/sound.h | 9 ++--- 2 files changed, 56 insertions(+), 47 deletions(-) diff --git a/src/libgame/sound.c b/src/libgame/sound.c index 144dd1ad..1a31557a 100644 --- a/src/libgame/sound.c +++ b/src/libgame/sound.c @@ -41,9 +41,8 @@ static struct SoundControl emptySoundControl = #if defined(PLATFORM_UNIX) static int stereo_volume[PSND_MAX_LEFT2RIGHT+1]; -static char premix_first_buffer[SND_BLOCKSIZE]; +static short premix_first_buffer[SND_BLOCKSIZE]; #if defined(AUDIO_STREAMING_DSP) -static short premix_second_buffer[SND_BLOCKSIZE]; static short premix_left_buffer[SND_BLOCKSIZE]; static short premix_right_buffer[SND_BLOCKSIZE]; static long premix_last_buffer[SND_BLOCKSIZE]; @@ -54,17 +53,12 @@ static short playing_buffer[SND_BLOCKSIZE]; /* forward declaration of internal functions */ #if defined(AUDIO_STREAMING_DSP) static void SoundServer_InsertNewSound(struct SoundControl); +static boolean InitAudioDevice_DSP(int, int); +#elif defined(PLATFORM_HPUX) +static boolean InitAudioDevice_HPUX(); #elif defined(PLATFORM_UNIX) static unsigned char linear_to_ulaw(int); static int ulaw_to_linear(unsigned char); -#endif - -#if defined(AUDIO_LINUX_IOCTL) -static boolean InitAudioDevice_Linux(); -#elif defined(PLATFORM_NETBSD) -static boolean InitAudioDevice_NetBSD(); -#elif defined(PLATFORM_HPUX) -static boolean InitAudioDevice_HPUX(); #elif defined(PLATFORM_MSDOS) static void SoundServer_InsertNewSound(struct SoundControl); static void SoundServer_StopSound(struct SoundControl); @@ -343,26 +337,16 @@ void SoundServer(void) if (playing_sounds || snd_ctrl.active) { - struct timeval delay = { 0, 0 }; - byte *sample_ptr; - long sample_size; - static int max_sample_size = 0; - static int fragment_size = DEFAULT_AUDIO_FRAGMENT_SIZE; - int sample_rate = DEFAULT_AUDIO_SAMPLE_RATE; - static boolean stereo = TRUE; - if (playing_sounds || (audio.device_fd = OpenAudioDevice(audio.device_name)) >= 0) { + struct timeval delay = { 0, 0 }; + static int fragment_size = DEFAULT_AUDIO_FRAGMENT_SIZE; + int sample_rate = DEFAULT_AUDIO_SAMPLE_RATE; + static boolean stereo = TRUE; + if (!playing_sounds) /* we just opened the audio device */ - { -#if defined(AUDIO_LINUX_IOCTL) - stereo = InitAudioDevice_Linux(fragment_size, sample_rate); -#elif defined(PLATFORM_NETBSD) - stereo = InitAudioDevice_NetBSD(fragment_size, sample_rate); -#endif - max_sample_size = fragment_size / ((stereo ? 2 : 1) * sizeof(short)); - } + stereo = InitAudioDevice_DSP(fragment_size, sample_rate); if (snd_ctrl.active) /* new sound has arrived */ SoundServer_InsertNewSound(snd_ctrl); @@ -371,10 +355,17 @@ void SoundServer(void) select(audio.soundserver_pipe[0] + 1, &sound_fdset, NULL, NULL, &delay) < 1) { + short *sample_ptr; + int sample_size; + int max_sample_size; + FD_SET(audio.soundserver_pipe[0], &sound_fdset); + max_sample_size = fragment_size / ((stereo ? 2 : 1) * sizeof(short)); + /* first clear the last premixing buffer */ - memset(premix_last_buffer, 0, fragment_size * sizeof(short)); + memset(premix_last_buffer, 0, + max_sample_size * (stereo ? 2 : 1) * sizeof(long)); for(i=0; i= SOUND_FADING_VOLUME_THRESHOLD) @@ -413,8 +402,8 @@ void SoundServer(void) /* adjust volume of actual sound sample */ if (playlist[i].volume != PSND_MAX_VOLUME) for(j=0; j> PSND_MAX_VOLUME_BITS; /* fill the last mixing buffer with stereo or mono sound */ @@ -427,10 +416,10 @@ void SoundServer(void) for(j=0; j> PSND_MAX_LEFT2RIGHT_BITS; premix_right_buffer[j] = - (right_volume * premix_second_buffer[j]) + (right_volume * premix_first_buffer[j]) >> PSND_MAX_LEFT2RIGHT_BITS; premix_last_buffer[2 * j + 0] += premix_left_buffer[j]; @@ -440,7 +429,7 @@ void SoundServer(void) else { for(j=0; jdata_len * sizeof(short)); + for (i=0; idata_len; i++) - ((byte *)snd_info->data_ptr)[i] ^= 0x80; + data_ptr[i] = ((short)(((byte *)snd_info->data_ptr)[i] ^ 0x80)) << 8; + + free(snd_info->data_ptr); + snd_info->data_ptr = data_ptr; #endif /* PLATFORM_UNIX */ diff --git a/src/libgame/sound.h b/src/libgame/sound.h index cb606b0b..63cab336 100644 --- a/src/libgame/sound.h +++ b/src/libgame/sound.h @@ -181,12 +181,11 @@ struct SoundHeader_8SVX struct SampleInfo { - char *source_filename; - int type; + char *source_filename; - void *data_ptr; long data_len; + void *data_ptr; }; typedef struct SampleInfo SoundInfo; @@ -210,8 +209,8 @@ struct SoundControl int playingtime; long playingpos; - unsigned long data_len; - byte *data_ptr; + long data_len; + void *data_ptr; #if defined(PLATFORM_MSDOS) int voice; -- 2.34.1