From de1d79e5c24e581b63dc2ea47532986cdc512aa5 Mon Sep 17 00:00:00 2001 From: Bruno Duarte Gouveia Date: Wed, 28 Nov 2018 18:10:28 +0000 Subject: [PATCH 1/4] whitespaces --- gbc_snd.vhd | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/gbc_snd.vhd b/gbc_snd.vhd index ae0f735..65b8b0a 100644 --- a/gbc_snd.vhd +++ b/gbc_snd.vhd @@ -52,21 +52,21 @@ architecture SYN of gbc_snd is signal sq1_slen : std_logic_vector(6 downto 0); -- Sq1 play length signal sq1_svol : std_logic_vector(3 downto 0); -- Sq1 initial volume - signal sq1_envsgn : std_logic; -- Sq1 envelope sign - signal sq1_envper : std_logic_vector(2 downto 0); -- Sq1 envelope period - signal sq1_freq : std_logic_vector(10 downto 0); -- Sq1 frequency - signal sq1_trigger : std_logic; -- Sq1 trigger play note - signal sq1_lenchk : std_logic; -- Sq1 length check enable - signal sq1_len_en_change : std_logic; -- Sq1 length off -> on + signal sq1_envsgn : std_logic; -- Sq1 envelope sign + signal sq1_envper : std_logic_vector(3 downto 0); -- Sq1 envelope period + signal sq1_freq : std_logic_vector(10 downto 0); -- Sq1 frequency + signal sq1_trigger : std_logic; -- Sq1 trigger play note + signal sq1_lenchk : std_logic; -- Sq1 length check enable + signal sq1_len_en_change : std_logic; -- Sq1 length off -> on - signal sq1_fr2 : std_logic_vector(10 downto 0); -- Sq1 frequency (shadow copy) + signal sq1_fr2 : std_logic_vector(10 downto 0); -- Sq1 frequency (shadow copy) signal sq1_vol : std_logic_vector(3 downto 0); -- Sq1 initial volume signal sq1_volchange : std_logic; signal sq1_lenchange : std_logic; signal sq1_lenquirk : std_logic; signal sq1_freqchange : std_logic; - signal sq1_playing : std_logic; -- Sq1 channel active + signal sq1_playing : std_logic; -- Sq1 channel active signal sq1_wav : std_logic_vector(5 downto 0); -- Sq1 output waveform signal sq2_duty : std_logic_vector(1 downto 0); -- Sq2 duty cycle @@ -75,30 +75,30 @@ architecture SYN of gbc_snd is signal sq2_volchange : std_logic; signal sq2_lenchange : std_logic; signal sq2_lenquirk : std_logic; - signal sq2_envsgn : std_logic; -- Sq2 envelope sign + signal sq2_envsgn : std_logic; -- Sq2 envelope sign signal sq2_envper : std_logic_vector(2 downto 0); -- Sq2 envelope period - signal sq2_freq : std_logic_vector(10 downto 0); -- Sq2 frequency - signal sq2_trigger : std_logic; -- Sq2 trigger play note - signal sq2_lenchk : std_logic; -- Sq2 length check enable + signal sq2_freq : std_logic_vector(10 downto 0); -- Sq2 frequency + signal sq2_trigger : std_logic; -- Sq2 trigger play note + signal sq2_lenchk : std_logic; -- Sq2 length check enable - signal sq2_fr2 : std_logic_vector(10 downto 0); -- Sq2 frequency (shadow copy) + signal sq2_fr2 : std_logic_vector(10 downto 0); -- Sq2 frequency (shadow copy) signal sq2_vol : std_logic_vector(3 downto 0); -- Sq2 initial volume - signal sq2_playing : std_logic; -- Sq2 channel active + signal sq2_playing : std_logic; -- Sq2 channel active signal sq2_wav : std_logic_vector(5 downto 0); -- Sq2 output waveform - signal wav_enable : std_logic; -- Wave enable + signal wav_enable : std_logic; -- Wave enable signal wav_slen : std_logic_vector(8 downto 0); -- Wave play length signal wav_lenchange : std_logic; signal wav_lenquirk : std_logic; signal wav_volsh : std_logic_vector(1 downto 0); -- Wave volume shift - signal wav_freq : std_logic_vector(10 downto 0); -- Wave frequency - signal wav_trigger : std_logic; -- Wave trigger play note - signal wav_lenchk : std_logic; -- Wave length check enable + signal wav_freq : std_logic_vector(10 downto 0); -- Wave frequency + signal wav_trigger : std_logic; -- Wave trigger play note + signal wav_lenchk : std_logic; -- Wave length check enable - signal wav_fr2 : std_logic_vector(10 downto 0); -- Wave frequency (shadow copy) + signal wav_fr2 : std_logic_vector(10 downto 0); -- Wave frequency (shadow copy) signal wav_playing : std_logic; signal wav_wav : std_logic_vector(5 downto 0); -- Wave output waveform - signal wav_ram : wav_arr_t; -- Wave table + signal wav_ram : wav_arr_t; -- Wave table signal noi_slen : std_logic_vector(6 downto 0); signal noi_lenchange : std_logic; @@ -113,9 +113,9 @@ architecture SYN of gbc_snd is signal noi_trigger : std_logic; signal noi_lenchk : std_logic; - signal noi_fr2 : std_logic_vector(10 downto 0); -- Noise frequency (shadow copy) + signal noi_fr2 : std_logic_vector(10 downto 0); -- Noise frequency (shadow copy) signal noi_vol : std_logic_vector(3 downto 0); -- Noise initial volume - signal noi_playing : std_logic; -- Noise channel active + signal noi_playing : std_logic; -- Noise channel active signal noi_wav : std_logic_vector(5 downto 0); -- Noise output waveform signal ch_map : std_logic_vector(7 downto 0); From 6f975ae3b3328d09c2941bf184d1ae11ec17490e Mon Sep 17 00:00:00 2001 From: Bruno Gouveia Date: Thu, 29 Nov 2018 22:14:42 +0000 Subject: [PATCH 2/4] SOUND: refactored and changed envelope counter to count up --- gbc_snd.vhd | 125 ++++++++++++++++++++++++++++++++++------------------ 1 file changed, 82 insertions(+), 43 deletions(-) diff --git a/gbc_snd.vhd b/gbc_snd.vhd index 65b8b0a..cdbb055 100644 --- a/gbc_snd.vhd +++ b/gbc_snd.vhd @@ -53,7 +53,7 @@ architecture SYN of gbc_snd is signal sq1_svol : std_logic_vector(3 downto 0); -- Sq1 initial volume signal sq1_envsgn : std_logic; -- Sq1 envelope sign - signal sq1_envper : std_logic_vector(3 downto 0); -- Sq1 envelope period + signal sq1_envper : std_logic_vector(2 downto 0); -- Sq1 envelope period signal sq1_freq : std_logic_vector(10 downto 0); -- Sq1 frequency signal sq1_trigger : std_logic; -- Sq1 trigger play note signal sq1_lenchk : std_logic; -- Sq1 length check enable @@ -531,7 +531,7 @@ begin variable sq1_fcnt : unsigned(10 downto 0); variable sq1_phase : integer range 0 to 7; variable sq1_len : std_logic_vector(6 downto 0); - variable sq1_envcnt : std_logic_vector(2 downto 0); -- Sq1 envelope timer count + variable sq1_envcnt : std_logic_vector(3 downto 0); -- Sq1 envelope timer count variable sq1_swcnt : std_logic_vector(3 downto 0); -- Sq1 sweep timer count variable sq1_swoffs : unsigned(11 downto 0); variable sq1_swfr : unsigned(11 downto 0); @@ -544,7 +544,7 @@ begin variable sq2_fcnt : unsigned(10 downto 0); variable sq2_phase : integer range 0 to 7; variable sq2_len : std_logic_vector(6 downto 0); - variable sq2_envcnt : std_logic_vector(2 downto 0); -- Sq2 envelope timer count + variable sq2_envcnt : std_logic_vector(3 downto 0); -- Sq2 envelope timer count variable sq2_out : std_logic; variable wav_fcnt : unsigned(10 downto 0); @@ -558,7 +558,7 @@ begin variable noi_fcnt : unsigned(10 downto 0); variable noi_lfsr : unsigned(14 downto 0); -- 15 bits variable noi_len : std_logic_vector(6 downto 0); - variable noi_envcnt : std_logic_vector(2 downto 0); -- Noise envelope timer count + variable noi_envcnt : std_logic_vector(3 downto 0); -- Noise envelope timer count variable noi_out : std_logic; variable noi_xor : std_logic; @@ -572,7 +572,7 @@ begin sq1_phase := 0; sq1_len := (others => '0'); sq1_vol <= "0000"; - sq1_envcnt := "000"; + sq1_envcnt := "0000"; sq1_swcnt := "0000"; sq1_swoffs := (others => '0'); sq1_swfr := (others => '0'); @@ -584,7 +584,7 @@ begin sq2_phase := 0; sq2_len := (others => '0'); sq2_vol <= "0000"; - sq2_envcnt := "000"; + sq2_envcnt := "0000"; sq2_out := '0'; wav_playing <= '0'; @@ -599,7 +599,7 @@ begin noi_lfsr := (others => '1'); noi_len := (others => '0'); noi_vol <= "0000"; - noi_envcnt := "000"; + noi_envcnt := "0000"; noi_out := '0'; sweep_calculate:= false; sweep_update := false; @@ -766,22 +766,29 @@ begin if sq1_playing = '1' then -- Envelope counter - if en_env then - if sq1_envper /= "000" then - sq1_envcnt := std_logic_vector(unsigned(sq1_envcnt) + to_unsigned(1, sq1_envcnt'length)); - if sq1_envcnt = sq1_envper then + if en_env and sq1_envper /= "000" then + + sq1_envcnt := std_logic_vector(unsigned(sq1_envcnt) - 1); -- decrement counter + + if sq1_envcnt = 0 then if sq1_envsgn = '1' then - if sq1_vol /= "1111" then - sq1_vol <= std_logic_vector(unsigned(sq1_vol) + to_unsigned(1, sq1_vol'length)); + if sq1_vol /= "1111" then -- sq1_vol < 15 + sq1_vol <= std_logic_vector(unsigned(sq1_vol) + 1); end if; else - if sq1_vol /= "0000" then - sq1_vol <= std_logic_vector(unsigned(sq1_vol) - to_unsigned(1, sq1_vol'length)); + if sq1_vol /= "0000" then -- sq1_vol > + sq1_vol <= std_logic_vector(unsigned(sq1_vol) - 1); end if; end if; - sq1_envcnt := "000"; + + -- reload counter with period + if sq1_envper = "000" then + sq1_envcnt := "1000"; -- set to 8 + else + sq1_envcnt := '0' & sq1_envper; -- set to period + end if; + end if; - end if; end if; -- Check for end of playing conditions @@ -831,7 +838,13 @@ begin if not (sq1_svol = "00000" and sq1_envsgn = '0') then -- dac enabled sq1_playing <= '1'; end if; - sq1_envcnt := "000"; + + -- reload envelope counter with period + if sq1_envper = "000" then + sq1_envcnt := "1000"; -- set to 8 + else + sq1_envcnt := '0' & sq1_envper; -- set to period + end if; sq1_phase := 0; if sq1_len = 0 then -- trigger quirks @@ -855,30 +868,36 @@ begin if sq2_playing = '1' then -- Envelope counter - if en_env then - if sq2_envper /= "000" then - sq2_envcnt := std_logic_vector(unsigned(sq2_envcnt) + to_unsigned(1, sq2_envcnt'length)); - if sq2_envcnt = sq2_envper then + if en_env and sq2_envper /= "000" then + + sq2_envcnt := std_logic_vector(unsigned(sq2_envcnt) - 1); -- decrement counter + + if sq2_envcnt = 0 then if sq2_envsgn = '1' then - if sq2_vol /= "1111" then - sq2_vol <= std_logic_vector(unsigned(sq2_vol) + to_unsigned(1, sq2_vol'length)); + if sq2_vol /= "1111" then -- sq2_vol < 15 + sq2_vol <= std_logic_vector(unsigned(sq2_vol) + 1); end if; else - if sq2_vol /= "0000" then - sq2_vol <= std_logic_vector(unsigned(sq2_vol) - to_unsigned(1, sq2_vol'length)); + if sq2_vol /= "0000" then -- sq2_vol > 0 + sq2_vol <= std_logic_vector(unsigned(sq2_vol) - 1); end if; end if; - sq2_envcnt := "000"; + + -- reload counter with period + if sq2_envper = "000" then + sq2_envcnt := "1000"; -- set to 8 + else + sq2_envcnt := '0' & sq2_envper; -- set to period + end if; end if; - end if; end if; -- Check for end of playing conditions - -- if sq2_vol = X"0" -- Volume == 0 + -- if sq2_vol = X"0" -- Volume == 0 if sq2_lenchk = '1' and sq2_len = 0 -- Play length timer overrun then sq2_playing <= '0'; - sq2_envcnt := "000"; + sq2_envcnt := "0000"; --sq2_wav <= "000000"; end if; end if; @@ -901,7 +920,14 @@ begin if not (sq2_svol = "00000" and sq2_envsgn = '0') then -- dac enabled sq2_playing <= '1'; end if; - sq2_envcnt := "000"; + + -- reload envelope counter with period + if sq2_envper = "000" then + sq2_envcnt := "1000"; -- set to 8 + else + sq2_envcnt := '0' & sq2_envper; -- set to period + end if; + sq2_phase := 0; if sq2_len = 0 then -- trigger quirks if sq2_lenchk = '1' and en_len_r then @@ -924,29 +950,35 @@ begin if noi_playing = '1' then -- Envelope counter - if en_env then - if noi_envper /= "000" then - noi_envcnt := std_logic_vector(unsigned(noi_envcnt) + to_unsigned(1, noi_envcnt'length)); - if noi_envcnt = noi_envper then + if en_env and noi_envper /= "000" then + + noi_envcnt := std_logic_vector(unsigned(noi_envcnt) - 1); -- decrement counter + + if noi_envcnt = 0 then if noi_envsgn = '1' then - if noi_vol /= "1111" then - noi_vol <= std_logic_vector(unsigned(noi_vol) + to_unsigned(1, noi_vol'length)); + if noi_vol /= "1111" then -- noi_vol < 15 + noi_vol <= std_logic_vector(unsigned(noi_vol) + 1); end if; else - if noi_vol /= "0000" then - noi_vol <= std_logic_vector(unsigned(noi_vol) - to_unsigned(1, noi_vol'length)); + if noi_vol /= "0000" then -- noi_vol > 0 + noi_vol <= std_logic_vector(unsigned(noi_vol) - 1); end if; end if; - noi_envcnt := "000"; + + -- reload counter with period + if noi_envper = "000" then + noi_envcnt := "1000"; -- set to 8 + else + noi_envcnt := '0' & noi_envper; -- set to period + end if; end if; - end if; end if; -- Check for end of playing conditions if noi_lenchk = '1' and noi_len = 0 -- Play length timer overrun then noi_playing <= '0'; - noi_envcnt := "000"; + noi_envcnt := "0000"; --sq2_wav <= "000000"; end if; end if; @@ -991,7 +1023,14 @@ begin noi_fr2 <= std_logic_vector(noi_freq); noi_fcnt := noi_freq; - noi_envcnt := "000"; + + -- reload envelope counter with period + if noi_envper = "000" then + noi_envcnt := "1000"; -- set to 8 + else + noi_envcnt := '0' & noi_envper; -- set to period + end if; + if not (noi_svol = "00000" and noi_envsgn = '0') then -- dac enabled noi_playing <= '1'; end if; From 79b417927220c794867cc26761eda9f8a8cd3f15 Mon Sep 17 00:00:00 2001 From: Bruno Gouveia Date: Thu, 29 Nov 2018 22:18:02 +0000 Subject: [PATCH 3/4] SOUND:removed non exisitng shadow freq reg. for sq2 and use normal registers instead for sq1 and sq2 --- gbc_snd.vhd | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/gbc_snd.vhd b/gbc_snd.vhd index cdbb055..898114c 100644 --- a/gbc_snd.vhd +++ b/gbc_snd.vhd @@ -81,7 +81,7 @@ architecture SYN of gbc_snd is signal sq2_trigger : std_logic; -- Sq2 trigger play note signal sq2_lenchk : std_logic; -- Sq2 length check enable - signal sq2_fr2 : std_logic_vector(10 downto 0); -- Sq2 frequency (shadow copy) + -- signal sq2_fr2 : std_logic_vector(10 downto 0); -- Sq2 frequency (shadow copy) signal sq2_vol : std_logic_vector(3 downto 0); -- Sq2 initial volume signal sq2_playing : std_logic; -- Sq2 channel active signal sq2_wav : std_logic_vector(5 downto 0); -- Sq2 output waveform @@ -579,7 +579,7 @@ begin sq1_out := '0'; sq2_playing <= '0'; - sq2_fr2 <= (others => '0'); + -- sq2_fr2 <= (others => '0'); sq2_fcnt := (others => '0'); sq2_phase := 0; sq2_len := (others => '0'); @@ -617,7 +617,7 @@ begin else sq1_phase := 0; end if; - sq1_fcnt := unsigned(sq1_fr2); + sq1_fcnt := unsigned(sq1_freq); else sq1_fcnt := acc_fcnt(sq1_fcnt'range); end if; @@ -632,7 +632,7 @@ begin else sq2_phase := 0; end if; - sq2_fcnt := unsigned(sq2_fr2); + sq2_fcnt := unsigned(sq2_freq); else sq2_fcnt := acc_fcnt(sq2_fcnt'range); end if; @@ -915,8 +915,10 @@ begin -- Check sample trigger and start playing if sq2_trigger = '1' then - sq2_fr2 <= sq2_freq; + + -- sq2_fr2 <= sq2_freq; sq2_fcnt := unsigned(sq2_freq); + if not (sq2_svol = "00000" and sq2_envsgn = '0') then -- dac enabled sq2_playing <= '1'; end if; From f6431fbfeeec85c3dc15d847b7881f91de2be1d6 Mon Sep 17 00:00:00 2001 From: Bruno Gouveia Date: Thu, 29 Nov 2018 23:30:28 +0000 Subject: [PATCH 4/4] SOUND: removed fr2 shadow register for wave channel use normal register --- gbc_snd.vhd | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/gbc_snd.vhd b/gbc_snd.vhd index 898114c..29d0e8c 100644 --- a/gbc_snd.vhd +++ b/gbc_snd.vhd @@ -81,7 +81,6 @@ architecture SYN of gbc_snd is signal sq2_trigger : std_logic; -- Sq2 trigger play note signal sq2_lenchk : std_logic; -- Sq2 length check enable - -- signal sq2_fr2 : std_logic_vector(10 downto 0); -- Sq2 frequency (shadow copy) signal sq2_vol : std_logic_vector(3 downto 0); -- Sq2 initial volume signal sq2_playing : std_logic; -- Sq2 channel active signal sq2_wav : std_logic_vector(5 downto 0); -- Sq2 output waveform @@ -95,7 +94,6 @@ architecture SYN of gbc_snd is signal wav_trigger : std_logic; -- Wave trigger play note signal wav_lenchk : std_logic; -- Wave length check enable - signal wav_fr2 : std_logic_vector(10 downto 0); -- Wave frequency (shadow copy) signal wav_playing : std_logic; signal wav_wav : std_logic_vector(5 downto 0); -- Wave output waveform signal wav_ram : wav_arr_t; -- Wave table @@ -1053,7 +1051,7 @@ begin acc_fcnt := ('0'&wav_fcnt) + to_unsigned(1, acc_fcnt'length); if acc_fcnt(acc_fcnt'high) = '1' then wav_shift := true; - wav_fcnt := unsigned(wav_fr2); + wav_fcnt := unsigned(wav_freq); else wav_fcnt := acc_fcnt(wav_fcnt'range); end if; @@ -1093,7 +1091,6 @@ begin -- Check sample trigger and start playing if wav_trigger = '1' then - wav_fr2 <= wav_freq; wav_fcnt := unsigned(wav_freq); wav_playing <= '1'; if wav_len = 0 then -- trigger quirks