Skip to content

Commit

Permalink
Pull in mister changes to remove audio popping
Browse files Browse the repository at this point in the history
  • Loading branch information
budude2 committed Nov 25, 2024
1 parent 8e4b815 commit 3ed1f3c
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 21 deletions.
4 changes: 2 additions & 2 deletions pkg/gb/Cores/budude2.GB/core.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"description": "Game Boy",
"author": "budude2",
"url": "https://github.com/budude2/openfpga-GBC",
"version": "1.3.1",
"date_release": "2024-08-21"
"version": "1.3.2",
"date_release": "2024-11-25"
},
"framework": {
"target_product": "Analogue Pocket",
Expand Down
Binary file modified pkg/gb/Cores/budude2.GB/gb.rbf_r
Binary file not shown.
12 changes: 12 additions & 0 deletions pkg/gb/Cores/budude2.GB/interact.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,18 @@
"defaultval": 0,
"mask": "0xFFFFFFFB",
"value": "0x00000004"
},
{

"name": "No Audio Pops",
"id": 1006,
"type": "check",
"enabled": true,
"persist": true,
"address": "0xF2000000",
"mask": "0xFFFFFF7F",
"defaultval": "0x00000000",
"value": "0x00000080"
}
],
"messages": []
Expand Down
4 changes: 2 additions & 2 deletions pkg/gbc/Cores/budude2.GBC/core.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"description": "Game Boy Color",
"author": "budude2",
"url": "https://github.com/budude2/openfpga-GBC",
"version": "1.3.1",
"date_release": "2024-08-21"
"version": "1.3.2",
"date_release": "2024-11-25"
},
"framework": {
"target_product": "Analogue Pocket",
Expand Down
Binary file modified pkg/gbc/Cores/budude2.GBC/gbc.rbf_r
Binary file not shown.
12 changes: 12 additions & 0 deletions pkg/gbc/Cores/budude2.GBC/interact.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@
"defaultval": 0,
"mask": "0xFFFFFFFB",
"value": "0x00000004"
},
{

"name": "No Audio Pops",
"id": 1006,
"type": "check",
"enabled": true,
"persist": true,
"address": "0xF2000000",
"mask": "0xFFFFFF7F",
"defaultval": "0x00000000",
"value": "0x00000080"
}
],
"messages": []
Expand Down
6 changes: 3 additions & 3 deletions src/apf/build_id.mif
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ DATA_RADIX = HEX;
CONTENT
BEGIN

0E0 : 20240821;
0E1 : 00163950;
0E2 : 246dd444;
0E0 : 20241125;
0E1 : 00124122;
0E2 : 2d937d58;

END;
4 changes: 3 additions & 1 deletion src/core/core_top.sv
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ synch_3 #(.WIDTH(32)) s07 (cont4_key, cont4_key_s, clk_sys);
synch_3 #(.WIDTH(32)) s08 (boot_settings, boot_settings_s, clk_sys);
synch_3 #(.WIDTH(32)) s09 (run_settings, run_settings_s, clk_sys);

logic sgb_en, rumble_en, originalcolors, ff_snd_en, ff_en, sgb_border_en, gba_en;
logic sgb_en, rumble_en, originalcolors, ff_snd_en, ff_en, sgb_border_en, gba_en, audio_no_pops;
logic [1:0] tint;

always_comb begin
Expand All @@ -541,6 +541,7 @@ always_comb begin
ff_en = run_settings_s[3];
sgb_border_en = run_settings_s[4];
tint = run_settings_s[6:5];
audio_no_pops = run_settings_s[7];
end

mf_pllbase mp1
Expand Down Expand Up @@ -965,6 +966,7 @@ gb gb
// audio
.audio_l ( GB_AUDIO_L ),
.audio_r ( GB_AUDIO_R ),
.audio_no_pops ( audio_no_pops ),

