Skip to content

Commit 4198bd3

Browse files
committed
implement simple LPF to fix Nox Archaist sampled audio
1 parent b1f2a52 commit 4198bd3

File tree

1 file changed

+27
-9
lines changed

1 file changed

+27
-9
lines changed

boards/a2n20v2/hdl/top.sv

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -480,26 +480,44 @@ module top #(
480480
// will cause the HDMI receiver to clip the audio or amplify anything such as the Mockingboard
481481
// audio that is added to it.
482482

483-
reg speaker_audio;
483+
484+
reg [7:0] speaker_audio;
484485
reg [7:0] speaker_audio_counter;
485486
reg prev_speaker_bit;
486487

487488
always_ff @(posedge clk_pixel_w) begin
488489
if (clk_audio_r) begin
489490
if (speaker_bit != prev_speaker_bit) begin
490-
speaker_audio_counter <= 8'b11111111;
491-
end else if (speaker_audio_counter != 0) begin
492-
speaker_audio_counter <= speaker_audio_counter - 8'd1;
491+
speaker_audio_counter <= 8'd255;
492+
end else begin
493+
speaker_audio_counter <= speaker_audio_counter != 0 ? speaker_audio_counter - 8'd1 : 0;
493494
end
494495
prev_speaker_bit <= speaker_bit;
495496

496-
if (prev_speaker_bit && (speaker_audio_counter != 0)) begin
497-
speaker_audio <= APPLE_SPEAKER_ENABLE | sw_apple_speaker_w;
497+
if ((speaker_audio_counter != 0) && (APPLE_SPEAKER_ENABLE | sw_apple_speaker_w)) begin
498+
if (speaker_bit) begin
499+
speaker_audio <= speaker_audio != 8'd127 ? speaker_audio + 8'd1 : 8'd127;
500+
end else begin
501+
speaker_audio <= speaker_audio != 8'd0 ? speaker_audio - 8'd1 : 8'd0;
502+
end
503+
end else begin
504+
speaker_audio <= speaker_audio != 8'd0 ? speaker_audio - 8'd1 : 8'd0;
505+
end
506+
end
507+
end
508+
509+
/*
510+
reg [7:0] speaker_audio;
511+
always_ff @(posedge clk_pixel_w) begin
512+
if (clk_audio_r) begin
513+
if (speaker_bit) begin
514+
speaker_audio <= speaker_audio != 8'd127 ? speaker_audio + 8'd1 : 8'd127;
498515
end else begin
499-
speaker_audio <= 1'b0;
516+
speaker_audio <= speaker_audio != 8'd0 ? speaker_audio - 8'd1 : 8'd0;
500517
end
501518
end
502519
end
520+
*/
503521

504522
////
505523
logic [2:0] tmds;
@@ -508,9 +526,9 @@ module top #(
508526
//wire [15:0] sample = {ssp_psg_mix_audio_o, 2'b00};
509527
reg [15:0] audio_sample_word[1:0], audio_sample_word0[1:0];
510528
always @(posedge clk_pixel_w) begin // crossing clock domain
511-
audio_sample_word0[0] <= ssp_audio_w + {mb_audio_l, 4'b00} + {speaker_audio, 13'b0};
529+
audio_sample_word0[0] <= ssp_audio_w + {mb_audio_l, 4'b00} + {speaker_audio, 8'b0};
512530
audio_sample_word[0] <= audio_sample_word0[0];
513-
audio_sample_word0[1] <= ssp_audio_w + {mb_audio_r, 4'b00} + {speaker_audio, 13'b0};
531+
audio_sample_word0[1] <= ssp_audio_w + {mb_audio_r, 4'b00} + {speaker_audio, 8'b0};
514532
audio_sample_word[1] <= audio_sample_word0[1];
515533
end
516534

0 commit comments

Comments
 (0)