somewhat working attempt
This commit is contained in:
parent
2eb9ed0aba
commit
b542e9e9e8
1 changed files with 62 additions and 18 deletions
|
|
@ -9,6 +9,14 @@ pub const FreqAmp = struct {
|
|||
freq: f16,
|
||||
r_amp: f16,
|
||||
|
||||
pub fn create(allocator: Allocator, freq: f16, r_amp: f16) !*FreqAmp {
|
||||
|
||||
const fa = try allocator.create(FreqAmp);
|
||||
fa.* = .{.freq = freq, .r_amp = r_amp};
|
||||
return fa;
|
||||
|
||||
}
|
||||
|
||||
pub fn prnt(self: *FreqAmp) void {
|
||||
print("<Freq::{d} ; R_Amp::{d}>\n", .{self.freq, self.r_amp});
|
||||
}
|
||||
|
|
@ -33,6 +41,21 @@ pub const FreqAmpList = struct {
|
|||
|
||||
}
|
||||
|
||||
pub fn create(allocator: Allocator) !*FreqAmpList {
|
||||
|
||||
const lst = ArrayList(*FreqAmp).init(allocator);
|
||||
const fal = try allocator.create(FreqAmpList);
|
||||
|
||||
fal.* = .{
|
||||
.allocator = allocator,
|
||||
.refcount = 0,
|
||||
.lst = lst,
|
||||
};
|
||||
|
||||
return fal;
|
||||
|
||||
}
|
||||
|
||||
pub fn deinit(self: *FreqAmpList) void {
|
||||
self.lst.deinit();
|
||||
}
|
||||
|
|
@ -59,17 +82,19 @@ pub const FreqAmpBuffer = struct {
|
|||
current_tick: u64,
|
||||
freqamps: [buffer_ticks_default]*FreqAmpList,
|
||||
|
||||
pub fn init(allocator: Allocator) FreqAmpBuffer {
|
||||
pub fn init(allocator: Allocator) !FreqAmpBuffer {
|
||||
|
||||
const current_tick = 0;
|
||||
|
||||
var initial_list = FreqAmpList.init(allocator);
|
||||
//var initial_list = FreqAmpList.init(allocator);
|
||||
var initial_list = try FreqAmpList.create(allocator);
|
||||
print("{any}", .{@TypeOf(initial_list)});
|
||||
initial_list.refcount = buffer_ticks_default;
|
||||
initial_list.prnt();
|
||||
|
||||
var freqamps: [buffer_ticks_default]*FreqAmpList = undefined;
|
||||
|
||||
@memset(&freqamps, &initial_list);
|
||||
@memset(&freqamps, initial_list);
|
||||
|
||||
return .{
|
||||
.allocator = allocator,
|
||||
|
|
@ -93,7 +118,16 @@ pub const FreqAmpBuffer = struct {
|
|||
|
||||
}
|
||||
|
||||
pub fn reset(self: *FreqAmpBuffer) void {
|
||||
pub fn prnt(self: *FreqAmpBuffer) void {
|
||||
|
||||
print("CURRENT STATE:\n", .{});
|
||||
print("0: {*}\n", .{self.freqamps[0]});
|
||||
print("1: {*}\n", .{self.freqamps[1]});
|
||||
print("2: {*}\n", .{self.freqamps[2]});
|
||||
|
||||
}
|
||||
|
||||
pub fn reset(self: *FreqAmpBuffer) !void {
|
||||
|
||||
const current_index = self.index_by_tick(self.current_tick);
|
||||
var clist = self.freqamps[current_index];
|
||||
|
|
@ -106,21 +140,25 @@ pub const FreqAmpBuffer = struct {
|
|||
|
||||
clist.refcount -= 1;
|
||||
|
||||
var new_list = FreqAmpList.init(self.allocator);
|
||||
//var new_list = FreqAmpList.init(self.allocator);
|
||||
var new_list = try FreqAmpList.create(self.allocator);
|
||||
print("!! {*} !! {any}\n", .{new_list, @TypeOf(new_list)});
|
||||
|
||||
new_list.refcount += 1;
|
||||
self.freqamps[current_index] = new_list;
|
||||
new_list.prnt();
|
||||
|
||||
self.freqamps[current_index] = &new_list;
|
||||
self.freqamps[current_index].refcount += 1;
|
||||
new_list.prnt();
|
||||
}
|
||||
|
||||
pub fn setfreq(self: *FreqAmpBuffer, freq: f16, r_amp: f16) !void {
|
||||
|
||||
const current_index = self.index_by_tick(self.current_tick);
|
||||
var clist = self.freqamps[current_index];
|
||||
|
||||
print("!! {*} !!\n", .{clist});
|
||||
clist.prnt();
|
||||
// If this freq already is set, sum the r_amps
|
||||
|
||||
|
||||
for (clist.lst.items) |freqamp| {
|
||||
|
||||
if (freqamp.freq == freq) {
|
||||
|
|
@ -133,9 +171,10 @@ pub const FreqAmpBuffer = struct {
|
|||
|
||||
// Otherwise, append new freqamp
|
||||
|
||||
var fa = try self.allocator.create(FreqAmp);
|
||||
fa.freq = freq;
|
||||
fa.r_amp = r_amp;
|
||||
const fa = try FreqAmp.create(self.allocator, freq, r_amp);
|
||||
//var fa = try self.allocator.create(FreqAmp);
|
||||
//fa.freq = freq;
|
||||
//fa.r_amp = r_amp;
|
||||
|
||||
try clist.lst.append(fa);
|
||||
|
||||
|
|
@ -149,16 +188,21 @@ pub fn main() !void {
|
|||
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
|
||||
const allocator = gpa.allocator();
|
||||
|
||||
var fab = FreqAmpBuffer.init(allocator);
|
||||
var fab = try FreqAmpBuffer.init(allocator);
|
||||
defer fab.deinit();
|
||||
|
||||
try fab.reset();
|
||||
|
||||
fab.reset();
|
||||
try fab.setfreq(440.0, 0.84);
|
||||
try fab.setfreq(440.0, 0.854);
|
||||
try fab.setfreq(440, 0.854);
|
||||
try fab.setfreq(441.3, 0.8);
|
||||
|
||||
var clist = fab.current_list();
|
||||
print("RESULT\n", .{});
|
||||
clist.prnt();
|
||||
fab.prnt();
|
||||
|
||||
if (0 == 0) {
|
||||
var clist = fab.current_list();
|
||||
print("RESULT\n", .{});
|
||||
print("!! {*} !!\n", .{clist});
|
||||
clist.prnt();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue