Try to fix setting and reading music positions
Disabling music fade in so we can see if this acutally works. Seems to have issues as it doesn't go back to the exact spot it saves (possibly samplerate related?). It also seems to play a short sample of the start of the song for some reason curtainly better then it not working at all.
This commit is contained in:
parent
1d2a4f98c6
commit
c7d577a4d0
2 changed files with 35 additions and 11 deletions
|
|
@ -878,7 +878,7 @@ void P_RestoreMusic(player_t *player)
|
|||
position = mapmusposition;
|
||||
|
||||
S_ChangeMusicEx(mapmusname, mapmusflags, true, position, 0,
|
||||
S_GetRestoreMusicFadeIn());
|
||||
/*S_GetRestoreMusicFadeIn()*/ 0);
|
||||
S_ClearRestoreMusicFadeInCvar();
|
||||
mapmusresume = 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -387,7 +387,7 @@ static boolean I_QueueNextSample(boolean unqueue)
|
|||
if (count == 0)
|
||||
{
|
||||
// TODO: looppoints
|
||||
sf_seek(audio.musicstream, 0, SEEK_SET);
|
||||
sf_seek(audio.musicstream, 0, SF_SEEK_SET);
|
||||
}
|
||||
|
||||
samplerate = audio.musicinfo.samplerate;
|
||||
|
|
@ -944,6 +944,19 @@ boolean I_SetSongSpeed(float speed)
|
|||
return false;
|
||||
}
|
||||
|
||||
// Thank you random stack overflow user (second post)!
|
||||
// https://stackoverflow.com/questions/10160401/openal-get-the-current-playing-position-of-a-source
|
||||
|
||||
float SamplesToSeconds(sf_count_t samples, int sampleRate) {
|
||||
float seconds = samples / (float) sampleRate;
|
||||
return seconds;
|
||||
}
|
||||
|
||||
float SecondsToSamples(sf_count_t samples, int sampleRate) {
|
||||
float seconds = samples * (float) sampleRate;
|
||||
return seconds;
|
||||
}
|
||||
|
||||
UINT32 I_GetSongLength(void)
|
||||
{
|
||||
LOCKAUDIO;
|
||||
|
|
@ -986,10 +999,12 @@ UINT32 I_GetSongLength(void)
|
|||
return (UINT32)(openmpt_module_get_duration_seconds(openmpt_mhandle) * 1000.);
|
||||
#endif
|
||||
|
||||
sf_count_t cur = sf_seek(audio.musicstream, 0, SEEK_CUR);
|
||||
sf_count_t length = sf_seek(audio.musicstream, 0, SEEK_END);
|
||||
sf_seek(audio.musicstream, cur, SEEK_SET);
|
||||
return length / 2 / audio.musicinfo.samplerate;
|
||||
float position = SamplesToSeconds(audio.musicinfo.frames, audio.musicinfo.samplerate);
|
||||
|
||||
float sampleoffset = ((float) BUFFERSIZE / audio.musicinfo.samplerate) * BUFFERCOUNT;
|
||||
position = position - sampleoffset;
|
||||
|
||||
return position * 1000.0f;
|
||||
}
|
||||
|
||||
boolean I_SetSongLoopPoint(UINT32 looppoint)
|
||||
|
|
@ -1010,8 +1025,14 @@ boolean I_SetSongPosition(UINT32 position)
|
|||
if (audio.music == INVALID_HANDLE)
|
||||
return false;
|
||||
|
||||
if (!TRY(alSourcef, audio.music, AL_SEC_OFFSET, position / 1000.0f))
|
||||
return false;
|
||||
position = position / 1000.0f;
|
||||
|
||||
float sampleoffset = ((float) BUFFERSIZE / audio.musicinfo.samplerate) * BUFFERCOUNT;
|
||||
position = position + sampleoffset;
|
||||
|
||||
sf_count_t finalposition = SecondsToSamples(position, audio.musicinfo.samplerate);
|
||||
|
||||
sf_seek(audio.musicstream, finalposition, SF_SEEK_SET);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -1023,9 +1044,12 @@ UINT32 I_GetSongPosition(void)
|
|||
if (audio.music == INVALID_HANDLE)
|
||||
return 0;
|
||||
|
||||
float position;
|
||||
if (!TRY(alGetSourcef, audio.music, AL_SEC_OFFSET, &position))
|
||||
return 0;
|
||||
sf_count_t samples = sf_seek(audio.musicstream, 0, SF_SEEK_CUR);
|
||||
|
||||
float position = SamplesToSeconds(samples, audio.musicinfo.samplerate);
|
||||
|
||||
float sampleoffset = ((float) BUFFERSIZE / audio.musicinfo.samplerate) * BUFFERCOUNT;
|
||||
position = position - sampleoffset;
|
||||
|
||||
return position * 1000.0f;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue