mirror of
https://github.com/KartKrewDev/RingRacers.git
synced 2025-12-05 07:33:00 +00:00
Hey it's audio- ....resynching...
This commit is contained in:
parent
36f9bb4381
commit
530cac8673
4 changed files with 53 additions and 0 deletions
|
|
@ -158,6 +158,8 @@ UINT32 I_GetSongLoopPoint(void);
|
||||||
boolean I_SetSongPosition(UINT32 position);
|
boolean I_SetSongPosition(UINT32 position);
|
||||||
UINT32 I_GetSongPosition(void);
|
UINT32 I_GetSongPosition(void);
|
||||||
|
|
||||||
|
void I_UpdateSongLagThreshold (void);
|
||||||
|
|
||||||
/// ------------------------
|
/// ------------------------
|
||||||
// MUSIC PLAYBACK
|
// MUSIC PLAYBACK
|
||||||
/// ------------------------
|
/// ------------------------
|
||||||
|
|
|
||||||
|
|
@ -120,6 +120,8 @@ consvar_t cv_gamesounds = {"sounds", "On", CV_SAVE|CV_CALL|CV_NOINIT, CV_OnOff,
|
||||||
consvar_t cv_playmusicifunfocused = {"playmusicifunfocused", "No", CV_SAVE|CV_CALL|CV_NOINIT, CV_YesNo, PlayMusicIfUnfocused_OnChange, 0, NULL, NULL, 0, 0, NULL};
|
consvar_t cv_playmusicifunfocused = {"playmusicifunfocused", "No", CV_SAVE|CV_CALL|CV_NOINIT, CV_YesNo, PlayMusicIfUnfocused_OnChange, 0, NULL, NULL, 0, 0, NULL};
|
||||||
consvar_t cv_playsoundifunfocused = {"playsoundsifunfocused", "No", CV_SAVE|CV_CALL|CV_NOINIT, CV_YesNo, PlaySoundIfUnfocused_OnChange, 0, NULL, NULL, 0, 0, NULL};
|
consvar_t cv_playsoundifunfocused = {"playsoundsifunfocused", "No", CV_SAVE|CV_CALL|CV_NOINIT, CV_YesNo, PlaySoundIfUnfocused_OnChange, 0, NULL, NULL, 0, 0, NULL};
|
||||||
|
|
||||||
|
consvar_t cv_music_resync_threshold = {"music_resync_threshold", "100", CV_SAVE|CV_CALL, CV_Unsigned, I_UpdateSongLagThreshold};
|
||||||
|
|
||||||
#define S_MAX_VOLUME 127
|
#define S_MAX_VOLUME 127
|
||||||
|
|
||||||
// when to clip out sounds
|
// when to clip out sounds
|
||||||
|
|
@ -283,6 +285,8 @@ void S_RegisterSoundStuff(void)
|
||||||
CV_RegisterVar(&cv_playmusicifunfocused);
|
CV_RegisterVar(&cv_playmusicifunfocused);
|
||||||
CV_RegisterVar(&cv_playsoundifunfocused);
|
CV_RegisterVar(&cv_playsoundifunfocused);
|
||||||
|
|
||||||
|
CV_RegisterVar(&cv_music_resync_threshold);
|
||||||
|
|
||||||
COM_AddCommand("tunes", Command_Tunes_f);
|
COM_AddCommand("tunes", Command_Tunes_f);
|
||||||
COM_AddCommand("restartaudio", Command_RestartAudio_f);
|
COM_AddCommand("restartaudio", Command_RestartAudio_f);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,8 @@ extern consvar_t cv_gamesounds;
|
||||||
extern consvar_t cv_playmusicifunfocused;
|
extern consvar_t cv_playmusicifunfocused;
|
||||||
extern consvar_t cv_playsoundifunfocused;
|
extern consvar_t cv_playsoundifunfocused;
|
||||||
|
|
||||||
|
extern consvar_t cv_music_resync_threshold;
|
||||||
|
|
||||||
#ifdef SNDSERV
|
#ifdef SNDSERV
|
||||||
extern consvar_t sndserver_cmd, sndserver_arg;
|
extern consvar_t sndserver_cmd, sndserver_arg;
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,12 @@
|
||||||
|
|
||||||
#if defined(HAVE_SDL) && defined(HAVE_MIXER) && SOUND==SOUND_MIXER
|
#if defined(HAVE_SDL) && defined(HAVE_MIXER) && SOUND==SOUND_MIXER
|
||||||
|
|
||||||
|
/*
|
||||||
|
Just for hu_stopped. I promise I didn't
|
||||||
|
write netcode into the sound code, OKAY?
|
||||||
|
*/
|
||||||
|
#include "../d_clisrv.h"
|
||||||
|
|
||||||
#include "../sounds.h"
|
#include "../sounds.h"
|
||||||
#include "../s_sound.h"
|
#include "../s_sound.h"
|
||||||
#include "../i_sound.h"
|
#include "../i_sound.h"
|
||||||
|
|
@ -74,12 +80,16 @@
|
||||||
|
|
||||||
UINT8 sound_started = false;
|
UINT8 sound_started = false;
|
||||||
|
|
||||||
|
static UINT32 stutter_threshold;
|
||||||
|
|
||||||
static Mix_Music *music;
|
static Mix_Music *music;
|
||||||
static UINT8 music_volume, sfx_volume, internal_volume;
|
static UINT8 music_volume, sfx_volume, internal_volume;
|
||||||
static float loop_point;
|
static float loop_point;
|
||||||
static float song_length; // length in seconds
|
static float song_length; // length in seconds
|
||||||
static boolean songpaused;
|
static boolean songpaused;
|
||||||
|
static UINT32 music_end_bytes;
|
||||||
static UINT32 music_bytes;
|
static UINT32 music_bytes;
|
||||||
|
static UINT32 music_stutter_bytes;
|
||||||
static boolean is_looping;
|
static boolean is_looping;
|
||||||
|
|
||||||
// fading
|
// fading
|
||||||
|
|
@ -101,6 +111,8 @@ static void var_cleanup(void)
|
||||||
loop_point = song_length =\
|
loop_point = song_length =\
|
||||||
music_bytes = fading_source = fading_target =\
|
music_bytes = fading_source = fading_target =\
|
||||||
fading_timer = fading_duration = 0;
|
fading_timer = fading_duration = 0;
|
||||||
|
music_end_bytes = 0;
|
||||||
|
music_stutter_bytes = 0;
|
||||||
|
|
||||||
songpaused = is_looping =\
|
songpaused = is_looping =\
|
||||||
is_fading = false;
|
is_fading = false;
|
||||||
|
|
@ -554,6 +566,8 @@ static void do_fading_callback(void)
|
||||||
|
|
||||||
static void count_music_bytes(int chan, void *stream, int len, void *udata)
|
static void count_music_bytes(int chan, void *stream, int len, void *udata)
|
||||||
{
|
{
|
||||||
|
UINT32 bytes;
|
||||||
|
|
||||||
(void)chan;
|
(void)chan;
|
||||||
(void)stream;
|
(void)stream;
|
||||||
(void)udata;
|
(void)udata;
|
||||||
|
|
@ -561,12 +575,35 @@ static void count_music_bytes(int chan, void *stream, int len, void *udata)
|
||||||
if (!music || I_SongType() == MU_GME || I_SongType() == MU_MOD || I_SongType() == MU_MID)
|
if (!music || I_SongType() == MU_GME || I_SongType() == MU_MOD || I_SongType() == MU_MID)
|
||||||
return;
|
return;
|
||||||
music_bytes += len;
|
music_bytes += len;
|
||||||
|
if (hu_stopped)
|
||||||
|
{
|
||||||
|
music_stutter_bytes += len;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (music_stutter_bytes >= stutter_threshold)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
This would be after looping. If we're too near to the start of the
|
||||||
|
file, subtracting the delta will just underflow.
|
||||||
|
*/
|
||||||
|
if (music_stutter_bytes > music_bytes)
|
||||||
|
{
|
||||||
|
/* We already know where the end is because we looped. */
|
||||||
|
bytes = ( music_end_bytes - ( music_stutter_bytes - music_bytes ));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
bytes = ( music_bytes - music_stutter_bytes );
|
||||||
|
I_SetSongPosition((int)( bytes/4/44100.0*1000 ));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void music_loop(void)
|
static void music_loop(void)
|
||||||
{
|
{
|
||||||
if (is_looping)
|
if (is_looping)
|
||||||
{
|
{
|
||||||
|
music_end_bytes = music_bytes;
|
||||||
Mix_PlayMusic(music, 0);
|
Mix_PlayMusic(music, 0);
|
||||||
Mix_SetMusicPosition(loop_point);
|
Mix_SetMusicPosition(loop_point);
|
||||||
music_bytes = loop_point*44100.0L*4; //assume 44.1khz, 4-byte length (see I_GetSongPosition)
|
music_bytes = loop_point*44100.0L*4; //assume 44.1khz, 4-byte length (see I_GetSongPosition)
|
||||||
|
|
@ -848,6 +885,8 @@ boolean I_SetSongPosition(UINT32 position)
|
||||||
// NOT if position input is greater than song length.
|
// NOT if position input is greater than song length.
|
||||||
music_bytes = 0;
|
music_bytes = 0;
|
||||||
|
|
||||||
|
music_stutter_bytes = 0;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -892,6 +931,12 @@ UINT32 I_GetSongPosition(void)
|
||||||
// 8M: 1 | 8S: 2 | 16M: 2 | 16S: 4
|
// 8M: 1 | 8S: 2 | 16M: 2 | 16S: 4
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
I_UpdateSongLagThreshold (void)
|
||||||
|
{
|
||||||
|
stutter_threshold = cv_music_resync_threshold.value/1000.0*(4*44100);
|
||||||
|
}
|
||||||
|
|
||||||
/// ------------------------
|
/// ------------------------
|
||||||
/// Music Playback
|
/// Music Playback
|
||||||
/// ------------------------
|
/// ------------------------
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue