Compare commits
2 Commits
697ec46cf1
...
1170673447
Author | SHA1 | Date |
---|---|---|
Rekai Nyangadzayi Musuka | 1170673447 | |
Rekai Nyangadzayi Musuka | c007bf4d8e |
|
@ -200,7 +200,10 @@ pub const Apu = struct {
|
||||||
self.stream = SDL.SDL_NewAudioStream(SDL.AUDIO_U16, 2, @intCast(c_int, self.sampleRate()), SDL.AUDIO_U16, 2, host_sample_rate) orelse unreachable;
|
self.stream = SDL.SDL_NewAudioStream(SDL.AUDIO_U16, 2, @intCast(c_int, self.sampleRate()), SDL.AUDIO_U16, 2, host_sample_rate) orelse unreachable;
|
||||||
}
|
}
|
||||||
|
|
||||||
_ = SDL.SDL_AudioStreamPut(self.stream, &[2]u16{ final_left, final_right }, 2 * @sizeOf(u16));
|
// If we add 0x4040 to each sample the DC Offset is removed
|
||||||
|
// note: found this through guess and check
|
||||||
|
// FIXME: Pretty sure this is a dirty hack and should be fixed
|
||||||
|
_ = SDL.SDL_AudioStreamPut(self.stream, &[2]u16{ final_left + 0x4040, final_right + 0x4040 }, 2 * @sizeOf(u16));
|
||||||
self.sched.push(.SampleAudio, self.sampleTicks() -| late);
|
self.sched.push(.SampleAudio, self.sampleTicks() -| late);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,10 +51,7 @@ pub fn runFrame(sched: *Scheduler, cpu: *Arm7tdmi) void {
|
||||||
const frame_end = sched.tick + cycles_per_frame;
|
const frame_end = sched.tick + cycles_per_frame;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
const next = sched.nextTimestamp();
|
while (sched.tick < std.math.min(frame_end, sched.nextTimestamp())) {
|
||||||
const run_until = std.math.min(next, frame_end);
|
|
||||||
|
|
||||||
while (sched.tick < run_until) {
|
|
||||||
if (cpu.bus.io.haltcnt == .Execute) cpu.step() else sched.tick += 1;
|
if (cpu.bus.io.haltcnt == .Execute) cpu.step() else sched.tick += 1;
|
||||||
cpu.handleDMATransfers();
|
cpu.handleDMATransfers();
|
||||||
}
|
}
|
||||||
|
|
|
@ -239,10 +239,13 @@ fn initAudio(apu: *Apu) SDL.SDL_AudioDeviceID {
|
||||||
return dev;
|
return dev;
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: Sometimes, we hear garbage upon program start. Why?
|
|
||||||
export fn audioCallback(userdata: ?*anyopaque, stream: [*c]u8, len: c_int) void {
|
export fn audioCallback(userdata: ?*anyopaque, stream: [*c]u8, len: c_int) void {
|
||||||
const apu = @ptrCast(*Apu, @alignCast(8, userdata));
|
const apu = @ptrCast(*Apu, @alignCast(8, userdata));
|
||||||
_ = SDL.SDL_AudioStreamGet(apu.stream, stream, len);
|
const written = 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)], 0x80);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn getSavePath(alloc: std.mem.Allocator) !?[]const u8 {
|
fn getSavePath(alloc: std.mem.Allocator) !?[]const u8 {
|
||||||
|
|
|
@ -90,10 +90,12 @@ pub const Scheduler = struct {
|
||||||
self.queue.add(.{ .kind = kind, .tick = self.now() + end }) catch unreachable;
|
self.queue.add(.{ .kind = kind, .tick = self.now() + end }) catch unreachable;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn nextTimestamp(self: *Self) u64 {
|
pub inline fn nextTimestamp(self: *const Self) u64 {
|
||||||
if (self.queue.peek()) |e| return e.tick;
|
@setRuntimeSafety(false);
|
||||||
|
|
||||||
unreachable; // There's always the HeatDeath event scheduled
|
// Typically you'd use PriorityQueue.peek here, but there's always at least a HeatDeath
|
||||||
|
// event in the PQ so we can just do this instead. Should be faster in ReleaseSafe
|
||||||
|
return self.queue.items[0].tick;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue