From 2bce02baaa692b36d30ce3228d55adc43323e7b5 Mon Sep 17 00:00:00 2001 From: Rekai Musuka Date: Sun, 30 Oct 2022 05:03:02 -0300 Subject: [PATCH] revert(apu): switch from f32 44.1kHz to u16 32.768kHz --- src/core/emu.zig | 4 ++-- src/platform.zig | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/core/emu.zig b/src/core/emu.zig index a1c7259..0c8a03c 100644 --- a/src/core/emu.zig +++ b/src/core/emu.zig @@ -105,8 +105,8 @@ pub fn runFrame(sched: *Scheduler, cpu: *Arm7tdmi) void { } fn audioSync(audio_sync: bool, stream: *SDL.SDL_AudioStream, is_buffer_full: *bool) void { - comptime std.debug.assert(@import("../platform.zig").sample_format == SDL.AUDIO_F32); - const sample_size = 2 * @sizeOf(f32); + comptime std.debug.assert(@import("../platform.zig").sample_format == SDL.AUDIO_U16); + const sample_size = 2 * @sizeOf(u16); const max_buf_size: c_int = 0x400; // Determine whether the APU is busy right at this moment diff --git a/src/platform.zig b/src/platform.zig index f4325dd..8e3cc87 100644 --- a/src/platform.zig +++ b/src/platform.zig @@ -14,8 +14,8 @@ const span = @import("util.zig").span; const gba_width = @import("core/ppu.zig").width; const gba_height = @import("core/ppu.zig").height; -pub const sample_rate = 44100; -pub const sample_format = SDL.AUDIO_F32; +pub const sample_rate = 1 << 15; +pub const sample_format = SDL.AUDIO_U16; const default_title: []const u8 = "ZBA"; @@ -203,8 +203,8 @@ pub const Gui = struct { SDL.SDLK_RETURN => io.keyinput.start.set(), SDL.SDLK_RSHIFT => io.keyinput.select.set(), SDL.SDLK_i => { - comptime std.debug.assert(sample_format == SDL.AUDIO_F32); - log.err("Sample Count: {}", .{@intCast(u32, SDL.SDL_AudioStreamAvailable(cpu.bus.apu.stream)) / (2 * @sizeOf(f32))}); + comptime std.debug.assert(sample_format == SDL.AUDIO_U16); + log.err("Sample Count: {}", .{@intCast(u32, SDL.SDL_AudioStreamAvailable(cpu.bus.apu.stream)) / (2 * @sizeOf(u16))}); }, SDL.SDLK_j => log.err("Scheduler Capacity: {} | Scheduler Event Count: {}", .{ scheduler.queue.capacity(), scheduler.queue.count() }), SDL.SDLK_k => { @@ -271,8 +271,8 @@ const Audio = struct { want.callback = Self.callback; want.userdata = apu; - std.debug.assert(sample_format == SDL.AUDIO_F32); - log.info("Host Sample Rate: {}Hz, Host Format: SDL.AUDIO_F32", .{sample_rate}); + std.debug.assert(sample_format == SDL.AUDIO_U16); + log.info("Host Sample Rate: {}Hz, Host Format: SDL.AUDIO_U16", .{sample_rate}); const device = SDL.SDL_OpenAudioDevice(null, 0, &want, &have, 0); if (device == 0) panic();