⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 huffman.vhd

📁 MP3的VHDL源码
💻 VHD
📖 第 1 页 / 共 3 页
字号:
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_unsigned.all;
use IEEE.std_logic_arith.all;
use work.all_types.all;			
use work.huffman_types.all;  -- this file contains all the tables of huffman decoders

entity huffman is
  port( clk   : in  std_logic;      -- input clock signal
        rst   : in  std_logic;      -- reset signal ('1' = reset)
        start : in  std_logic;      -- start='1' means that this component is activated
        done  : out std_logic;      -- produce a done signal when process is finished
        gr    : in  std_logic;      -- granule ('0'=granule0, '1'=granule1)
        bin   : in  std_logic_vector(7 downto 0);    -- input main data for huffman
        addr  : out std_logic_vector(9 downto 0);    -- address for main data
        dout  :  out std_logic_vector(31 downto 0);   -- data to memory
	      memc  : out mem_control_type;  -- memeory controll signal
	      sco   : out scalefac_type;  -- output scale factors 
        frm   : in  frame_type      -- contains all header and side information for the current frame
      );
end;

architecture behavioral of huffman is

  type state_type is 
  ( IDLE1,IDLE2,IDLE3,READ,READ1,READ2,READREADY,SCALE,HUFFMAN,HUFFBIGVALUE,TABLELOOKUP1,HUFFCOUNT1,TABLELOOKUP2,HUFFEND,DATAREADY,READY );
  signal cs,ns:state_type;
  
  type is_type is array (0 to 575) of integer;
  signal isg : is_type;

  signal addrcount1:std_logic_vector(9 downto 0);
  signal valuebuffer : std_logic_vector(0 to 8191 );
 
