Fix an issue where the Ambience layer would break looping points for all other channels due to loop_start and loop_end only being a single variable. (#164)

This occurs due to BASS not having any private variables of its own, so it was simply using the public variables loop_start and loop_end as reference - since those changed for any new song playing on another channel, the old looping points got replaced, and the seamless looping stops working.
The solution was easy - just make a  loop_start/loop_end variable for every supported channel - so 4 variables in our case.
This commit is contained in:
Crystalwarrior 2020-07-04 20:15:52 +03:00 committed by GitHub
parent c533370fd8
commit 44a4a2d23e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 14 deletions

View File

@ -25,8 +25,8 @@ public:
const int m_channelmax = 4;
// These have to be public for the stupid sync thing
int loop_start = 0;
int loop_end = 0;
int loop_start[4] = {0, 0, 0, 0};
int loop_end[4] = {0, 0, 0, 0};
public slots:
void play(QString p_song, int channel = 0, bool loop = false,

View File

@ -40,8 +40,8 @@ void AOMusicPlayer::play(QString p_song, int channel, bool loop,
QString d_path = f_path + ".txt";
loop_start = 0;
loop_end = BASS_ChannelGetLength(newstream, BASS_POS_BYTE);
loop_start[channel] = 0;
loop_end[channel] = BASS_ChannelGetLength(newstream, BASS_POS_BYTE);
if (loop && file_exists(d_path)) // Contains loop/etc. information file
{
QStringList lines = ao_app->read_file(d_path).split("\n");
@ -64,11 +64,11 @@ void AOMusicPlayer::play(QString p_song, int channel, bool loop,
QWORD bytes = static_cast<QWORD>(args[1].trimmed().toFloat() *
sample_size * num_channels);
if (arg == "loop_start")
loop_start = bytes;
loop_start[channel] = bytes;
else if (arg == "loop_length")
loop_end = loop_start + bytes;
loop_end[channel] = loop_start[channel] + bytes;
else if (arg == "loop_end")
loop_end = bytes;
loop_end[channel] = bytes;
}
qDebug() << "Found data file for song" << p_song << "length"
<< BASS_ChannelGetLength(newstream, BASS_POS_BYTE) << "loop start"
@ -111,7 +111,7 @@ void AOMusicPlayer::play(QString p_song, int channel, bool loop,
else
this->set_volume(m_volume[channel], channel);
this->set_looping(loop); // Have to do this here due to any
this->set_looping(loop, channel); // Have to do this here due to any
// crossfading-related changes, etc.
}
@ -145,6 +145,7 @@ void CALLBACK loopProc(HSYNC handle, DWORD channel, DWORD data, void *user)
void AOMusicPlayer::set_looping(bool toggle, int channel)
{
qDebug() << "Setting looping for channel" << channel << "to" << toggle;
m_looping = toggle;
if (!m_looping) {
if (BASS_ChannelFlags(m_stream_list[channel], 0, 0) & BASS_SAMPLE_LOOP)
@ -161,13 +162,13 @@ void AOMusicPlayer::set_looping(bool toggle, int channel)
loop_sync[channel]); // remove the sync
loop_sync[channel] = 0;
}
if (loop_start > 0) {
if (loop_end == 0)
loop_end = BASS_ChannelGetLength(m_stream_list[channel], BASS_POS_BYTE);
if (loop_end > 0) // Don't loop zero length songs even if we're asked to
if (loop_start[channel] > 0) {
if (loop_end[channel] == 0)
loop_end[channel] = BASS_ChannelGetLength(m_stream_list[channel], BASS_POS_BYTE);
if (loop_end[channel] > 0) // Don't loop zero length songs even if we're asked to
loop_sync[channel] = BASS_ChannelSetSync(
m_stream_list[channel], BASS_SYNC_POS | BASS_SYNC_MIXTIME, loop_end,
loopProc, &loop_start);
m_stream_list[channel], BASS_SYNC_POS | BASS_SYNC_MIXTIME, loop_end[channel],
loopProc, &loop_start[channel]);
}
}
}