From e471b7857b2a2b739445776fa5b29fd9b12659fd Mon Sep 17 00:00:00 2001 From: Andre Weissflog Date: Thu, 22 Aug 2024 18:42:37 +0200 Subject: [PATCH] get rid of signed integer division --- emus/bombjack/bombjack.zig | 2 +- emus/kc85/kc85.zig | 2 +- emus/namco/namco.zig | 2 +- src/chips/ay3891.zig | 2 +- src/common/audio.zig | 2 +- src/systems/namco.zig | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/emus/bombjack/bombjack.zig b/emus/bombjack/bombjack.zig index 7df780e..babc13e 100644 --- a/emus/bombjack/bombjack.zig +++ b/emus/bombjack/bombjack.zig @@ -12,7 +12,7 @@ export fn init() void { host.prof.init(); sys.initInPlace(.{ .audio = .{ - .sample_rate = host.audio.sampleRate(), + .sample_rate = @intCast(host.audio.sampleRate()), .callback = host.audio.push, }, .roms = .{ diff --git a/emus/kc85/kc85.zig b/emus/kc85/kc85.zig index 223bb4d..cb49a85 100644 --- a/emus/kc85/kc85.zig +++ b/emus/kc85/kc85.zig @@ -38,7 +38,7 @@ export fn init() void { host.prof.init(); sys.initInPlace(.{ .audio = .{ - .sample_rate = host.audio.sampleRate(), + .sample_rate = @intCast(host.audio.sampleRate()), .volume = 0.5, .callback = host.audio.push, }, diff --git a/emus/namco/namco.zig b/emus/namco/namco.zig index b0e060c..fe32641 100644 --- a/emus/namco/namco.zig +++ b/emus/namco/namco.zig @@ -22,7 +22,7 @@ export fn init() void { host.prof.init(); sys.initInPlace(.{ .audio = .{ - .sample_rate = host.audio.sampleRate(), + .sample_rate = @intCast(host.audio.sampleRate()), .callback = host.audio.push, }, .roms = switch (model) { diff --git a/src/chips/ay3891.zig b/src/chips/ay3891.zig index f6e51c1..11689c4 100644 --- a/src/chips/ay3891.zig +++ b/src/chips/ay3891.zig @@ -217,7 +217,7 @@ pub fn Type(comptime cfg: TypeConfig) type { } pub fn init(opts: Options) Self { - const sample_period: i32 = @intCast(@divFloor(opts.tick_hz * FIXEDPOINT_SCALE, opts.sound_hz)); + const sample_period: i32 = @intCast((opts.tick_hz * FIXEDPOINT_SCALE) / opts.sound_hz); var self = Self{ .cs_mask = @as(u8, opts.chip_select) << 4, .noise = .{ diff --git a/src/common/audio.zig b/src/common/audio.zig index e2ab027..0c3104d 100644 --- a/src/common/audio.zig +++ b/src/common/audio.zig @@ -32,7 +32,7 @@ pub fn Type(cfg: TypeConfig) type { /// runtime audio options pub const Options = struct { /// host audio frequency in Hz - sample_rate: i32, + sample_rate: u32, /// output volume modulator (0..1) volume: f32 = 0.75, /// called when new chunk of audio data is ready diff --git a/src/systems/namco.zig b/src/systems/namco.zig index 9a6cf2d..9691c1a 100644 --- a/src/systems/namco.zig +++ b/src/systems/namco.zig @@ -810,7 +810,7 @@ pub fn Type(comptime sys: System) type { fn initWSG(opts: Options) WSG { assert(opts.audio.sample_rate > 0); - const period: i32 = @divFloor(CPU_FREQUENCY * AUDIO.SAMPLE_SCALE, opts.audio.sample_rate); + const period: i32 = @intCast((CPU_FREQUENCY * AUDIO.SAMPLE_SCALE) / opts.audio.sample_rate); return .{ .tick_counter = AUDIO.PERIOD, .sample_period = period,