Fix seeking

This commit is contained in:
Zachary Hall 2024-10-16 10:56:24 -07:00
parent 299a85bfad
commit 28314c4372

View file

@ -95,6 +95,7 @@ void ZsmBackend::switch_stream(int idx) {
for (uint8_t i = 0; i < 16; i++) { for (uint8_t i = 0; i < 16; i++) {
psg_writereg(i * 4 + 2, 0); psg_writereg(i * 4 + 2, 0);
} }
file->seek(music_data_start, SeekType::SET);
this->cpuClocks = 0.0; this->cpuClocks = 0.0;
this->delayTicks = 0.0; this->delayTicks = 0.0;
this->ticks = 0.0; this->ticks = 0.0;
@ -330,6 +331,7 @@ void ZsmBackend::seek_internal(double position, bool loop) {
this->position = std::floor(this->position * PSG_FREQ) / PSG_FREQ; this->position = std::floor(this->position * PSG_FREQ) / PSG_FREQ;
position = std::floor(position * PSG_FREQ) / PSG_FREQ; position = std::floor(position * PSG_FREQ) / PSG_FREQ;
if (this->position > position) { if (this->position > position) {
switch_stream(0);
file->seek(music_data_start, SeekType::SET); file->seek(music_data_start, SeekType::SET);
this->cpuClocks = 0.0; this->cpuClocks = 0.0;
this->delayTicks = 0; this->delayTicks = 0;
@ -338,8 +340,6 @@ void ZsmBackend::seek_internal(double position, bool loop) {
} else if (this->position == position) { } else if (this->position == position) {
audio_buf.clear(); audio_buf.clear();
return; return;
} else {
switch_stream(0);
} }
while (this->position < position) { while (this->position < position) {
audio_buf.clear(); audio_buf.clear();