Skip to content

Commit

Permalink
get rid of signed integer division
Browse files Browse the repository at this point in the history
  • Loading branch information
floooh committed Aug 22, 2024
1 parent 2440a20 commit e471b78
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion emus/bombjack/bombjack.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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 = .{
Expand Down
2 changes: 1 addition & 1 deletion emus/kc85/kc85.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down
2 changes: 1 addition & 1 deletion emus/namco/namco.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/chips/ay3891.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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 = .{
Expand Down
2 changes: 1 addition & 1 deletion src/common/audio.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/systems/namco.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit e471b78

Please sign in to comment.