一、以20M的時鐘頻率編寫的高中低音符,每個音符響一秒鐘(樂譜知識見后面文字部分介紹):
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
use ieee.std_logic_arith.all;
USE IEEE.STD_LOGIC_UNSIGNED.ALL;
ENTITY music_act IS
PORT(CLK,rst:in std_logic;
out_bit:OUT STD_LOGIC);
END music_act;
ARCHITECTURE PVJ OF music_act IS
SIGNAL time:STD_LOGIC_VECTOR(24 DOWNTO 0);
signal music21:STD_LOGIC_VECTOR(8 DOWNTO 0);
SIGNAL L1,L2,L3,L4,L5,L6,L7:STD_LOGIC_VECTOR(16 DOWNTO 0);
SIGNAL M1,M2,M3,M4,M5,M6,M7:STD_LOGIC_VECTOR(16 DOWNTO 0);
SIGNAL H1,H2,H3,H4,H5,H6,H7:STD_LOGIC_VECTOR(16 DOWNTO 0);
SIGNAL LL1,LL2,LL3,LL4,LL5,LL6,LL7,C:STD_LOGIC;
SIGNAL MM1,MM2,MM3,MM4,MM5,MM6,MM7:STD_LOGIC;
SIGNAL HH1,HH2,HH3,HH4,HH5,HH6,HH7,X0:STD_LOGIC;
BEGIN
process(clk,rst)
begin
X0<='1';
if clk'event and clk='1' then time<=time+1; --將20M頻率6分頻
if L1=76444 then L1<="00000000000000000";
else L1<=L1+1;
end if;
IF L1<38222 THEN LL1<='1';ELSE LL1<='0';END IF;
if L2=68104 then L2<="00000000000000000";
else L2<=L2+1;
end if;
IF L2<34052 THEN LL2<='1';ELSE LL2<='0';END IF;
if L3=60674 then L3<="00000000000000000";
else L3<=L3+1;
end if;
IF L3<30337 THEN LL3<='1';ELSE LL3<='0';END IF;
if L4=57268 then L4<="00000000000000000";
else L4<=L4+1;
end if;
IF L4<28634 THEN LL4<='1';ELSE LL4<='0';END IF;
if L5=51020 then L5<="00000000000000000";
else L5<=L5+1;
end if;
IF L5<25510 THEN LL5<='1';ELSE LL5<='0';END IF;
if L6=50000 then L6<="00000000000000000";
else L6<=L6+1;
end if;
IF L6<25000 THEN LL6<='1';ELSE LL6<='0';END IF;
if L7=40494 then L7<="00000000000000000";
else L7<=L7+1;
end if;
IF L7<20247 THEN LL7<='1';ELSE LL7<='0';END IF;
if M1=38222 then M1<="00000000000000000";
else M1<=M1+1;
end if;
IF M1<19111 THEN MM1<='1';ELSE MM1<='0';END IF;
if M2=34051 then M2<="00000000000000000";
else M2<=M2+1;
end if;
IF M2<17026 THEN MM2<='1';ELSE MM2<='0';END IF;
if M3=33036 then M3<="00000000000000000";
else M3<=M3+1;
end if;
IF M3<16518 THEN MM3<='1';ELSE MM3<='0';END IF;
if M4=28634 then M4<="00000000000000000";
else M4<=M4+1;
end if;
IF M4<14217 THEN MM4<='1';ELSE MM4<='0';END IF;
if M5=25510 then M5<="00000000000000000";
else M5<=M5+1;
end if;
IF M5<12755 THEN MM5<='1';ELSE MM5<='0';END IF;
if M6=25000 then M6<="00000000000000000";
else M6<=M6+1;
end if;
IF M6<12500 THEN MM6<='1';ELSE MM6<='0';END IF;
if M7=20247 then M7<="00000000000000000";
else M7<=M7+1;
end if;
IF M7<10124 THEN MM7<='1';ELSE MM7<='0';END IF;
if H1=19110 then H1<="00000000000000000";
else H1<=H1+1;
end if;
IF H1<9555 THEN HH1<='1';ELSE HH1<='0';END IF;
if H2=17025 then H2<="00000000000000000";
else H2<=H2+1;
end if;
IF H2<8513 THEN HH2<='1';ELSE HH2<='0';END IF;
if H3=15168 then H3<="00000000000000000";
else H3<=H3+1;
end if;
IF H3<7584 THEN HH3<='1';ELSE HH3<='0';END IF;
if H4=14316 then H4<="00000000000000000";
else H4<=H4+1;
end if;
IF H4<7158 THEN HH4<='1';ELSE HH4<='0';END IF;
if H5=12754 then H5<="00000000000000000";
else H5<=H5+1;
end if;
IF H5<6377 THEN HH5<='1';ELSE HH5<='0';END IF;
if H6=11764 then H6<="00000000000000000";
else H6<=H6+1;
end if;
IF H6<5882 THEN HH6<='1';ELSE HH6<='0';END IF;
if H7=10124 then H7<="00000000000000000";
else H7<=H7+1;
end if;
IF H7<5062 THEN HH7<='1';ELSE HH7<='0';END IF;
if time=2499999 then time<="0000000000000000000000000";c<='1';
else c<='0';
end if;
end if;
end process;
PROCESS(c,RST)
BEGIN
if c'event and c='1' then music21<=music21+1;
if music21=263 then music21<="000000000";
end if;
end if;--(國歌)
if music21>=0 and music21<=1 then out_bit<=LL5;END IF;
IF music21>=2 and music21<=5 then out_bit<=MM1;END IF;
IF music21>=6 and music21<=7 then out_bit<=MM1;END IF;
IF music21>=8 and music21<=10 then out_bit<=mm1;END IF;
IF music21=11 then out_bit<=MM1;END IF;
IF music21>=12 and music21<=14 then out_bit<=LL5;END IF;
IF music21=15 then out_bit<=LL6;END IF;
if music21=16 then out_bit<=LL7;END IF;
IF music21>=17 and music21<=20 then out_bit<=MM1;END IF;
IF music21>=21 and music21<=24 then out_bit<=MM1;END IF;
IF music21>=25 and music21<=26 then out_bit<=X0;END IF;
IF music21>=27 and music21<=28 then out_bit<=MM3;END IF;
IF music21>=29 and music21<=30 then out_bit<=MM1;END IF;
IF music21=31 then out_bit<=MM2;END IF;
if music21=32 then out_bit<=MM3;END IF;
IF music21>=33 and music21<=38 then out_bit<=MM5;END IF;
IF music21=39 then out_bit<=MM5;END IF;
IF music21>=40 and music21<=48 then out_bit<=MM5;END IF;
IF music21>=49 and music21<=53 then out_bit<=MM3;END IF;
IF music21>=54 and music21<=56 then out_bit<=MM1;END IF;
IF music21=57 then out_bit<=MM3;END IF;
IF music21>=58 and music21<=60 then out_bit<=MM5;END IF;
IF music21=61 then out_bit<=MM3;END IF;
IF music21>=62 and music21<=71 then out_bit<=MM2;END IF;
IF music21>=72 and music21<=75 then out_bit<=MM6;END IF;
IF music21>=76 and music21<=79 then out_bit<=MM5;END IF;
IF music21>=80 and music21<=83 then out_bit<=MM2;END IF;
IF music21>=84 and music21<=87 then out_bit<=MM3;END IF;
IF music21>=88 and music21<=89 then out_bit<=MM5;END IF;
IF music21>=90 and music21<=93 then out_bit<=MM3;END IF;
IF music21>=94 and music21<=95 then out_bit<=MM5;END IF;
IF music21>=96 and music21<=97 then out_bit<=MM3;END IF;
IF music21>=98 then out_bit<=MM2;END IF;
IF music21>=93 then out_bit<=MM3;END IF;
IF music21>=100 and music21<=102 then out_bit<=MM1;END IF;
IF music21>=103 then out_bit<=MM2;END IF;
IF music21>=104 and music21<=107 then out_bit<=MM3;END IF;
IF music21>=108 and music21<=111 then out_bit<=X0;END IF;
IF music21>=112 and music21<=114 then out_bit<=MM5;END IF;
IF music21=115 then out_bit<=LL6;END IF;
IF music21>=116 and music21<=119 then out_bit<=MM1;END IF;
IF music21>=120 and music21<=123 then out_bit<=MM3;END IF;
IF music21>=124 and music21<=127 then out_bit<=MM5;END IF;
IF music21>=128 and music21<=131 then out_bit<=MM2;END IF;
IF music21>=132 and music21<=135 then out_bit<=LL6;END IF;
IF music21>=136 and music21<=141 then out_bit<=MM2;END IF;
IF music21>=142 and music21<=143 then out_bit<=LL5;END IF;
IF music21>=144 and music21<=151 then out_bit<=MM1;END IF;
IF music21>=152 and music21<=159 then out_bit<=MM3;END IF;
IF music21>=160 and music21<=175 then out_bit<=MM5;END IF;
IF music21>=176 and music21<=178 then out_bit<=MM1;END IF;
IF music21=179 then out_bit<=MM3;END IF;
IF music21>=180 and music21<=183 then out_bit<=MM5;END IF;
IF music21>=184 and music21<=187 then out_bit<=MM6;END IF;
IF music21>=188 and music21<=191 then out_bit<=MM5;END IF;
IF music21>=192 and music21<=194 then out_bit<=MM3;END IF;
IF music21=195 then out_bit<=MM1;END IF;
IF music21>=196 and music21<=199 then out_bit<=MM5;END IF;
IF music21>=200 and music21<=201 then out_bit<=MM3;END IF;
IF music21>=202 and music21<=203 then out_bit<=X0;END IF;
IF music21>=204 and music21<=205 then out_bit<=MM1;END IF;
IF music21>=206 and music21<=207 then out_bit<=X0;END IF;
IF music21>=208 and music21<=211 then out_bit<=LL5;END IF;
IF music21>=212 and music21<=215 then out_bit<=MM1;END IF;
IF music21>=216 and music21<=218 then out_bit<=MM3;END IF;
IF music21=219 then out_bit<=MM1;END IF;
IF music21>=220 and music21<=223 then out_bit<=MM5;END IF;
IF music21>=224 and music21<=225 then out_bit<=MM3;END IF;
IF music21>=226 and music21<=227 then out_bit<=X0;END IF;
IF music21>=228 and music21<=229 then out_bit<=MM1;END IF;
IF music21>=230 and music21<=231 then out_bit<=X0;END IF;
IF music21>=232 and music21<=235 then out_bit<=LL5;END IF;
IF music21>=236 and music21<=239 then out_bit<=MM1;END IF;
IF music21>=240 and music21<=243 then out_bit<=LL5;END IF;
IF music21>=244 and music21<=247 then out_bit<=MM1;END IF;
IF music21>=248 and music21<=251 then out_bit<=LL5;END IF;
IF music21>=252 and music21<=255 then out_bit<=MM1;END IF;
IF music21>=256 and music21<=259 then out_bit<=MM1;END IF;
IF music21>=260 and music21<=263 then out_bit<=X0;END IF;
IF RST='0' THEN MUSIC21<="000000000";END IF;
END PROCESS;
end;
二、以50M的時鐘頻率編寫:
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
use ieee.std_logic_arith.all;
USE IEEE.STD_LOGIC_UNSIGNED.ALL;
ENTITY music IS
PORT(CLK,rst:in std_logic;
out_bit:OUT STD_LOGIC);
END music;
ARCHITECTURE PVJ OF music IS
SIGNAL clk_div1:STD_LOGIC_VECTOR(2 DOWNTO 0);
SIGNAL clk_div2:STD_LOGIC_VECTOR(12 DOWNTO 0);
SIGNAL cnt:STD_LOGIC_VECTOR(20 DOWNTO 0);
signal state:STD_LOGIC_VECTOR(2 DOWNTO 0);
constant duo :STD_LOGIC_VECTOR(12 DOWNTO 0):="0111011101110";--3822頻率為1308.2Hz
constant lai :STD_LOGIC_VECTOR(12 DOWNTO 0):="0110101001101";--3405頻率為1468.4Hz
constant mi :STD_LOGIC_VECTOR(12 DOWNTO 0):="0101111011010";--3034頻率為1647.9Hz
constant fa :STD_LOGIC_VECTOR(12 DOWNTO 0):="0101100110001";--2865頻率為1745.2Hz
constant suo :STD_LOGIC_VECTOR(12 DOWNTO 0):="0100111110111";--2551頻率為1960.0Hz
constant la :STD_LOGIC_VECTOR(12 DOWNTO 0):="0100011100001";--2273頻率為2199.7Hz
constant xi :STD_LOGIC_VECTOR(12 DOWNTO 0):="0011111101000";--2024頻率為2470.3Hz
constant duo1 :STD_LOGIC_VECTOR(12 DOWNTO 0):="0011101110111";--1911頻率為2616.4Hz
signal out_bit_tmp: STD_LOGIC;
BEGIN
out_bit<=out_bit_tmp;
process(clk,rst)
begin
if rst='0' then
clk_div1<="000";
elsif clk'event and clk='1' then --將20M頻率6分頻
if clk_div1=5 then clk_div1<="000";
else clk_div1<=clk_div1+1;
end if;
end if;
end process;
process(clk,rst)
begin
if rst='0' then
clk_div2<="0000000000000";
state<="000";
cnt<="000000000000000000000";--決定音符長短
out_bit_tmp<='0';
elsif clk'event and clk='1' then
if clk_div1=5 then
case state is
when "000"=> cnt<=cnt+1;
if cnt="111111111111111111111" then state<="001";
end if;
if clk_div2=duo then
clk_div2<="0000000000000";
out_bit_tmp<=not out_bit_tmp;
else
clk_div2<=clk_div2+1;
end if;
when "001"=>cnt<=cnt+1;
if cnt="111111111111111111111" then state<="010";
end if;
if clk_div2=lai then
clk_div2<="0000000000000";
out_bit_tmp<=not out_bit_tmp;
else
clk_div2<=clk_div2+1;
end if;
when "010"=>cnt<=cnt+1;
if cnt="111111111111111111111" then state<="011";
end if;
if clk_div2=mi then
clk_div2<="0000000000000";
out_bit_tmp<=not out_bit_tmp;
else
clk_div2<=clk_div2+1;
end if;
when "011"=>cnt<=cnt+1;
if cnt="111111111111111111111" then state<="100";
end if;
if clk_div2=fa then
clk_div2<="0000000000000";
out_bit_tmp<=not out_bit_tmp;
else
clk_div2<=clk_div2+1;
end if;
when "100"=> cnt<=cnt+1;
if cnt="111111111111111111111" then state<="101";
end if;
if clk_div2=suo then
clk_div2<="0000000000000";
out_bit_tmp<=not out_bit_tmp;
else
clk_div2<=clk_div2+1;
end if;
when "101"=> cnt<=cnt+1;
if cnt="111111111111111111111" then state<="110";
end if;
if clk_div2=la then
out_bit_tmp<=not out_bit_tmp;
clk_div2<="0000000000000";
else
clk_div2<=clk_div2+1;
end if;
when "110"=>cnt<=cnt+1;
if cnt="111111111111111111111" then state<="111";
end if;
if clk_div2=xi then
out_bit_tmp<=not out_bit_tmp;
clk_div2<="0000000000000";
else
clk_div2<=clk_div2+1;
end if;
when "111"=> cnt<=cnt+1;
if cnt="111111111111111111111" then state<="010";
end if;
if clk_div2=duo1 then
out_bit_tmp<=not out_bit_tmp;
clk_div2<="0000000000000";
else
clk_div2<=clk_div2+1;
end if;
when others=>null;
end case;
end if;
end if;
end process;
end;
音 樂 和 簡 譜 知 識
和語言一樣,不同民族都有過自己創立并傳承下來的記錄音樂的方式---記譜法。各民族的記譜方式各有千秋,但是目前被更廣泛使用的是五線譜和簡譜(據說簡譜是由法國思想家盧梭于1742年發明的)。
簡譜應該說是一種比較簡單易學的音樂記譜法。它的最大好處是僅用7個阿拉伯數字----1234567,就能將萬千變化的音樂曲子記錄并表示出來,并能使人很快記住而終身不忘;同時涉及其他的音樂元素也基本可以正確顯示。簡譜雖然不是出現在中國,但是好象只有在中國得到非常廣泛的傳播。
一般來說,所有音樂的構成有四個基本要素,而其中最重要的是“音的高低”和“音的長短”:
1 音的高低:任何一首曲子都是高低相間的音組成的,從鋼琴上直觀看就是越往左面的鍵盤音越低,越往右面的鍵盤音越高。
2 音的長短:除了音的高低外,還有一個重要的因素就是音的長短。音的高低和長短的標住決定了該首曲子有別于另外的曲子,因此成為構成音樂的最重要的基礎元素。
3 音的力度:音樂的力度很容易理解,也叫強度。一首音樂作品總會有一些音符的力度比教強一些,有些地方弱一些。而力度的變化是音樂作品中表達情感的因素之一。
4 音質:也可以稱音色。也就是發出音樂的樂器或人聲。同樣的旋律音高男生和女聲唱就不一樣的音色;小提琴和鋼琴的音色就不一樣。
上述四項構成了任一首樂曲的基礎元素。應該說簡譜基本可以將這些基礎性元素正確標住。