帮忙做个基于Vhdl的音乐播放器,eda的,要求是有开始和结束,能选歌,两首就够了

帮忙做个基于Vhdl的音乐播放器,eda的,要求是有开始和结束,能选歌,两首就够了,第1张

LIBRARY IEEE

USE IEEE.STD_LOGIC_1164.ALL

ENTITY songer IS

PORT(clk12mhz:IN STD_LOGIC

clk8hz,done,COUT:IN STD_LOGIC

code1:OUT STD_LOGIC_VECTOR(3 DOWNTO 0)

HIGH1:OUT STD_LOGIC

spkout:OUT STD_LOGIC)

END songer

architecture one of songer is

COMPONENT notetabs

PORT (clk:IN STD_LOGIC

toneindex:OUT STD_LOGIC_VECTOR(3 DOWNTO 0))

END COMPONENT

COMPONENT tonetaba

PORT (done,COUT:in STD_LOGIC

index:IN STD_LOGIC_VECTOR(3 DOWNTO 0)

code:OUT STD_LOGIC_VECTOR(3 DOWNTO 0)

high:out STD_LOGIC

tone:OUT STD_LOGIC_VECTOR(10 DOWNTO 0))

END COMPONENT

COMPONENT speakera

PORT (clk:IN STD_LOGIC

done,COUT:IN STD_LOGIC

tone:IN STD_LOGIC_VECTOR(10 DOWNTO 0)

SPKS:out STD_LOGIC)

END COMPONENT

SIGNAL tone:STD_LOGIC_VECTOR(10 DOWNTO 0)

SIGNAL toneindex:STD_LOGIC_VECTOR(3 DOWNTO 0)

BEGIN

U1:notetabs PORT MAP(clk=>clk8hz,toneindex=>toneindex)

u2:tonetaba PORT MAP(index=>toneindex,tone=>tone,code=>code1,high=>high1,DONE=>DONE,cout=>cout)

u3:speakera PORT MAP(clk=>clk12mhz,done=>done,COUT=>COUT,tone=>tone,spks=>spkout)

END

LIBRARY IEEE

USE IEEE.STD_LOGIC_1164.ALL

USE IEEE.STD_LOGIC_UNSIGNED.ALL

ENTITY notetabs IS

PORT(clk:IN STD_LOGIC

toneindex:OUT STD_LOGIC_VECTOR(3 DOWNTO 0))

END

ARCHITECTURE one OF notetabs IS

COMPONENT music

PORT(address:IN STD_LOGIC_VECTOR(7 DOWNTO 0)

clock:IN STD_LOGIC

Q:OUT STD_LOGIC_VECTOR(3 DOWNTO 0))

END COMPONENT

SIGNAL counter:STD_LOGIC_VECTOR(7 DOWNTO 0)

BEGIN

CNT8:PROCESS(clk,counter)

begin

IF counter=138 THEN counter<="00000000"

