diff options
Diffstat (limited to 'src/AudioOut.vhd')
-rw-r--r-- | src/AudioOut.vhd | 72 |
1 files changed, 40 insertions, 32 deletions
diff --git a/src/AudioOut.vhd b/src/AudioOut.vhd index 715bf7f..c19a19a 100644 --- a/src/AudioOut.vhd +++ b/src/AudioOut.vhd @@ -16,10 +16,10 @@ entity AudioOut is end AudioOut; architecture Behavioral of AudioOut is - signal count: integer; - --signal bStartMusic : boolean; + signal count: integer := 0; + signal bStartMusic : boolean := false; -begin +begin process (reset, clk) variable currentThreasHold: integer; begin @@ -35,37 +35,45 @@ begin outMusic <= '0'; count <= 0; currentThreasHold := 0; - + -- start code - -- calculate amount of puls to turn on PWM - -- calculate available PWM pulses: (INPUT_CLK_KHZ/INPUT_AUDIO_KHZ) - -- multiply by target audio signal level - -- devide by available audio signal depth - currentThreasHold := ((INPUT_CLK_HZ/INPUT_AUDIO_HZ) * to_integer(unsigned(inMusicData))) / (INPUT_DEPTH); - - -- check if PWM duty cicle is high enough: currentThreasHold has to be variable otherwise first check count = 1 one to late - if (count >= currentThreasHold) then - -- no pwm output - outMusic <= '0'; - else - -- keep pwm high - outMusic <= '1'; + -- sync count to soundlevel input + if (bStartMusic = true) then + -- calculate amount of puls to turn on PWM + -- calculate available PWM pulses: (INPUT_CLK_KHZ/INPUT_AUDIO_KHZ) + -- multiply by target audio signal level + -- devide by available audio signal depth + currentThreasHold := ((INPUT_CLK_HZ/INPUT_AUDIO_HZ) * to_integer(unsigned(inMusicData))) / (INPUT_DEPTH); + + -- check if PWM duty cicle is high enough: currentThreasHold has to be variable otherwise first check count = 1 one to late + if (count >= currentThreasHold) then + -- no pwm output + outMusic <= '0'; + else + -- keep pwm high + outMusic <= '1'; + end if; + + -- + count <= count + 1; + + -- check for max level + -- if counter is >= the max amount of pulses per audio sample + if (count >= (INPUT_CLK_HZ/INPUT_AUDIO_HZ)) then + -- Next audio sample + count <= 1; + end if; end if; - - -- - count <= count + 1; - - -- check for max level - -- if counter is >= the max amount of pulses per audio sample - if (count >= (INPUT_CLK_HZ/INPUT_AUDIO_HZ)) then - -- Next audio sample - count <= 1; - end if; - - - - end if; end process; - + + process (reset) + begin + if (reset = '1') then + bStartMusic <= false; + else + -- start sound level input sync + bStartMusic <= true; + end if; + end process; end Behavioral; |