From: Holger Schemel Date: Sun, 12 May 2002 22:35:42 +0000 (+0200) Subject: rnd-20020513-1-src X-Git-Tag: 2.1.0^2~21 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=2f1f47c267eb7b16d95eb25cfb53eb5effedea9a;p=rocksndiamonds.git rnd-20020513-1-src --- diff --git a/src/game.c b/src/game.c index d096ac20..417d00f9 100644 --- a/src/game.c +++ b/src/game.c @@ -6425,31 +6425,32 @@ boolean PlaceBomb(struct PlayerInfo *player) return TRUE; } -void PlaySoundLevel(int x, int y, int sound_nr) +void PlaySoundLevel(int x, int y, int nr) { int sx = SCREENX(x), sy = SCREENY(y); - int volume, stereo; + int volume, stereo_position; int silence_distance = 8; + int type = (IS_LOOP_SOUND(nr) ? SND_CTRL_PLAY_LOOP : SND_CTRL_PLAY_SOUND); - if ((!setup.sound_simple && !IS_LOOP_SOUND(sound_nr)) || - (!setup.sound_loops && IS_LOOP_SOUND(sound_nr))) + if ((!setup.sound_simple && !IS_LOOP_SOUND(nr)) || + (!setup.sound_loops && IS_LOOP_SOUND(nr))) return; if (!IN_LEV_FIELD(x, y) || - sx < -silence_distance || sx >= SCR_FIELDX+silence_distance || - sy < -silence_distance || sy >= SCR_FIELDY+silence_distance) + sx < -silence_distance || sx >= SCR_FIELDX + silence_distance || + sy < -silence_distance || sy >= SCR_FIELDY + silence_distance) return; volume = PSND_MAX_VOLUME; #if !defined(PLATFORM_MSDOS) - stereo = (sx - SCR_FIELDX/2) * 12; + stereo_position = (sx - SCR_FIELDX / 2) * 12; #else - stereo = PSND_MIDDLE + (2 * sx - (SCR_FIELDX - 1)) * 5; - if (stereo > PSND_MAX_RIGHT) - stereo = PSND_MAX_RIGHT; - if (stereo < PSND_MAX_LEFT) - stereo = PSND_MAX_LEFT; + stereo_position = PSND_MIDDLE + (2 * sx - (SCR_FIELDX - 1)) * 5; + if (stereo_position > PSND_MAX_RIGHT) + stereo_position = PSND_MAX_RIGHT; + if (stereo_position < PSND_MAX_LEFT) + stereo_position = PSND_MAX_LEFT; #endif if (!IN_SCR_FIELD(sx, sy)) @@ -6460,7 +6461,7 @@ void PlaySoundLevel(int x, int y, int sound_nr) volume -= volume * (dx > dy ? dx : dy) / silence_distance; } - PlaySoundExt(sound_nr, volume, stereo, SND_CTRL_PLAY_SOUND); + PlaySoundExt(nr, volume, stereo_position, type); } void RaiseScore(int value) diff --git a/src/libgame/sdl.c b/src/libgame/sdl.c index 6365c871..42e6286b 100644 --- a/src/libgame/sdl.c +++ b/src/libgame/sdl.c @@ -890,15 +890,6 @@ inline void SDLOpenAudio(void) audio.music_channel = MUSIC_CHANNEL; audio.first_sound_channel = FIRST_SOUND_CHANNEL; - /* reserve first channel for music loops */ - if (Mix_ReserveChannels(1) == 1) - audio.music_channel = 0; - else - audio.music_available = FALSE; - - Mix_Volume(-1, SOUND_MAX_VOLUME); - Mix_VolumeMusic(SOUND_MAX_VOLUME); - Mixer_InitChannels(); } diff --git a/src/libgame/sound.c b/src/libgame/sound.c index cb7dc63d..048829f5 100644 --- a/src/libgame/sound.c +++ b/src/libgame/sound.c @@ -17,6 +17,21 @@ #include #include #include +#include + +#include "platform.h" + +#if defined(PLATFORM_LINUX) +#include +#include +#elif defined(PLATFORM_FREEBSD) +#include +#elif defined(PLATFORM_NETBSD) +#include +#include +#elif defined(PLATFORM_HPUX) +#include +#endif #include "system.h" #include "sound.h" @@ -24,8 +39,101 @@ #include "setup.h" -#define IS_PARENT_PROCESS(pid) ((pid) > 0) -#define IS_CHILD_PROCESS(pid) ((pid) == 0) +/* expiration time (in milliseconds) for sound loops */ +#define SOUND_LOOP_EXPIRATION_TIME 200 + +#if defined(TARGET_SDL) +/* one second fading interval == 1000 ticks (milliseconds) */ +#define SOUND_FADING_INTERVAL 1000 +#define SOUND_MAX_VOLUME SDL_MIX_MAXVOLUME +#endif + +#if defined(AUDIO_STREAMING_DSP) +#define SOUND_FADING_VOLUME_STEP (PSND_MAX_VOLUME / 40) +#define SOUND_FADING_VOLUME_THRESHOLD (SOUND_FADING_VOLUME_STEP * 2) +#endif + +#if !defined(PLATFORM_HPUX) +#define SND_BLOCKSIZE 4096 +#else +#define SND_BLOCKSIZE 32768 +#endif + +#define SND_TYPE_NONE 0 +#define SND_TYPE_WAV 1 + +#define MUS_TYPE_NONE 0 +#define MUS_TYPE_WAV 1 +#define MUS_TYPE_MOD 2 + +#define DEVICENAME_DSP "/dev/dsp" +#define DEVICENAME_AUDIO "/dev/audio" +#define DEVICENAME_AUDIOCTL "/dev/audioCtl" + + +#if 0 +struct SoundHeader_SUN +{ + unsigned long magic; + unsigned long hdr_size; + unsigned long data_size; + unsigned long encoding; + unsigned long sample_rate; + unsigned long channels; +}; + +struct SoundHeader_8SVX +{ + char magic_FORM[4]; + unsigned long chunk_size; + char magic_8SVX[4]; +}; +#endif + +struct AudioFormatInfo +{ + boolean stereo; /* availability of stereo sound */ + int format; /* size and endianess of sample data */ + int sample_rate; /* sample frequency */ + int fragment_size; /* audio device fragment size in bytes */ +}; + +struct SampleInfo +{ + char *source_filename; + int num_references; + + int type; + int format; + long data_len; + void *data_ptr; +}; +typedef struct SampleInfo SoundInfo; +typedef struct SampleInfo MusicInfo; + +struct SoundControl +{ + boolean active; + + int nr; + int volume; + int stereo_position; + + int state; + + unsigned long playing_starttime; + unsigned long playing_pos; + + int type; + int format; + long data_len; + void *data_ptr; + +#if defined(PLATFORM_MSDOS) + int voice; +#endif +}; +typedef struct SoundControl SoundControl; struct ListNode { @@ -483,6 +591,45 @@ void Mixer_InitChannels() mixer_active_channels = 0; } +static void Mixer_ResetChannelExpiration(int channel) +{ + mixer[channel].playing_starttime = Counter(); + +#if defined(TARGET_SDL) + if (IS_LOOP(mixer[channel]) && !IS_MUSIC(mixer[channel])) + Mix_ExpireChannel(channel, SOUND_LOOP_EXPIRATION_TIME); +#endif +} + +static boolean Mixer_ChannelExpired(int channel) +{ + if (!mixer[channel].active) + return TRUE; + + if (IS_LOOP(mixer[channel]) && !IS_MUSIC(mixer[channel]) && + DelayReached(&mixer[channel].playing_starttime, + SOUND_LOOP_EXPIRATION_TIME)) + return TRUE; + +#if defined(TARGET_SDL) + + if (!Mix_Playing(channel)) + return TRUE; + +#elif defined(TARGET_ALLEGRO) + + mixer[channel].playing_pos = voice_get_position(mixer[channel].voice); + mixer[channel].volume = voice_get_volume(mixer[channel].voice); + + /* sound sample has completed playing or was completely faded out */ + if (mixer[channel].playing_pos == -1 || mixer[channel].volume == 0) + return TRUE; + +#endif /* TARGET_ALLEGRO */ + + return FALSE; +} + static void Mixer_PlayChannel(int channel) { /* start with inactive channel in case something goes wrong */ @@ -491,9 +638,6 @@ static void Mixer_PlayChannel(int channel) if (mixer[channel].type != MUS_TYPE_WAV) return; - mixer[channel].playing_pos = 0; - mixer[channel].playing_starttime = Counter(); - #if defined(TARGET_SDL) Mix_Volume(channel, SOUND_MAX_VOLUME); Mix_PlayChannel(channel, mixer[channel].data_ptr, @@ -511,6 +655,9 @@ static void Mixer_PlayChannel(int channel) voice_start(mixer[channel].voice); #endif + Mixer_ResetChannelExpiration(channel); + + mixer[channel].playing_pos = 0; mixer[channel].active = TRUE; mixer_active_channels++; } @@ -532,12 +679,6 @@ static void Mixer_PlayMusicChannel() static void Mixer_StopChannel(int channel) { -#if 0 -#if defined(TARGET_SDL) - printf("----------> %d [%d]\n", Mix_Playing(channel), Mix_Playing(0)); -#endif -#endif - if (!mixer[channel].active) return; @@ -642,15 +783,31 @@ static void Mixer_InsertSound(SoundControl snd_ctrl) /* check if sound is already being played (and how often) */ for (k=0, i=audio.first_sound_channel; i= 1 && IS_LOOP(snd_ctrl)) +#if 0 + printf("SOUND %d [CURRENTLY PLAYING %d TIMES]\n", snd_ctrl.nr, k); +#endif + + /* reset expiration delay for already playing loop sounds */ + if (k > 0 && IS_LOOP(snd_ctrl)) { for(i=audio.first_sound_channel; i= longest) { @@ -700,12 +853,8 @@ static void Mixer_InsertSound(SoundControl snd_ctrl) for (i=audio.first_sound_channel; i longest) { @@ -717,7 +866,7 @@ static void Mixer_InsertSound(SoundControl snd_ctrl) Mixer_StopChannel(longest_nr); } - /* add new sound to mixer */ + /* add the new sound to the mixer */ for(i=0; i - #include "platform.h" -#if defined(PLATFORM_LINUX) -#include -#endif - -#if defined(PLATFORM_LINUX) -#include -#elif defined(PLATFORM_FREEBSD) -#include -#elif defined(PLATFORM_NETBSD) -#include -#include -#elif defined(PLATFORM_HPUX) -#include -#endif - -#include "system.h" - #if defined(PLATFORM_UNIX) && !defined(TARGET_SDL) #define AUDIO_UNIX_NATIVE @@ -48,50 +29,34 @@ #define AUDIO_STREAMING_DSP #endif -#define AUDIO_SAMPLE_RATE_8000 8000 -#define AUDIO_SAMPLE_RATE_22050 22050 - -#define AUDIO_FRAGMENT_SIZE_512 512 -#define AUDIO_FRAGMENT_SIZE_1024 1024 -#define AUDIO_FRAGMENT_SIZE_2048 2048 -#define AUDIO_FRAGMENT_SIZE_4096 4096 +/* values for platform specific sound initialization */ +#define AUDIO_SAMPLE_RATE_8000 8000 +#define AUDIO_SAMPLE_RATE_22050 22050 -#define AUDIO_NUM_CHANNELS_MONO 1 -#define AUDIO_NUM_CHANNELS_STEREO 2 +#define AUDIO_FRAGMENT_SIZE_512 512 +#define AUDIO_FRAGMENT_SIZE_1024 1024 +#define AUDIO_FRAGMENT_SIZE_2048 2048 +#define AUDIO_FRAGMENT_SIZE_4096 4096 -#define AUDIO_FORMAT_UNKNOWN (0) -#define AUDIO_FORMAT_U8 (1 << 0) -#define AUDIO_FORMAT_S16 (1 << 1) -#define AUDIO_FORMAT_LE (1 << 2) -#define AUDIO_FORMAT_BE (1 << 3) +#define AUDIO_NUM_CHANNELS_MONO 1 +#define AUDIO_NUM_CHANNELS_STEREO 2 -/* expiration time (in milliseconds) for sound loops */ -#define SOUND_LOOP_EXPIRATION_TIME 200 +#define AUDIO_FORMAT_UNKNOWN (0) +#define AUDIO_FORMAT_U8 (1 << 0) +#define AUDIO_FORMAT_S16 (1 << 1) +#define AUDIO_FORMAT_LE (1 << 2) +#define AUDIO_FORMAT_BE (1 << 3) -#if defined(TARGET_SDL) -/* one second fading interval == 1000 ticks (milliseconds) */ -#define SOUND_FADING_INTERVAL 1000 -#define SOUND_MAX_VOLUME SDL_MIX_MAXVOLUME -#endif - -#if defined(AUDIO_STREAMING_DSP) -#define SOUND_FADING_VOLUME_STEP (PSND_MAX_VOLUME / 40) -#define SOUND_FADING_VOLUME_THRESHOLD (SOUND_FADING_VOLUME_STEP * 2) -#endif - -#if defined(AUDIO_STREAMING_DSP) -#define DEFAULT_AUDIO_SAMPLE_RATE AUDIO_SAMPLE_RATE_22050 +#if defined(AUDIO_UNIX_NATIVE) && !defined(AUDIO_STREAMING_DSP) +#define DEFAULT_AUDIO_SAMPLE_RATE AUDIO_SAMPLE_RATE_8000 #else -#define DEFAULT_AUDIO_SAMPLE_RATE AUDIO_SAMPLE_RATE_8000 +#define DEFAULT_AUDIO_SAMPLE_RATE AUDIO_SAMPLE_RATE_22050 #endif -#define DEFAULT_AUDIO_FRAGMENT_SIZE_UNIX AUDIO_FRAGMENT_SIZE_512 -#define DEFAULT_AUDIO_FRAGMENT_SIZE_WIN32 AUDIO_FRAGMENT_SIZE_2048 - -#if defined(PLATFORM_UNIX) -#define DEFAULT_AUDIO_FRAGMENT_SIZE DEFAULT_AUDIO_FRAGMENT_SIZE_UNIX +#if defined(PLATFORM_WIN32) +#define DEFAULT_AUDIO_FRAGMENT_SIZE AUDIO_FRAGMENT_SIZE_2048 #else -#define DEFAULT_AUDIO_FRAGMENT_SIZE DEFAULT_AUDIO_FRAGMENT_SIZE_WIN32 +#define DEFAULT_AUDIO_FRAGMENT_SIZE AUDIO_FRAGMENT_SIZE_512 #endif #if defined(TARGET_SDL) @@ -103,138 +68,8 @@ #define MUSIC_CHANNEL 0 #define FIRST_SOUND_CHANNEL 1 -#if !defined(PLATFORM_HPUX) -#define SND_BLOCKSIZE 4096 -#else -#define SND_BLOCKSIZE 32768 -#endif - -/* some values for PlaySound(), StopSound() and friends */ -#if !defined(PLATFORM_MSDOS) - -#define PSND_SILENCE 0 -#define PSND_MAX_VOLUME_BITS 15 -#define PSND_MIN_VOLUME 0 -#define PSND_MAX_VOLUME (1 << PSND_MAX_VOLUME_BITS) -#define PSND_MIDDLE 0 -#define PSND_MAX_STEREO_BITS 7 -#define PSND_MAX_STEREO (1 << PSND_MAX_STEREO_BITS) -#define PSND_MAX_LEFT (-PSND_MAX_STEREO) -#define PSND_MAX_RIGHT (+PSND_MAX_STEREO) -#define PSND_MAX_LEFT2RIGHT_BITS (PSND_MAX_STEREO_BITS+1) -#define PSND_MAX_LEFT2RIGHT (1 << PSND_MAX_LEFT2RIGHT_BITS) - -#else /* PLATFORM_MSDOS */ - -#define PSND_SILENCE 0 -#define PSND_MIN_VOLUME 0 -#define PSND_MAX_VOLUME 255 -#define PSND_MAX_LEFT 0 -#define PSND_MAX_RIGHT 255 -#define PSND_MIDDLE 128 - -#endif - -#if 0 -#define PSND_NO_LOOP 0 -#define PSND_LOOP 1 -#define PSND_MUSIC 2 - -#define SSND_FADE_SOUND (1 << 0) -#define SSND_FADE_MUSIC (1 << 1) -#define SSND_FADE_ALL (1 << 2) -#define SSND_FADING (SSND_FADE_SOUND | \ - SSND_FADE_MUSIC | \ - SSND_FADE_ALL) -#define SSND_STOP_SOUND (1 << 3) -#define SSND_STOP_MUSIC (1 << 4) -#define SSND_STOP_ALL (1 << 5) -#define SSND_STOPPING (SSND_STOP_SOUND | \ - SSND_STOP_MUSIC | \ - SSND_STOP_ALL) -#define SSND_MUSIC (SSND_FADE_MUSIC | SSND_STOP_MUSIC) -#define SSND_ALL (SSND_FADE_ALL | SSND_STOP_ALL) - -#define SND_RELOAD_SOUNDS 1 -#define SND_RELOAD_MUSIC 2 -#endif - -#define SND_TYPE_NONE 0 -#define SND_TYPE_WAV 1 - -#define MUS_TYPE_NONE 0 -#define MUS_TYPE_WAV 1 -#define MUS_TYPE_MOD 2 - -/* settings for sound path, sound device, etc. */ -#ifndef SND_PATH -#define SND_PATH "./sounds" -#endif - -#define DEVICENAME_DSP "/dev/dsp" -#define DEVICENAME_AUDIO "/dev/audio" -#define DEVICENAME_AUDIOCTL "/dev/audioCtl" - -#if 0 -#if defined(AUDIO_STREAMING_DSP) -#define AUDIO_DEVICE DEVICENAME_DSP -#else -#define AUDIO_DEVICE DEVICENAME_AUDIO -#endif -#endif - -/* value for undefined sound effect filename */ -#define SND_FILE_UNDEFINED "NONE" - - -#if 0 -struct SoundHeader_SUN -{ - unsigned long magic; - unsigned long hdr_size; - unsigned long data_size; - unsigned long encoding; - unsigned long sample_rate; - unsigned long channels; -}; - -struct SoundHeader_8SVX -{ - char magic_FORM[4]; - unsigned long chunk_size; - char magic_8SVX[4]; -}; -#endif - -struct AudioFormatInfo -{ - boolean stereo; /* availability of stereo sound */ - int format; /* size and endianess of sample data */ - int sample_rate; /* sample frequency */ - int fragment_size; /* audio device fragment size in bytes */ -}; - -struct SoundEffectInfo -{ - char *text; - char *default_filename; - char *filename; -}; - -struct SampleInfo -{ - char *source_filename; - int num_references; - - int type; - int format; - long data_len; - void *data_ptr; -}; - -typedef struct SampleInfo SoundInfo; -typedef struct SampleInfo MusicInfo; +/* values for PlaySound(), StopSound() and friends */ #define SND_CTRL_NONE (0) #define SND_CTRL_MUSIC (1 << 0) #define SND_CTRL_LOOP (1 << 1) @@ -264,30 +99,43 @@ typedef struct SampleInfo MusicInfo; SND_CTRL_RELOAD_MUSIC)) #define ALL_SOUNDS(x) ((x).state & SND_CTRL_ALL_SOUNDS) -struct SoundControl -{ - boolean active; - int nr; - int volume; - int stereo_position; +#if !defined(TARGET_ALLEGRO) - int state; +#define PSND_SILENCE 0 +#define PSND_MAX_VOLUME_BITS 15 +#define PSND_MIN_VOLUME 0 +#define PSND_MAX_VOLUME (1 << PSND_MAX_VOLUME_BITS) +#define PSND_MIDDLE 0 +#define PSND_MAX_STEREO_BITS 7 +#define PSND_MAX_STEREO (1 << PSND_MAX_STEREO_BITS) +#define PSND_MAX_LEFT (-PSND_MAX_STEREO) +#define PSND_MAX_RIGHT (+PSND_MAX_STEREO) +#define PSND_MAX_LEFT2RIGHT_BITS (PSND_MAX_STEREO_BITS+1) +#define PSND_MAX_LEFT2RIGHT (1 << PSND_MAX_LEFT2RIGHT_BITS) - unsigned long playing_starttime; - unsigned long playing_pos; +#else /* TARGET_ALLEGRO */ - int type; - int format; - long data_len; - void *data_ptr; +#define PSND_SILENCE 0 +#define PSND_MIN_VOLUME 0 +#define PSND_MAX_VOLUME 255 +#define PSND_MAX_LEFT 0 +#define PSND_MAX_RIGHT 255 +#define PSND_MIDDLE 128 -#if defined(PLATFORM_MSDOS) - int voice; #endif + +/* value for undefined sound effect filename */ +#define SND_FILE_UNDEFINED "NONE" + + +struct SoundEffectInfo +{ + char *text; + char *default_filename; + char *filename; }; -typedef struct SoundControl SoundControl; /* general sound functions */ void UnixOpenAudio(void); diff --git a/src/libgame/system.h b/src/libgame/system.h index d6223182..0a54fe23 100644 --- a/src/libgame/system.h +++ b/src/libgame/system.h @@ -172,6 +172,10 @@ #define VERSION_MINOR(x) (((x) % 10000) / 100) #define VERSION_PATCH(x) ((x) % 100) +/* functions for parent/child process identification */ +#define IS_PARENT_PROCESS(pid) ((pid) > 0) +#define IS_CHILD_PROCESS(pid) ((pid) == 0) + /* type definitions */ typedef int (*EventFilter)(const Event *); diff --git a/src/timestamp.h b/src/timestamp.h index 6505e6f1..757a3a8f 100644 --- a/src/timestamp.h +++ b/src/timestamp.h @@ -1 +1 @@ -#define COMPILE_DATE_STRING "[2002-05-10 16:21]" +#define COMPILE_DATE_STRING "[2002-05-12 22:43]"