ELSIF(clk'EVENT AND clk='1')then

counter<=counter+1

END IF

END process

END

LIBRARY IEEE

USE IEEE.STD_LOGIC_1164.ALL

ENTITY tonetaba IS

PORT(done,COUT:in STD_LOGIC

index:IN STD_LOGIC_VECTOR(3 DOWNTO 0)

code:OUT STD_LOGIC_VECTOR(3 DOWNTO 0)

HIGH:OUT STD_LOGIC

tone:OUT STD_LOGIC_VECTOR(10 DOWNTO 0))

END tonetaba

architecture one OF tonetaba IS

BEGIN

search:PROCESS(index)

BEGIN

if done='1'OR COUT='1' THEN

CASE index IS

WHEN"0000"=>tone<="11111111111"code<="0000"high<='0'

WHEN"0001"=>tone<="01100000101"code<="0001"high<='0'

WHEN"0010"=>tone<="01110010000"code<="0010"high<='0'

WHEN"0011"=>tone<="10000001100"code<="0011"high<='0'

WHEN"0101"=>tone<="10010101101"code<="0101"high<='0'

WHEN"0110"=>tone<="10100001010"code<="0110"high<='0'

WHEN"0111"=>tone<="10101011100"code<="0111"high<='0'

WHEN"1000"=>tone<="10110000010"code<="0001"high<='1'

WHEN"1001"=>tone<="10111001000"code<="0010"high<='1'

WHEN"1010"=>tone<="11000000110"code<="0011"high<='1'

WHEN"1100"=>tone<="11001010110"code<="0101"high<='1'

WHEN"1101"=>tone<="11010000100"code<="0110"high<='1'

WHEN"1111"=>tone<="11011000000"code<="0001"high<='1'

WHEN OTHERS=>NULL

END CASE

END IF

END PROCESS

END ONE

-数控频率转换器

LIBRARY IEEE

USE IEEE.STD_LOGIC_1164.ALL

USE IEEE.STD_LOGIC_UNSIGNED.ALL

ENTITY speakera IS

PORT( clk:IN STD_LOGIC

done,COUT:IN STD_LOGIC

tone:IN STD_LOGIC_VECTOR(10 DOWNTO 0)

SPKS:OUT STD_LOGIC)

END speakera

ARCHITECTURE one OF speakera is

SIGNAL preclk,fullspks:STD_LOGIC

BEGIN

divideclk:process(clk)

VARIABLE count4:STD_LOGIC_VECTOR(3 DOWNTO 0)

BEGIN

IF count4>11 THEN

preclk<='1'

count4:="0000"

ELSIF clk'EVENT AND clk='1' THEN

count4:=count4+1preclk<='0'

END IF

END PROCESS

genspks:PROCESS(preclk,tone)

VARIABLE count11:STD_LOGIC_VECTOR(10 DOWNTO 0)

BEGIN

IF done='1'OR COUT='1' THEN

IF preclk'EVENT AND preclk='1' THEN

IF count11=16#7FF# THEN count11:=tone

fullspks<='1'

ELSE

count11:=count11+1

fullspks<='0'

END IF

END IF

END IF

END PROCESS

delayspks: PROCESS(fullspks)

VARIABLE count2:STD_LOGIC

BEGIN

IF fullspks'EVENT AND fullspks='1' then

count2:=NOT count2

if count2='1' THEN spks<='1'

ELSE

spks<='0'

END IF

END IF

END PROCESS

END ONE

然后自己定制一个RAM

-------------------------------------

-- Title: Music of Liangzhu --

-- Data: 2009-11-17 --

-------------------------------------

library ieee

use ieee.std_logic_1164.all

use ieee.std_logic_arith.all

use ieee.std_logic_unsigned.all

--------------------------------------------------------------------

entity music is

port( inclk : in std_logic --Clock Signal

spk : buffer std_logic) --speaker driver

end music

--------------------------------------------------------------------

architecture behave of music is

signal tone: std_logic_vector(10 downto 0)

signal tone_count : std_logic_vector(10 downto 0)

signal tone_index : integer range 0 to 15

signal clk10_count : std_logic_vector(17 downto 0)

signal time: integer range 0 to 150

signal clk : std_logic

signal clk10 : std_logic

begin

PROCESS(inclk) --generate 2Mhz clock signal

variable cnt1 : INTEGER RANGE 0 TO 29

BEGIN

IF inclk='1' AND inclk'event THEN

IF cnt1=29 THEN cnt1:=0

ELSE

IF cnt1<20 THEN clk<='1'

ELSE clk<='0'

END IF

cnt1:=cnt1+1

END IF

END IF

END PROCESS

process(clk) --generate 10hz clock signal

begin

if(clk'event and clk='1') then

clk10_count<=clk10_count+1

if(clk10_count=16#3fff#) then

clk10<=not clk10

end if

end if

end process

process(clk10)

begin

if(clk10'event and clk10='1') then

if(time=150) then

time<=0

else

time<=time+1

end if

end if

end process

process(clk10)

begin

if(clk10'event and clk10='1') then

case time is

when 0=>tone_index<=3

when 1=>tone_index<=3

when 2=>tone_index<=3

when 3=>tone_index<=3--

when 4=>tone_index<=5

when 5=>tone_index<=5

when 6=>tone_index<=5

when 7=>tone_index<=6--

when 8=>tone_index<=8

when 9=>tone_index<=8

when 10=>tone_index<=8

when 11=>tone_index<=9--

when 12=>tone_index<=6

when 13=>tone_index<=8

when 14=>tone_index<=5

when 15=>tone_index<=5--

when 16=>tone_index<=12

when 17=>tone_index<=12

when 18=>tone_index<=12

when 19=>tone_index<=15--

when 20=>tone_index<=13

when 21=>tone_index<=12

when 22=>tone_index<=10

when 23=>tone_index<=12--

when 24=>tone_index<=9

when 25=>tone_index<=9

when 26=>tone_index<=9

when 27=>tone_index<=9--

when 28=>tone_index<=9

when 29=>tone_index<=9

when 30=>tone_index<=0

when 31=>tone_index<=0--

when 32=>tone_index<=9

when 33=>tone_index<=9

when 34=>tone_index<=9

when 35=>tone_index<=10--

when 36=>tone_index<=7

when 37=>tone_index<=7

when 38=>tone_index<=6

when 39=>tone_index<=6--

when 40=>tone_index<=5

when 41=>tone_index<=5

when 42=>tone_index<=5

when 43=>tone_index<=6--

when 44=>tone_index<=8

when 45=>tone_index<=8

when 46=>tone_index<=9

when 47=>tone_index<=9--

when 48=>tone_index<=3

when 49=>tone_index<=3

when 50=>tone_index<=8

when 51=>tone_index<=8--

when 52=>tone_index<=6

when 53=>tone_index<=5

when 54=>tone_index<=6

when 55=>tone_index<=8--

when 56=>tone_index<=5

when 57=>tone_index<=5

when 58=>tone_index<=5

when 59=>tone_index<=5--

when 60=>tone_index<=5

when 61=>tone_index<=5

when 62=>tone_index<=0

when 63=>tone_index<=0----

when 64=>tone_index<=10

when 65=>tone_index<=10

when 66=>tone_index<=10

when 67=>tone_index<=12--

when 68=>tone_index<=7

when 69=>tone_index<=7

when 70=>tone_index<=9

when 71=>tone_index<=9--

when 72=>tone_index<=6

when 73=>tone_index<=8

when 74=>tone_index<=5

when 75=>tone_index<=5--

when 76=>tone_index<=5

when 77=>tone_index<=5

when 78=>tone_index<=5

when 79=>tone_index<=5--

when 80=>tone_index<=5

when 81=>tone_index<=0

when 82=>tone_index<=0

when 83=>tone_index<=3--

when 84=>tone_index<=5

when 85=>tone_index<=3

when 86=>tone_index<=5

when 87=>tone_index<=5--

when 88=>tone_index<=6

when 89=>tone_index<=7

when 90=>tone_index<=9

when 91=>tone_index<=6--

when 92=>tone_index<=6

when 93=>tone_index<=6

when 94=>tone_index<=6

when 95=>tone_index<=6--

when 96=>tone_index<=6

when 97=>tone_index<=5

when 98=>tone_index<=6

when 99=>tone_index<=8--

when 100=>tone_index<=8

when 101=>tone_index<=8

when 102=>tone_index<=9

when 103=>tone_index<=12--

when 104=>tone_index<=12

when 105=>tone_index<=12

when 106=>tone_index<=10

when 107=>tone_index<=9--

when 108=>tone_index<=9

when 109=>tone_index<=10

when 110=>tone_index<=9

when 111=>tone_index<=8--

when 112=>tone_index<=8

when 113=>tone_index<=6

when 114=>tone_index<=5

when 115=>tone_index<=3--

when 116=>tone_index<=3

when 117=>tone_index<=3

when 118=>tone_index<=3

when 119=>tone_index<=8--

when 120=>tone_index<=8

when 121=>tone_index<=8

when 122=>tone_index<=8

when 123=>tone_index<=6--

when 124=>tone_index<=8

when 125=>tone_index<=6

when 126=>tone_index<=5

when 127=>tone_index<=3--

when 128=>tone_index<=5

when 129=>tone_index<=6

when 130=>tone_index<=8

when 131=>tone_index<=5--

when 132=>tone_index<=5

when 133=>tone_index<=5

when 134=>tone_index<=5

when 135=>tone_index<=5--

when 136=>tone_index<=5

when 137=>tone_index<=5

when 138=>tone_index<=0

when 139=>tone_index<=0--

when others=>tone_index<=0

end case

end if

end process

process(tone_index)

begin

case tone_index is

when 0=>tone<="11111111111" --no output

when 1=>tone<="01100000101" --773

when 2=>tone<="01110010000" --912

when 3=>tone<="10000001100" --1036

when 5=>tone<="10010101101" --1197

when 6=>tone<="10100001010" --1290

when 7=>tone<="10101011100" --1372

when 8=>tone<="10110000010" --1410

when 9=>tone<="10111001000" --1480

when 10=>tone<="11000000110" --1542

when 12=>tone<="11001010110" --1622

when 13=>tone<="11010000100" --1668

when 15=>tone<="11011000000" --1728

when others=>tone<="11111111111"--others:no output

end case

end process

process(clk) --control the frequence of the speaker

begin

if(clk'event and clk='1') then

if(tone_count=16#7ff#) then

tone_count<=tone

if(tone<2047) then

spk<=not spk

end if

else

tone_count<=tone_count+1

end if

end if

end process

end behave

---------------------------

很简单的单音播放,《梁祝

其他播放程序原理类似,很好改。当然,要播放flash里面的音乐(.wav文件等)那就很麻烦了,如果是altera就需要用NIOS2来开发软件部分

---------------------------

没有分也没关系,互相帮助嘛~


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/7858236.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-10
下一篇 2023-04-10

发表评论

登录后才能评论

评论列表(0条)

保存