aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/AudioOut.vhd72
-rw-r--r--src/PlayAudio.vhd8
-rw-r--r--src/SampleOut.vhd5
3 files changed, 46 insertions, 39 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;
diff --git a/src/PlayAudio.vhd b/src/PlayAudio.vhd
index a916d3e..1af4a12 100644
--- a/src/PlayAudio.vhd
+++ b/src/PlayAudio.vhd
@@ -14,8 +14,8 @@ architecture Behavioral of PlayAudio is
generic(
INPUT_DEPTH: integer := 256;
INPUT_SAMPLE_SIZE: integer := 36984;
- INPUT_AUDIO_KHZ: integer := 44;
- INPUT_CLK_KHZ: integer := 100000
+ INPUT_AUDIO_HZ: integer := 44100;
+ INPUT_CLK_HZ: integer := 100000000
);
Port ( reset, clk : in STD_LOGIC;
inCOEData : in STD_LOGIC_VECTOR(7 downto 0);
@@ -28,8 +28,8 @@ architecture Behavioral of PlayAudio is
generic(
INPUT_DEPTH: integer := 256;
INPUT_SAMPLE_SIZE: integer := 36984;
- INPUT_AUDIO_KHZ: integer := 44;
- INPUT_CLK_KHZ: integer := 100000
+ INPUT_AUDIO_HZ: integer := 44100;
+ INPUT_CLK_HZ: integer := 100000000
);
Port ( reset, clk : in STD_LOGIC;
inMusicData : in STD_LOGIC_VECTOR(7 downto 0);
diff --git a/src/SampleOut.vhd b/src/SampleOut.vhd
index bd2d2dc..53e3f1a 100644
--- a/src/SampleOut.vhd
+++ b/src/SampleOut.vhd
@@ -25,7 +25,6 @@ begin
outCOEData <= inCOEData;
process (reset, clk)
- --variable currentThreasHold: integer;
begin
-- if reset
if (reset = '1') then
@@ -45,8 +44,8 @@ begin
count <= count + 1;
COEAddress <= COEAddress;
- -- if counter is >= the max amount of pulses per audio sample
- if (count >= INPUT_CLK_HZ/INPUT_AUDIO_HZ) then -- Next audio sample
+ -- if counter is >= the max amount of pulses paer audio sample
+ if (count >= INPUT_CLK_HZ/INPUT_AUDIO_HZ) then-- Next audio sample
count <= 0;
COEAddress <= COEAddress + 1; --todo: check timing delay
-- add + 1 becouse COEAddress is signal updated ad end of process