Skip to content

Commit 4c1fdce

Browse files
committed
IIR filter
1 parent 019f6fa commit 4c1fdce

File tree

13 files changed

+6595
-10859
lines changed

13 files changed

+6595
-10859
lines changed

boards/a2n20v2/a2n20v2.gprj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,13 @@
3333
<File path="../../hdl/memory/a2mem_if.sv" type="file.verilog" enable="1"/>
3434
<File path="../../hdl/memory/apple_memory.sv" type="file.verilog" enable="1"/>
3535
<File path="../../hdl/mockingboard/mockingboard.sv" type="file.verilog" enable="1"/>
36+
<File path="../../hdl/sound/apple_speaker.sv" type="file.verilog" enable="1"/>
37+
<File path="../../hdl/sound/audio_out.v" type="file.verilog" enable="1"/>
3638
<File path="../../hdl/ssc/ssc_rom.vhd" type="file.vhdl" enable="1"/>
3739
<File path="../../hdl/ssc/super_serial_card.sv" type="file.verilog" enable="1"/>
3840
<File path="../../hdl/supersprite/supersprite.sv" type="file.verilog" enable="1"/>
3941
<File path="../../hdl/support/cdc.sv" type="file.verilog" enable="1"/>
42+
<File path="../../hdl/support/iir_filter.v" type="file.verilog" enable="1"/>
4043
<File path="../../hdl/support/sdpram32.sv" type="file.verilog" enable="1"/>
4144
<File path="../../hdl/support/uart_6551.v" type="file.verilog" enable="1"/>
4245
<File path="../../hdl/support/uart_rx.v" type="file.verilog" enable="1"/>

boards/a2n20v2/hdl/top.sv

Lines changed: 47 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -452,73 +452,60 @@ module top #(
452452

453453
assign irq_n_w = (mb_irq_n && vdp_irq_n && ssc_irq_n) || !IRQ_OUT_ENABLE;
454454

455-
// HDMI
455+
// Audio
456+
457+
wire speaker_audio_w;
458+
459+
apple_speaker apple_speaker (
460+
.a2bus_if(a2bus_if),
461+
.enable(APPLE_SPEAKER_ENABLE | sw_apple_speaker_w),
462+
.speaker_o(speaker_audio_w)
463+
);
464+
465+
localparam [31:0] aflt_rate = 7_056_000;
466+
localparam [39:0] acx = 4258969;
467+
localparam [7:0] acx0 = 3;
468+
localparam [7:0] acx1 = 3;
469+
localparam [7:0] acx2 = 1;
470+
localparam [23:0] acy0 = -24'd6216759;
471+
localparam [23:0] acy1 = 24'd6143386;
472+
localparam [23:0] acy2 = -24'd2023767;
456473