begin

  process(cs, frm, gr, start)
   
    variable scalefac : integer;
    variable count : integer ;
    variable memaddrcount : std_logic_vector(9 downto 0);
    variable scout : scalefac_type;
    variable bitpos:std_logic_vector(12 downto 0);
    variable region1start,region2start,bigvalues,count1s,start_bit1,start_bit2,start_bit,tempbit: integer;
    variable line,line1,region,old_region : integer;
    variable u,w,x,y,linbits:integer;
    variable level,level1,value,temp,templevel:integer;
    variable tindex:integer range 0 to 33;
    variable tempvector : std_logic_vector(7 downto 0);
    variable tempvector1 : std_logic_vector(3 downto 0);
    variable slenval0,slenval1:integer;
    variable tempval,tempdata,temphuff,temphuff1,temppos:integer;
    variable tempcount1:std_logic;

  begin

    case cs is
      when IDLE1   =>  
                       addrcount1 <= (others =>'0');
		       ns<=IDLE2;
      when IDLE2   =>  
                       done <= '0';
                       count :=0;
		       line :=0;
		       line1 :=0;
		       bigvalues:=0;
		       count1s:=0;
		       start_bit:=0;
		       linbits:=0;
		       tempvector1:=(others =>'0');
		       tempvector:=(others =>'0');
		       tindex:=0;
		       temp:=0;
		       value:=0;
		       isg<=(others=>0);   
         	       ns<=IDLE3;
      when IDLE3  => 
                     if (start = '1') then
		         memaddrcount :=(others =>'0');
                     end if;
                     ns<=READ;
      when READ   => 
                    
                     addr <= addrcount1;
                     ns<=READ1;
                          
      when READ1=>
		    ns<=READREADY;
           
      when READREADY => 
      			valuebuffer(count to count+7 ) <= bin;
      			count := count +8;
      		        addrcount1 <= addrcount1 +1;
      		       
                        if count=8192 then
                           if gr='0' then
			      bitpos:=conv_std_logic_vector((conv_integer(frm.sideinfo.main_data)*8),13);
         	           else
		              start_bit2:=conv_integer(bitpos);
                       	   end if;
                              ns<= SCALE;
                        else
                            ns<= READ;
                        end if;
                  
      when SCALE  => scalefac := conv_integer(frm.sideinfo.scalefac_compress);
                  
                     slenval0:= slen(0,scalefac);
                     slenval1:= slen(1,scalefac);
                     if (frm.sideinfo.blocksplit_flag = '1') and (frm.sideinfo.block_type = "10") then
        			if (frm.sideinfo.switch_point = '1' ) then
	    		   for sfb in 0 to 7 loop 
	      		       if 8191-conv_integer(bitpos)+1>=slenval0 then
	      		       	  scout.scalefac_l(sfb)	:= conv_std_logic_vector(conv_integer(valuebuffer(conv_integer(bitpos) to conv_integer(bitpos)+slenval0-1)),4);
		     	          if 8191-conv_integer(bitpos)+1=slenval0 then
		     	             bitpos:=(others=>'0');
		     	             tempcount1:='1';
		     	          else
		     	             bitpos := conv_std_logic_vector((conv_integer(bitpos) + slenval0),13);
		     	          end if;
		     	       else
	                          temppos:=conv_integer(bitpos);
	                          tempval:=8191-temppos+1;	
	                              
		     	          scout.scalefac_l(sfb)	:=
		     	          conv_std_logic_vector(conv_integer(valuebuffer(temppos to 8191)& valuebuffer(0 to slenval0-tempval-1)),4);
		     	          bitpos:=(others=>'0'); 
	                          tempcount1:='1';    	   
		     	          bitpos := conv_std_logic_vector((slenval0-tempval),13);
		     	       end if;
	
		     	   end loop;   
		     	   for sfb in 3 to 11 loop
		       	       for window in 0 to 2 loop 
			          if (sfb < 6) then 
			              if 8191-conv_integer(bitpos)+1>=slenval0 then
	      		       	  	scout.scalefac_s(sfb)(window):= conv_std_logic_vector(conv_integer(valuebuffer(conv_integer(bitpos) to conv_integer(bitpos)+slenval0-1)),4);
		     	          		if 8191-conv_integer(bitpos)+1=slenval0 then
		     	                   bitpos:=(others=>'0');
		     	                   tempcount1:='1';
		     	                else
		     	          		   bitpos := conv_std_logic_vector((conv_integer(bitpos) + slenval0),13);
		     	       	        end if;
		     	       	      else
	                          			   temppos:=conv_integer(bitpos);
	                                tempval:=8191-temppos+1;
	                          		   
		     	                scout.scalefac_s(sfb)(window):=
		     	                conv_std_logic_vector(conv_integer(valuebuffer(temppos to 8191)& valuebuffer(0 to slenval0-tempval-1)),4);
		     	                bitpos:=(others=>'0');
	                          		    tempcount1:='1';      	       
		     	                bitpos := conv_std_logic_vector((slenval0-tempval),13);
		     	              end if;			
			          else  
			             if 8191-conv_integer(bitpos)+1>=slenval1 then
	      		       	  	scout.scalefac_s(sfb)(window):=
	      		       	  	conv_std_logic_vector(conv_integer(valuebuffer(conv_integer(bitpos) to conv_integer(bitpos)+slenval1-1)),4);
		     	          		if 8191-conv_integer(bitpos)+1=slenval1 then
		     	             		   bitpos:=(others=>'0');
		     	                   tempcount1:='1';
		     	                else
		     	          		   bitpos := conv_std_logic_vector((conv_integer(bitpos) + slenval1),13);
		     	                end if;
		     	             else
	                          			   temppos:=conv_integer(bitpos);
	                                tempval:=8191-temppos+1;
	                          		    
		     	                scout.scalefac_s(sfb)(window):=
		     	                conv_std_logic_vector(conv_integer(valuebuffer(temppos to 8191)& valuebuffer(0 to slenval1-tempval-1)),4);
		     	                bitpos:=(others=>'0'); 
	                          		    tempcount1:='1';     	       
		     	                bitpos := conv_std_logic_vector((slenval1-tempval),13);
		     	            end if;		

				    	
			          end if;
			       end loop;
		           end loop;
	                 
	               else 
	  		    for sfb in 0 to 11 loop 
	                       for window in 0 to 2 loop 
		  	           if (sfb < 6) then 
		  	               if 8191-conv_integer(bitpos)+1>=slenval0 then
	      		       	  	scout.scalefac_s(sfb)(window):= conv_std_logic_vector(conv_integer(valuebuffer(conv_integer(bitpos) to conv_integer(bitpos)+slenval0-1)),4);
		     	          		if 8191-conv_integer(bitpos)+1=slenval0 then
		     	                   bitpos:=(others=>'0');
		     	                   tempcount1:='1';
		     	                else
		     	          		   bitpos := conv_std_logic_vector((conv_integer(bitpos) + slenval0),13);
		     	          		end if;
		     	       	      else
	                          			   temppos:=conv_integer(bitpos);
	                                tempval:=8191-temppos+1;
	                          		   
		     	                scout.scalefac_s(sfb)(window):=
		     	                conv_std_logic_vector(conv_integer(valuebuffer(temppos to 8191)& valuebuffer(0 to slenval0-tempval-1)),4);
		     	                bitpos:=(others=>'0'); 
	                          		    tempcount1:='1';     	       
		     	                bitpos := conv_std_logic_vector((slenval0-tempval),13);
		     	              end if;			
		    		   else 
		    		       if 8191-conv_integer(bitpos)+1>=slenval1 then
	      		       	  	scout.scalefac_s(sfb)(window):= 
	      		       	  	conv_std_logic_vector(conv_integer(valuebuffer(conv_integer(bitpos) to conv_integer(bitpos)+slenval1-1)),4);
		     	          		if 8191-conv_integer(bitpos)+1=slenval1 then
		     	                   bitpos:=(others=>'0');
		     	                   tempcount1:='1';
		     	                else
		     	          		   bitpos := conv_std_logic_vector((conv_integer(bitpos) + slenval1),13);
		     	       	        end if;
		     	       	      else
	                          			   temppos:=conv_integer(bitpos);
	                                tempval:=8191-temppos+1;
	                          		    
		     	                scout.scalefac_s(sfb)(window):=
		     	                conv_std_logic_vector(conv_integer(valuebuffer(temppos to 8191)& valuebuffer(0 to slenval1-tempval-1)),4);
		     	                bitpos:=(others=>'0');
	                          		    tempcount1:='1';      	       
		     	                bitpos := conv_std_logic_vector((slenval1-tempval),13);
		     	              end if;			
			  	       

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -