fixed freq and r_amp float precision
This commit is contained in:
parent
d827dbb754
commit
d33bd771f8
3 changed files with 15 additions and 15 deletions
|
|
@ -8,7 +8,7 @@ pub const Activity = struct {
|
|||
end_tick: u32,
|
||||
opcode: u16,
|
||||
soundnode: *SoundNode,
|
||||
operands: [10]f16 = std.mem.zeroes([10]f16),
|
||||
operands: [10]f64 = std.mem.zeroes([10]f64),
|
||||
|
||||
pub fn do(self: *Activity) !void {
|
||||
switch (self.opcode) {
|
||||
|
|
@ -32,20 +32,20 @@ pub const Activity = struct {
|
|||
|
||||
try self.soundnode.freqamp.reset();
|
||||
|
||||
const init_freq: f16 = self.operands[0];
|
||||
const final_freq: f16 = self.operands[1];
|
||||
const init_freq: f64 = self.operands[0];
|
||||
const final_freq: f64 = self.operands[1];
|
||||
|
||||
const timediff: u32 = self.end_tick - self.start_tick;
|
||||
const elapsed: u32 = self.soundnode.freqamp.current_tick - self.start_tick;
|
||||
const freqdiff: f128 = ((@as(f128, final_freq - init_freq))) / @as(f128, @floatFromInt(timediff));
|
||||
|
||||
const res_freq: f16 = init_freq + @as(f16, @floatCast(freqdiff * @as(f128, @floatFromInt(elapsed)) ));
|
||||
const res_freq: f64 = init_freq + @as(f64, @floatCast(freqdiff * @as(f128, @floatFromInt(elapsed)) ));
|
||||
|
||||
try self.soundnode.freqamp.setfreq(res_freq, self.operands[2]);
|
||||
|
||||
if (self.soundnode.freqamp.current_tick % 44100 == 0) {
|
||||
print("TIMEDIFF {d}\n", .{timediff});
|
||||
print("FREQDIFF {d}\n", .{@as(f16, @floatCast(freqdiff))});
|
||||
print("FREQDIFF {d}\n", .{@as(f64, @floatCast(freqdiff))});
|
||||
print("RESFREQ {d}\n", .{res_freq});
|
||||
self.soundnode.freqamp.prnt();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,10 +6,10 @@ const ArrayList = std.ArrayList;
|
|||
|
||||
pub const FreqAmp = struct {
|
||||
|
||||
freq: f16,
|
||||
r_amp: f16,
|
||||
freq: f64,
|
||||
r_amp: f64,
|
||||
|
||||
pub fn create(allocator: Allocator, freq: f16, r_amp: f16) !*FreqAmp {
|
||||
pub fn create(allocator: Allocator, freq: f64, r_amp: f64) !*FreqAmp {
|
||||
|
||||
const fa = try allocator.create(FreqAmp);
|
||||
fa.* = .{.freq = freq, .r_amp = r_amp};
|
||||
|
|
@ -172,7 +172,7 @@ pub const FreqAmpBuffer = struct {
|
|||
|
||||
}
|
||||
|
||||
pub fn setfreq(self: *FreqAmpBuffer, freq: f16, r_amp: f16) !void {
|
||||
pub fn setfreq(self: *FreqAmpBuffer, freq: f64, r_amp: f64) !void {
|
||||
|
||||
const cur_index = self.index_by_tick(self.current_tick);
|
||||
var clist = self.freqamps[cur_index];
|
||||
|
|
@ -197,7 +197,7 @@ pub const FreqAmpBuffer = struct {
|
|||
|
||||
}
|
||||
|
||||
pub fn addfreq(self: *FreqAmpBuffer, freq: f16, r_amp: f16) !void {
|
||||
pub fn addfreq(self: *FreqAmpBuffer, freq: f64, r_amp: f64) !void {
|
||||
|
||||
const cur_index = self.index_by_tick(self.current_tick);
|
||||
var clist = self.freqamps[cur_index];
|
||||
|
|
|
|||
|
|
@ -10,9 +10,9 @@ const Activity = @import("activity.zig").Activity;
|
|||
const SoundSettings = @import("settings.zig").SoundSettings;
|
||||
|
||||
|
||||
pub fn singleSineTick(st: *SoundSettings, freq: f16, t: u32) f64 {
|
||||
pub fn singleSineTick(st: *SoundSettings, freq: f64, t: u32) f64 {
|
||||
const ft: f64 = @floatFromInt(t);
|
||||
return math.sin(st.sine_multiplier * @as(f64, freq) * ft);
|
||||
return math.sin(st.sine_multiplier * freq * ft);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -26,7 +26,7 @@ pub fn main() !void {
|
|||
var settings: SoundSettings = SoundSettings{};
|
||||
|
||||
const start_tick: u32 = 0;
|
||||
const end_tick: u32 = 44100 * 10;
|
||||
const end_tick: u32 = 44100 * 3;
|
||||
|
||||
var left: SoundNode = try SoundNode.init(allocator, "left_sink");
|
||||
defer left.deinit();
|
||||
|
|
@ -47,7 +47,7 @@ pub fn main() !void {
|
|||
};
|
||||
|
||||
a.operands[0] = 410.0;
|
||||
a.operands[1] = 0.8;
|
||||
a.operands[1] = 0.5;
|
||||
|
||||
var sine2: SoundNode = try SoundNode.init(allocator, "sine2");
|
||||
defer sine2.deinit();
|
||||
|
|
@ -91,7 +91,7 @@ pub fn main() !void {
|
|||
try soundnodes.append(&left);
|
||||
try soundnodes.append(&right);
|
||||
|
||||
try left.wire_in.append(&sine2);
|
||||
try left.wire_in.append(&sine);
|
||||
try right.wire_in.append(&sine2);
|
||||
|
||||
var tick: u32 = start_tick;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue