音频数量计算。每帧的音频包数量= 采样率/帧率 48K/50 = 48000/50= 960个起始点
如果是4个音频group,则有16个声道音频。 960*16= 15360 个声道采样点。
always @(posedge vclk or negedge rstN)
begin
if ( rstN == 1’b0 )
begin
hdstate <= HD_IDLE ; end else if ( vclken == 1'b1 ) begin case (hdstate)
HD_IDLE : begin
if ( hd == 1’b1 && vdata_zeroes[0] == 1’b1) begin
hdstate <= HD_3FFA ; end end
HD_3FFA : begin
if ( vdata_ones[0] == 1’b1 ) begin
hdstate <= HD_3FFB ; end else begin hdstate <=
HD_IDLE ;
end
end
HD_3FFB : begin if ( vdata_ones[0] == 1'b1 ) begin hdstate <=
HD_DID ;
end else begin
hdstate <= HD_IDLE ; end end
HD_DID : begin
// IF ( vdata_dly(9 DOWNTO 0) = “–111001–” ) THEN
if (vdata_dly[7:2] == 6’b111001) begin// 10bit 0x2e7
hdstate <= HD_DBN ; end else begin hdstate <=
HD_IDLE ;
end
end
HD_DBN : begin hdstate <=
HD_DC ;
end
HD_DC : begin hdstate <=
HD_UDW ;
end
HD_UDW : begin if ( udwcnt == 5'b11000 ) begin hdstate <=
HD_DONE ;
end
end
HD_DONE : begin if ( hd == 1'b1 && vdata_zeroes[0] == 1'b1) begin hdstate <=
HD_3FFA ;
end else
hdstate <= HD_IDLE ; end default : begin hdstate <=
HD_IDLE ;
end
endcase
end
end
// Get the sample values
always @(posedge vclk or negedge rstN)
begin
if ( rstN == 1’b0 )
begin
audio1 <= {24{1’b0}} ;
audio2 <= {24{1’b0}} ;
audio3 <= {24{1’b0}} ;
audio4 <= {24{1’b0}} ;
end
else if ( vclken == 1’b1 )
begin
if ( hdstate == `HD_UDW )
begin
case (udwcnt)
5’b00010 : audio1[3:0] <= vdata_dly[7:4] ;
5’b00011 : audio1[11:4] <= vdata_dly[7:0] ;
5’b00100 : audio1[19:12] <= vdata_dly[7:0] ;
5’b00101 : audio1[23:20] <= vdata_dly[3:0] ;
5’b00110 : audio2[3:0] <= vdata_dly[7:4] ;
5’b00111 : audio2[11:4] <= vdata_dly[7:0] ;
5’b01000 : audio2[19:12] <= vdata_dly[7:0] ;
5’b01001 : audio2[23:20] <= vdata_dly[3:0] ;
//
5’b01010 : audio3[3:0] <= vdata_dly[7:4] ;
5’b01011 : audio3[11:4] <= vdata_dly[7:0] ;
5’b01100 : audio3[19:12] <= vdata_dly[7:0] ;
5’b01101 : audio3[23:20] <= vdata_dly[3:0] ;
5’b01110 : audio4[3:0] <= vdata_dly[7:4] ;
5’b01111 : audio4[11:4] <= vdata_dly[7:0] ;
5’b10000 : audio4[19:12] <= vdata_dly[7:0] ;
5’b10001 : audio4[23:20] <= vdata_dly[3:0] ;
default :
begin
end
endcase
end
function [31:0] hd_grp_det ;
input [7:0] i;
reg [3:0] grp;
begin
if (i == 8’hE4) // HD Embedded Audio Packets Group 4
begin
grp = 4’b1000;
end
else if (i == 8’hE5) // HD Embedded Audio Packets Group 3
begin
grp = 4’b0100 ;
end
else if (i == 8’hE6) // HD Embedded Audio Packets Group 2
begin
grp = 4’b0010 ;
end
else if (i == 8’hE7) // HD Embedded Audio Packets Group 1
begin
grp = 4’b0001 ;
end
else
begin
grp = 4’b0000 ;
end
hd_grp_det = grp ;
end
endfunction
always @(posedge vclk or negedge rstN)
if (!rstN) audio_pak[127:0] <= 128’b0;
else
begin
if ( vclken ) begin
if (aud_pass == 1’b1 && aud_pass_d1 == 1’b1)
audio_pak <= 128’h0;
else if (grp == 4’b0001) begin
audio_pak[31:0] <= {8’h51, audio1_dly};
audio_pak[63:32] <= {8’h52, audio2};
audio_pak[95:64] <= {8’h53, audio3};
audio_pak[127:96] <= {8’h54, audio4};
end
else if (grp == 4’b0010) begin
audio_pak[31:0] <= {8’h55, audio1_dly};
audio_pak[63:32] <= {8’h56, audio2};
audio_pak[95:64] <= {8’h57, audio3};
audio_pak[127:96] <= {8’h58, audio4};
end
else if (grp == 4’b0100) begin
audio_pak[31:0] <= {8’h59, audio1_dly};
audio_pak[63:32] <= {8’h5a, audio2};
audio_pak[95:64] <= {8’h5b, audio3};
audio_pak[127:96] <= {8’h5c, audio4};
end
else if (grp == 4’b1000) begin
audio_pak[31:0] <= {8’h5d, audio1_dly};
audio_pak[63:32] <= {8’h5e, audio2};
audio_pak[95:64] <= {8’h5f, audio3};
audio_pak[127:96] <= {8’h60, audio4};
end
else audio_pak <= audio_pak;
end
end