feat: reimplement audio sync

APU will now drop samples if the Audio Queue is already full, therefore
creating a "sped-up" effect when the emulator runs faster than 100%
This commit is contained in:
2022-09-08 20:38:42 -03:00
parent fa862f095a
commit 65cfc97f28
3 changed files with 58 additions and 33 deletions

View File

@@ -180,11 +180,11 @@ const Audio = struct {
export fn callback(userdata: ?*anyopaque, stream: [*c]u8, len: c_int) void {
const apu = @ptrCast(*Apu, @alignCast(@alignOf(*Apu), userdata));
const written = SDL.SDL_AudioStreamGet(apu.stream, stream, len);
_ = SDL.SDL_AudioStreamGet(apu.stream, stream, len);
// If we don't write anything, play silence otherwise garbage will be played
// FIXME: I don't think this hack to remove DC Offset is acceptable :thinking:
if (written == 0) std.mem.set(u8, stream[0..@intCast(usize, len)], 0x40);
// if (written == 0) std.mem.set(u8, stream[0..@intCast(usize, len)], 0x40);
}
};