Skip to content

Commit

Permalink
mix_lut_linear[9'(mix_enhanced >> 1)] uses a linear LUT to take it to…
Browse files Browse the repository at this point in the history
… 16bit resolution
  • Loading branch information
fjpolo committed May 28, 2024
1 parent e101294 commit 687e911
Showing 1 changed file with 71 additions and 2 deletions.
73 changes: 71 additions & 2 deletions src/apu.v
Original file line number Diff line number Diff line change
Expand Up @@ -1304,6 +1304,74 @@ assign mix_lut = '{
16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000
};

logic [15:0] mix_lut_linear[512];
assign mix_lut_linear = '{
16'h0000, 16'h0096, 16'h012c, 16'h01c2, 16'h0258, 16'h2ee, 16'h0384, 16'h041a,
16'h04b0, 16'h0546, 16'h05dc, 16'h0672, 16'h708, 16'h079e, 16'h0834, 16'h08ca,
16'h0960, 16'h09f6, 16'h0a8c, 16'hb22, 16'h0bb8, 16'h0c4e, 16'h0ce4, 16'h0d7a,
16'h0e10, 16'h0ea6, 16'hf3c, 16'h0fd2, 16'h1068, 16'h10fe, 16'h1194, 16'h122a,
16'h12c0, 16'h1356, 16'h13ec, 16'h1482, 16'h1518, 16'h15ae, 16'h1644, 16'h16da,
16'h1770, 16'h1806, 16'h189c, 16'h1932, 16'h19c8, 16'h1a5e, 16'h1af4, 16'h1b8a,
16'h1c20, 16'h1cb6, 16'h1d4c, 16'h1de2, 16'h1e78, 16'h1f0e, 16'h1fa4, 16'h203a,
16'h20d0, 16'h2166, 16'h21fc, 16'h2292, 16'h2328, 16'h23be, 16'h2454, 16'h24ea,
16'h2580, 16'h2616, 16'h26ac, 16'h2742, 16'h27d8, 16'h286e, 16'h2904, 16'h299a,
16'h2a30, 16'h2ac6, 16'h2b5c, 16'h2bf2, 16'h2c88, 16'h2d1e, 16'h2db4, 16'h2e4a,
16'h2ee0, 16'h2f76, 16'h300c, 16'h30a2, 16'h3138, 16'h31ce, 16'h3264, 16'h32fa,
16'h3390, 16'h3426, 16'h34bc, 16'h3552, 16'h35e8, 16'h367e, 16'h3714, 16'h37aa,
16'h3840, 16'h38d6, 16'h396c, 16'h3a02, 16'h3a98, 16'h3b2e, 16'h3bc4, 16'h3c5a,
16'h3cf0, 16'h3d86, 16'h3e1c, 16'h3eb2, 16'h3f48, 16'h3fde, 16'h4074, 16'h410a,
16'h41a0, 16'h4236, 16'h42cc, 16'h4362, 16'h43f8, 16'h448e, 16'h4524, 16'h45ba,
16'h4650, 16'h46e6, 16'h477c, 16'h4812, 16'h48a8, 16'h493e, 16'h49d4, 16'h4a6a,
16'h4b00, 16'h4b96, 16'h4c2c, 16'h4cc2, 16'h4d58, 16'h4dee, 16'h4e84, 16'h4f1a,
16'h4fb0, 16'h5046, 16'h50dc, 16'h5172, 16'h5208, 16'h529e, 16'h5334, 16'h53ca,
16'h5460, 16'h54f6, 16'h558c, 16'h5622, 16'h56b8, 16'h574e, 16'h57e4, 16'h587a,
16'h5910, 16'h59a6, 16'h5a3c, 16'h5ad2, 16'h5b68, 16'h5bfe, 16'h5c94, 16'h5d2a,
16'h5dc0, 16'h5e56, 16'h5eec, 16'h5f82, 16'h6018, 16'h60ae, 16'h6144, 16'h61da,
16'h6270, 16'h6306, 16'h639c, 16'h6432, 16'h64c8, 16'h655e, 16'h65f4, 16'h668a,
16'h6720, 16'h67b6, 16'h684c, 16'h68e2, 16'h6978, 16'h6a0e, 16'h6aa4, 16'h6b3a,
16'h6bd0, 16'h6c66, 16'h6cfc, 16'h6d92, 16'h6e28, 16'h6ebe, 16'h6f54, 16'h6fea,
16'h7080, 16'h7116, 16'h71ac, 16'h7242, 16'h72d8, 16'h736e, 16'h7404, 16'h749a,
16'h7530, 16'h75c6, 16'h765c, 16'h76f2, 16'h7788, 16'h781e, 16'h78b4, 16'h794a,
16'h79e0, 16'h7a76, 16'h7b0c, 16'h7ba2, 16'h7c38, 16'h7cce, 16'h7d64, 16'h7dfa,
16'h7e90, 16'h7f26, 16'h7fbc, 16'h8052, 16'h80e8, 16'h817e, 16'h8214, 16'h82aa,
16'h8340, 16'h83d6, 16'h846c, 16'h8502, 16'h8598, 16'h862e, 16'h86c4, 16'h875a,
16'h87f0, 16'h8886, 16'h891c, 16'h89b2, 16'h8a48, 16'h8ade, 16'h8b74, 16'h8c0a,
16'h8ca0, 16'h8d36, 16'h8dcc, 16'h8e62, 16'h8ef8, 16'h8f8e, 16'h9024, 16'h90ba,
16'h9150, 16'h91e6, 16'h927c, 16'h9312, 16'h93a8, 16'h943e, 16'h94d4, 16'h956a,
16'h9600, 16'h9696, 16'h972c, 16'h97c2, 16'h9858, 16'h98ee, 16'h9984, 16'h9a1a,
16'h9ab0, 16'h9b46, 16'h9bdc, 16'h9c72, 16'h9d08, 16'h9d9e, 16'h9e34, 16'h9eca,
16'h9f60, 16'h9ff6, 16'ha08c, 16'ha122, 16'ha1b8, 16'ha24e, 16'ha2e4, 16'ha37a,
16'ha410, 16'ha4a6, 16'ha53c, 16'ha5d2, 16'ha668, 16'ha6fe, 16'ha794, 16'ha82a,
16'ha8c0, 16'ha956, 16'ha9ec, 16'haa82, 16'hab18, 16'habae, 16'hac44, 16'hacda,
16'had70, 16'hae06, 16'hae9c, 16'haf32, 16'hafc8, 16'hb05e, 16'h0000, 16'h0000,
16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000,
16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000,
16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000,
16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000,
16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000,
16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000,
16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000,
16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000,
16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000,
16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000,
16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000,
16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000,
16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000,
16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000,
16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000,
16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000,
16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000,
16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000,
16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000,
16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000,
16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000,
16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000,
16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000,
16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000,
16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000,
16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000, 16'h0000
};

