From 9ec0d380a76588e183c0c002c22cb066cc7c58c3 Mon Sep 17 00:00:00 2001 From: Fabian Greffrath Date: Wed, 1 May 2024 21:13:08 +0200 Subject: [PATCH 1/2] update all sounds relative to the player Fixes #52 --- rott/fx_man.h | 3 +++ rott/fx_mixer.c | 35 ++++++++++++++++++++++++++++++++++- rott/rt_playr.c | 1 + rott/rt_sound.c | 9 +++++++++ rott/rt_sound.h | 1 + 5 files changed, 48 insertions(+), 1 deletion(-) diff --git a/rott/fx_man.h b/rott/fx_man.h index 8b2a6ed..e74b55a 100644 --- a/rott/fx_man.h +++ b/rott/fx_man.h @@ -80,6 +80,9 @@ int FX_SoundActive( int handle ); int FX_StopSound( int handle ); int FX_StopAllSounds( void ); +int FX_SetXY(int handle, int x, int y); +int FX_AllSoundsRTP(void); + #if 0 int FX_StartDemandFeedPlayback( void ( *function )( char **ptr, unsigned long *length ), int rate, int pitchoffset, int vol, int left, int right, diff --git a/rott/fx_mixer.c b/rott/fx_mixer.c index 173ef42..1482ace 100644 --- a/rott/fx_mixer.c +++ b/rott/fx_mixer.c @@ -44,6 +44,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. static struct { sound_t *sfx; + int x, y; } channels[MAX_CHANNELS]; static int FX_Installed = 0; @@ -209,7 +210,7 @@ int FX_StopSound(int handle) channels[handle].sfx->count--; } - channels[handle].sfx = NULL; + memset(&channels[handle], 0, sizeof(channels[handle])); } return FX_Ok; @@ -407,6 +408,16 @@ int FX_Play(int handle, int sndnum, int pitchoffset, int angle, int distance, return -1; } +int FX_SetXY(int handle, int x, int y) +{ + CHECK_HANDLE(handle); + + channels[handle].x = x; + channels[handle].y = y; + + return FX_Ok; +} + int FX_SetPitch(int handle, int pitchoffset) { return FX_Ok; @@ -433,3 +444,25 @@ int FX_StopAllSounds(void) return FX_Ok; } + +int FX_AllSoundsRTP(void) +{ + int i; + + for (i = 0; i < MAX_CHANNELS; i++) + { + if (FX_SoundActive(i)) + { + if (channels[i].x || channels[i].y) + { + SD_PanRTP(i, channels[i].x, channels[i].y); + } + } + else + { + FX_StopSound(i); + } + } + + return FX_Ok; +} diff --git a/rott/rt_playr.c b/rott/rt_playr.c index 669dfe7..2cf4d38 100644 --- a/rott/rt_playr.c +++ b/rott/rt_playr.c @@ -5938,6 +5938,7 @@ void T_Player (objtype *ob) } #endif + SD_AllSoundsRTP(); } diff --git a/rott/rt_sound.c b/rott/rt_sound.c index f93672d..a0f2514 100644 --- a/rott/rt_sound.c +++ b/rott/rt_sound.c @@ -413,6 +413,8 @@ int SD_PlaySoundRTP ( int sndnum, int x, int y ) voice = SD_PlayIt ( sndnum, angle, distance, pitch ); + FX_SetXY(voice, x, y); + return voice; } @@ -499,12 +501,19 @@ void SD_PanRTP ( int handle, int x, int y ) status = FX_Pan3D ( handle, angle, distance ); + FX_SetXY(handle, x, y); + if (status != FX_Ok) { //TODO: This code does nothing. } } +void SD_AllSoundsRTP(void) +{ + FX_AllSoundsRTP(); +} + //*************************************************************************** // // SD_SetPan - set the pan of a sample diff --git a/rott/rt_sound.h b/rott/rt_sound.h index d8a3b74..a1ecbf2 100644 --- a/rott/rt_sound.h +++ b/rott/rt_sound.h @@ -508,6 +508,7 @@ int SD_Play3D ( int sndnum, int angle, int distance ); int SD_PlayPitchedSound ( int sndnum, int volume, int pitch ); void SD_SetSoundPitch ( int sndnum, int pitch ); boolean SD_SoundOkay ( int sndnum ); +void SD_AllSoundsRTP(void); //*************************************************************************** // From 701aed0e9204cdb8b2532267d81f9af8d1530238 Mon Sep 17 00:00:00 2001 From: Fabian Greffrath Date: Thu, 2 May 2024 22:42:30 +0200 Subject: [PATCH 2/2] comment --- rott/fx_mixer.c | 2 +- rott/rt_playr.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/rott/fx_mixer.c b/rott/fx_mixer.c index 1482ace..473ecc3 100644 --- a/rott/fx_mixer.c +++ b/rott/fx_mixer.c @@ -453,7 +453,7 @@ int FX_AllSoundsRTP(void) { if (FX_SoundActive(i)) { - if (channels[i].x || channels[i].y) + if (channels[i].x | channels[i].y) { SD_PanRTP(i, channels[i].x, channels[i].y); } diff --git a/rott/rt_playr.c b/rott/rt_playr.c index 2cf4d38..51bfa10 100644 --- a/rott/rt_playr.c +++ b/rott/rt_playr.c @@ -5938,6 +5938,7 @@ void T_Player (objtype *ob) } #endif + // [FG] update all sound pannings relative to the player SD_AllSoundsRTP(); }