Revert "Fix music looping on digital"

This reverts commit fd8454c395.
This commit is contained in:
Alug committed 2025-12-07 17:08:51 +01:00
1 parent 265d949bf2
commit aea7fbb872
1 file changed
+21 -23
+21 -23
View File
@@ -94,8 +94,8 @@ static SF_INFO music_info;
static SNDFILE *music_file;
static SDL_AudioStream *music_stream;
static sndlump_t music_lump;
static INT32 loop_point;
static INT32 song_length;
static float loop_point;
static float song_length;
static bool song_paused;
static bool loop_song;
static float music_speed;
@@ -259,7 +259,7 @@ static void MusicCallback(void *userdata, SDL_AudioStream *stream, int additiona
{
if (loop_song)
{
sf_seek(music_file, loop_point * music_info.samplerate / 1000, SEEK_SET);
sf_seek(music_file, loop_point * music_info.samplerate, SEEK_SET);
sf_read_float(music_file, &needed[count], amount - count);
}
else
@@ -370,12 +370,12 @@ static void StreamCallback(void *userdata, SDL_AudioStream *stream, int addition
if (new_pos < pos)
{
// we looped, compensate
INT32 len = song_length;
if (len > 0)
float len = I_GetSongLength();
if (len > 0.0f)
{
pos -= len - loop_point;
fading_from -= len - loop_point;
fading_to -= len - loop_point;
pos -= len - loop_point * 1000.0f;
fading_from -= len - loop_point * 1000.0f;
fading_to -= len - loop_point * 1000.0f;
}
}
@@ -1326,7 +1326,7 @@ UINT32 I_GetSongLength(void)
}
#endif
if (music_stream)
return song_length;
return song_length / 1000.0f;
return 0;
}
@@ -1341,7 +1341,7 @@ boolean I_SetSongLoopPoint(UINT32 looppoint)
looppoint %= length;
SDL_LockAudioStream(audio_stream);
loop_point = max(looppoint, 0);
loop_point = max(((float)looppoint / 1000.0f), 0.0f);
SDL_UnlockAudioStream(audio_stream);
return true;
}
@@ -1368,8 +1368,7 @@ UINT32 I_GetSongLoopPoint(void)
}
#endif
if (music_stream)
return loop_point;
return loop_point * 1000.0f;
return 0;
}
@@ -1429,8 +1428,8 @@ boolean I_SetSongPosition(UINT32 position)
if (music_stream)
{
SDL_LockAudioStream(audio_stream);
position %= song_length;
bool status = sf_seek(music_file, position * music_info.samplerate / 1000, SEEK_SET) != -1;
position %= (int)(song_length * music_info.samplerate * music_info.channels);
bool status = sf_seek(music_file, position, SEEK_SET) != -1;
SDL_UnlockAudioStream(audio_stream);
return status;
}
@@ -1504,8 +1503,8 @@ static const size_t loopms_key_len = sizeof(loopms_key)-1;
static void ResetMusic(void)
{
loop_point = 0;
song_length = 0;
loop_point = 0.0f;
song_length = 0.0f;
song_paused = false;
fading_target = 1.0f;
fading_source = fading_from = fading_to = 0.0f;
@@ -1697,33 +1696,32 @@ boolean I_LoadSong(char *data, size_t len)
SDL_SetAudioStreamGetCallback(music_stream, MusicCallback, NULL);
// Find the OGG loop point.
loop_point = 0;
song_length = music_info.frames * 1000 / music_info.samplerate;
loop_point = 0.0f;
song_length = (float)music_info.frames / music_info.samplerate;
while ((UINT32)(p - data) < len)
{
if (loop_point == 0 && strncmp(p, loop_prefix, loop_prefix_len) == 0)
if (fpclassify(loop_point) == FP_ZERO && strncmp(p, loop_prefix, loop_prefix_len) == 0)
{
p += loop_prefix_len; // skip LOOP
if (strncmp(p, looppoint_key, looppoint_key_len) == 0) // is it LOOPPOINT=?
{
p += looppoint_key_len; // skip POINT=
loop_point = (44.1f+atoi(p)) / 44.1f; // LOOPPOINT works by sample count.
loop_point = (float)((44.1f+atoi(p)) / 44100.0f); // LOOPPOINT works by sample count.
// because SDL_Mixer is USELESS and can't even tell us
// something simple like the frequency of the streaming music,
// we are unfortunately forced to assume that ALL MUSIC is 44100hz.
// This means a lot of tracks that are only 22050hz for a reasonable downloadable file size will loop VERY badly.
// ^ the above is no longer true, but we're keeping it for backwards compatibility
}
else if (strncmp(p, loopms_key, loopms_key_len) == 0) // is it LOOPMS=?
{
p += loopms_key_len; // skip MS=
loop_point = atoi(p); // LOOPMS works by real time, as miliseconds.
loop_point = (float)(atof(p) / 1000.0); // LOOPMS works by real time, as miliseconds.
// Everything that uses LOOPMS will work perfectly with SDL_Mixer.
}
}
if (loop_point != 0) // Got what we needed
if (fpclassify(loop_point) != FP_ZERO) // Got what we needed
break;
else // continue searching
p++;