add not-broken looping code using seconds instead of samples (#944)

This commit is contained in:
in1tiate 2024-04-10 19:29:03 -05:00 committed by GitHub
parent 3e42588b51
commit ad93dd8238
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -61,11 +61,19 @@ QString AOMusicPlayer::play(QString p_song, int channel, bool loop,
if (loop && file_exists(d_path)) // Contains loop/etc. information file
{
QStringList lines = ao_app->read_file(d_path).split("\n");
bool seconds_mode = false;
foreach (QString line, lines) {
QStringList args = line.split("=");
if (args.size() < 2)
continue;
QString arg = args[0].trimmed();
if (arg == "seconds") {
if (args[1].trimmed() == "true") {
seconds_mode = true; // Use new epic behavior
continue;
}
continue;
}
float sample_rate;
BASS_ChannelGetAttribute(newstream, BASS_ATTRIB_FREQ, &sample_rate);
@ -77,8 +85,15 @@ QString AOMusicPlayer::play(QString p_song, int channel, bool loop,
int num_channels = 2;
// Calculate the bytes for loop_start/loop_end to use with the sync proc
QWORD bytes = static_cast<QWORD>(args[1].trimmed().toUInt() *
sample_size * num_channels);
QWORD bytes;
if (seconds_mode) {
bytes =
BASS_ChannelSeconds2Bytes(newstream, args[1].trimmed().toDouble());
}
else {
bytes = static_cast<QWORD>(args[1].trimmed().toUInt() * sample_size *
num_channels);
}
if (arg == "loop_start")
loop_start[channel] = bytes;
else if (arg == "loop_length")