Prefer previous position used when loop position is not exactly at a command
This commit is contained in:
parent
1372b758ee
commit
f092b4bd36
1 changed files with 14 additions and 4 deletions
|
@ -49,23 +49,33 @@ void ZsmBackend::load(const char *filename) {
|
||||||
pcm_data_offs = (loop_point[0] * 16) + pcm_offset;
|
pcm_data_offs = (loop_point[0] * 16) + pcm_offset;
|
||||||
file->seek(music_data_start, SeekType::SET);
|
file->seek(music_data_start, SeekType::SET);
|
||||||
this->loop_point = std::max(this->loop_point, (uint32_t)music_data_start);
|
this->loop_point = std::max(this->loop_point, (uint32_t)music_data_start);
|
||||||
|
double prev_time = 0.0;
|
||||||
double time = 0.0;
|
double time = 0.0;
|
||||||
double tmpDelayTicks = 0.0;
|
double tmpDelayTicks = 0.0;
|
||||||
loop_pos = -1.0;
|
loop_pos = -1.0;
|
||||||
|
uint32_t prev_pos = 0;
|
||||||
while (true) {
|
while (true) {
|
||||||
tmpDelayTicks -= get_delay_per_frame();
|
tmpDelayTicks -= get_delay_per_frame();
|
||||||
if (tmpDelayTicks < 0.0) {
|
if (tmpDelayTicks < 0.0) {
|
||||||
if (file->get_pos() >= this->loop_point && this->loop_pos < 0) {
|
|
||||||
loop_pos = time;
|
|
||||||
this->loop_point = file->get_pos();
|
|
||||||
}
|
|
||||||
ZsmCommand cmd = get_command();
|
ZsmCommand cmd = get_command();
|
||||||
|
size_t cur_pos = file->get_pos();
|
||||||
|
if (cur_pos >= this->loop_point && this->loop_pos < 0) {
|
||||||
|
if (cur_pos > this->loop_point) {
|
||||||
|
this->loop_point = prev_pos;
|
||||||
|
loop_pos = prev_time;
|
||||||
|
} else {
|
||||||
|
loop_pos = time;
|
||||||
|
this->loop_point = cur_pos;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (cmd.id == ZsmEOF) {
|
if (cmd.id == ZsmEOF) {
|
||||||
break;
|
break;
|
||||||
} else if (cmd.id == Delay) {
|
} else if (cmd.id == Delay) {
|
||||||
time += ((double)cmd.delay) / ((double)(tick_rate));
|
time += ((double)cmd.delay) / ((double)(tick_rate));
|
||||||
tmpDelayTicks += cmd.delay;
|
tmpDelayTicks += cmd.delay;
|
||||||
}
|
}
|
||||||
|
prev_pos = file->get_pos();
|
||||||
|
prev_time = time;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this->loop_pos < 0.0) {
|
if (this->loop_pos < 0.0) {
|
||||||
|
|
Loading…
Reference in a new issue