// interface to the lcd
.lcd_clkena ( lcd_clkena ),
Expand Down
4 changes: 3 additions & 1 deletion src/gb/gb.v
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ module gb (

input [7:0] joystick,
input isGBC,
input real_cgb_boot,
input real_cgb_boot,
input isSGB,

// cartridge interface
Expand Down Expand Up @@ -58,6 +58,7 @@ module gb (
// audio
output [15:0] audio_l,
output [15:0] audio_r,
input audio_no_pops,

// Megaduck?
input megaduck,
Expand Down Expand Up @@ -417,6 +418,7 @@ gbc_snd audio (
.reset ( reset_ss ),

.is_gbc ( isGBC ),
.remove_pops ( audio_no_pops ),

.s1_read ( audio_rd ),
.s1_write ( audio_wr ),
Expand Down
40 changes: 28 additions & 12 deletions src/gb/gbc_snd.vhd
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ entity gbc_snd is
reset : in std_logic;

is_gbc : in std_logic;
remove_pops : in std_logic; -- 0: Accurate output, 1: Toggling DACs will not cause pops but some audio can be inaccurate.

s1_read : in std_logic;
s1_write : in std_logic;
Expand All @@ -45,6 +46,7 @@ architecture SYN of gbc_snd is
clk : in std_logic;
ce : in std_logic;
dac_en : in std_logic;
dac_invert : in std_logic;
dac_input : in std_logic_vector(3 downto 0);
dac_output : out signed(8 downto 0)
);
Expand Down Expand Up @@ -1643,13 +1645,13 @@ begin

-- Analog hardware emulation

sq1_dac : apu_dac port map (clk=>clk, ce=>ce, dac_en=>sq1_dac_en, dac_input=>sq1_wav,dac_output=>sq1_dac_out);
sq2_dac : apu_dac port map (clk=>clk, ce=>ce, dac_en=>sq2_dac_en, dac_input=>sq2_wav,dac_output=>sq2_dac_out);
wav_dac : apu_dac port map (clk=>clk, ce=>ce, dac_en=>wav_enable, dac_input=>wav_wav,dac_output=>wav_dac_out);
noi_dac : apu_dac port map (clk=>clk, ce=>ce, dac_en=>noi_dac_en, dac_input=>noi_wav,dac_output=>noi_dac_out);
sq1_dac : apu_dac port map (clk=>clk, ce=>ce, dac_en=>sq1_dac_en, dac_invert => not remove_pops, dac_input=>sq1_wav,dac_output=>sq1_dac_out);
sq2_dac : apu_dac port map (clk=>clk, ce=>ce, dac_en=>sq2_dac_en, dac_invert => not remove_pops, dac_input=>sq2_wav,dac_output=>sq2_dac_out);
wav_dac : apu_dac port map (clk=>clk, ce=>ce, dac_en=>wav_enable, dac_invert => not remove_pops, dac_input=>wav_wav,dac_output=>wav_dac_out);
noi_dac : apu_dac port map (clk=>clk, ce=>ce, dac_en=>noi_dac_en, dac_invert => not remove_pops, dac_input=>noi_wav,dac_output=>noi_dac_out);


mixer : process (sq1_dac_out, sq2_dac_out, wav_dac_out, noi_dac_out, ch_map, ch_vol)
mixer : process (sq1_dac_out, sq2_dac_out, wav_dac_out, noi_dac_out, ch_map, ch_vol, remove_pops)
variable snd_left_in : signed(10 downto 0);
variable snd_right_in : signed(10 downto 0);
variable snd_tmp : signed(15 downto 0);
Expand Down Expand Up @@ -1680,10 +1682,18 @@ begin
end loop;

snd_tmp := snd_right_in * signed(("00" & ch_vol(2 downto 0)) + '1');
snd_right <= std_logic_vector(snd_tmp);
if (remove_pops = '1') then
snd_right <= std_logic_vector(shift_left(snd_tmp,1)); -- Compensate lower volume
else
snd_right <= std_logic_vector(snd_tmp);
end if;

snd_tmp := snd_left_in * signed(("00" & ch_vol(6 downto 4)) + '1');
snd_left <= std_logic_vector(snd_tmp);
snd_tmp := snd_left_in * signed(("00" & ch_vol(6 downto 4)) + '1');
if (remove_pops = '1') then
snd_left <= std_logic_vector(shift_left(snd_tmp,1));
else
snd_left <= std_logic_vector(snd_tmp);
end if;
end process;

end SYN;
Expand All @@ -1697,6 +1707,7 @@ entity apu_dac is
clk : in std_logic;
ce : in std_logic;
dac_en : in std_logic;
dac_invert : in std_logic;
dac_input : in std_logic_vector(3 downto 0);
dac_output : out signed(8 downto 0)
);
Expand All @@ -1712,10 +1723,15 @@ architecture apu_dac_arch of apu_dac is

-- Convert a DAC input code to a pseudo-analog value
function dac_out(
wav : std_logic_vector(3 downto 0)
wav : std_logic_vector(3 downto 0);
invert : std_logic
) return signed is
begin
return signed((wav xor "0111") & "00000");
if (invert = '1') then
return signed((wav xor "0111") & "00000"); -- 0xF = -256, 0x0 = 224.
else
return signed("0" & wav & "0000"); -- 0xF = 240, 0x0 = 0.
end if;
end function;
begin
dac_output <= dac_analog;
Expand All @@ -1735,11 +1751,11 @@ begin
end if;
end process timers;

process(clk, ce, dac_en, dac_input, dac_decay_timer)
process(clk, ce, dac_en, dac_invert, dac_input, dac_decay_timer)
begin
if rising_edge(clk) and ce = '1' then
if dac_en = '1' then
dac_analog <= dac_out(dac_input);
dac_analog <= dac_out(dac_input, dac_invert);
elsif dac_decay_timer = 0 then
if dac_analog < 0 then
dac_analog <= dac_analog + 1;
Expand Down

0 comments on commit 3ed1f3c

Please sign in to comment.