457474
localparam AUDIO_RATE = 44100;
458475
localparam AUDIO_BIT_WIDTH = 16;
459-
localparam AUDIO_CLK_COUNT = (CLOCK_SPEED_HZ / 2) / AUDIO_RATE;
460-
logic [$clog2(AUDIO_CLK_COUNT)-1:0] audio_counter_r;
461-
logic clk_audio_r;
462-
463-
always_ff @(posedge clk_pixel_w)
464-
begin
465-
audio_counter_r <= (audio_counter_r == AUDIO_CLK_COUNT) ? 1'd0 : audio_counter_r + 1'd1;
466-
clk_audio_r <= audio_counter_r == AUDIO_CLK_COUNT;
467-
end
468-
469-
reg speaker_bit;
470-
always @(posedge clk_logic_w or negedge system_reset_n_w) begin
471-
if (!system_reset_n_w) begin
472-
speaker_bit <= 1'b0;
473-
end else if (phi1_posedge && (a2bus_if.addr[15:0] == 16'hC030) && !a2bus_if.m2sel_n)
474-
speaker_bit <= !speaker_bit;
475-
end
476+
wire clk_audio_w;
477+
wire [15:0] audio_sample_word[1:0];
478+
audio_out #(
479+
.CLK_RATE(CLOCK_SPEED_HZ / 2),
480+
.AUDIO_RATE(AUDIO_RATE)
481+
) audio_out
482+
(
483+
.reset(~device_reset_n_w),
484+
.clk(clk_pixel_w),
485+
486+
.flt_rate(aflt_rate),
487+
.cx(acx),
488+
.cx0(acx0),
489+
.cx1(acx1),
490+
.cx2(acx2),
491+
.cy0(acy0),
492+
.cy1(acy1),
493+
.cy2(acy2),
494+
495+
.is_signed(1'b0),
496+
.core_l(ssp_audio_w + {mb_audio_l, 5'b00} + {speaker_audio_w, 13'b0}),
497+
.core_r(ssp_audio_w + {mb_audio_r, 5'b00} + {speaker_audio_w, 13'b0}),
498+
499+
.audio_clk(clk_audio_w),
500+
.audio_l(audio_sample_word[0]),
501+
.audio_r(audio_sample_word[1])
502+
);
476503

477-
// Apple intermal audio toggles a +5V signal to a speaker. We cannot simply leave a square wave
478-
// indefinitaley on the HDMI audio line, so we need to generate a pulse of a maximum length.
479-
// If we don't do this, the HDMI audio line will essentially have an amplitude offset, which
480-
// will cause the HDMI receiver to clip the audio or amplify anything such as the Mockingboard
481-
// audio that is added to it.
482-
483-
484-
reg [6:0] speaker_audio;
485-
reg [7:0] speaker_audio_counter;
486-
reg prev_speaker_bit;
487-
488-
always_ff @(posedge clk_pixel_w) begin
489-
if (clk_audio_r) begin
490-
if (speaker_bit != prev_speaker_bit) begin
491-
speaker_audio_counter <= 8'd255;
492-
end else begin
493-
speaker_audio_counter <= speaker_audio_counter != 0 ? speaker_audio_counter - 8'd1 : 0;
494-
end
495-
prev_speaker_bit <= speaker_bit;
496-
497-
if ((speaker_audio_counter != 0) && (APPLE_SPEAKER_ENABLE | sw_apple_speaker_w)) begin
498-
if (speaker_bit) begin
499-
speaker_audio <= speaker_audio != 7'd127 ? speaker_audio + 7'd1 : 7'd127;
500-
end else begin
501-
speaker_audio <= speaker_audio != 7'd0 ? speaker_audio - 7'd1 : 7'd0;
502-
end
503-
end else begin
504-
speaker_audio <= speaker_audio != 7'd0 ? speaker_audio - 7'd1 : 7'd0;
505-
end
506-
end
507-
end
504+
// HDMI
508505

509-
////
510506
logic [2:0] tmds;
511507
wire tmdsClk;
512508

513-
//wire [15:0] sample = {ssp_psg_mix_audio_o, 2'b00};
514-
reg [15:0] audio_sample_word[1:0], audio_sample_word0[1:0];
515-
always @(posedge clk_pixel_w) begin // crossing clock domain
516-
audio_sample_word0[0] <= ssp_audio_w + {mb_audio_l, 4'b00} + {2'b0, speaker_audio, 7'b0};
517-
audio_sample_word[0] <= audio_sample_word0[0];
518-
audio_sample_word0[1] <= ssp_audio_w + {mb_audio_r, 4'b00} + {2'b0, speaker_audio, 7'b0};
519-
audio_sample_word[1] <= audio_sample_word0[1];
520-
end
521-
522509
wire scanline_en = scanlines_w && hdmi_y[0];
523510

524511
hdmi #(
@@ -536,7 +523,7 @@ module top #(
536523
) hdmi (
537524
.clk_pixel_x5(clk_hdmi_w),
538525
.clk_pixel(clk_pixel_w),
539-
.clk_audio(clk_audio_r),
526+
.clk_audio(clk_audio_w),
540527
.rgb({
541528
scanline_en ? {1'b0, rgb_r_w[7:1]} : rgb_r_w,
542529
scanline_en ? {1'b0, rgb_g_w[7:1]} : rgb_g_w,

boards/a2n20v2/impl/pnr/a2n20v2.fs

Lines changed: 1566 additions & 1566 deletions
Large diffs are not rendered by default.

boards/a2n20v2/impl/pnr/a2n20v2.pin.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ <h1><a name="Message">Pin Messages</a></h1>
6262
</tr>
6363
<tr>
6464
<td class="label">Version</td>
65-
<td>V1.9.8.11 Education</td>
65+
<td>V1.9.9 Beta-4 Education</td>
6666
</tr>
6767
<tr>
6868
<td class="label">Part Number</td>
@@ -78,7 +78,7 @@ <h1><a name="Message">Pin Messages</a></h1>
7878
</tr>
7979
<tr>
8080
<td class="label">Created Time</td>
81-
<td>Tue Apr 23 22:38:30 2024
81+
<td>Thu Apr 25 15:18:35 2024
8282
</td>
8383
</tr>
8484
<tr>

0 commit comments

Comments
 (0)