// Square waves
wire [4:0] squares = square1 + square2;
wire [15:0] ch1 = pulse_lut[squares];
Expand All @@ -1313,14 +1381,15 @@ wire [8:0] mix_normal = 9'(tri_lut[triangle]) + 9'(noise_lut[noise]) + 9'(dmc_lu
wire [15:0] ch2 = mix_lut[mix_normal];
wire [15:0] sample_normal = ch1 + ch2;

// Linear mixer + enhanced trinagle wave
// Linear mixer + enhanced triangle wave
// dmc_lut is 8bit already, tri_lut_enhanced[triangle_enhanced] also.
// For linear mixing, noise_lut[noise] needs to be converted to 8bit
// by shifting to the left two bits, since it's 6bit wide now.
// After calculating the mix, for final mix with ch1, mix_enhanced
// needs to be shifted to the right by 1 bit, losing some minor resolution
// mix_lut[9'(mix_enhanced >> 1)] needed to take it to 16bit resolution (might need to be adapted)
wire [9:0] mix_enhanced = 10'(tri_lut_enhanced[triangle_enhanced]) + 10'(noise_lut[noise] << 2) + 10'(dmc_lut[dmc]);
wire [15:0] sample_linear = ch1 + 9'(mix_enhanced >> 1);
wire [15:0] sample_linear = ch1 + mix_lut_linear[9'(mix_enhanced >> 1)];

assign sample = (!apu_enhanced_ce ? sample_normal : sample_linear);

Expand Down

0 comments on commit 687e911

Please sign in to comment.