Embodiment
The embodiment of the present invention provides a kind of multi-medium data acquisition methods and device, utilize the design feature of Huffman code, become to need the multi-medium data obtained by the data transformations to be decoded inputted with the form of data stream, in this course, Huffman code table is recoded into binary tree code table, the feature that when decoding in conjunction with Huffman code, data to be decoded input with the form of data stream, utilize the corresponding relation in the node type of each code length coding and binary tree code table and between the decoded result memory address of end-node each Huffman code corresponding, by the mode of iteration, calculate the decoded result memory address of the Huffman code to be decoded of corresponding end-node, therefrom obtain the decoded result of Huffman code, as the multi-medium data got, larger with the storage capacity requirement of the coding/decoding method solving Huffman code in prior art, the problem that system resources consumption is more.
Below in conjunction with accompanying drawing, the preferred embodiments of the present invention are described.
The process flow diagram of the multi-medium data acquisition methods that Fig. 1 provides for the embodiment of the present invention, comprises the steps:
Step 101: being recoded by the Huffman code table of current use is binary tree code table, store each self-corresponding decoded result of Huffman code of each end-node corresponding in this binary tree code table successively, and store the node type coding of the code length of each Huffman code in this binary tree code table successively.
The Huffman code table that several are different is defined in MP3 audio protocols, cataloged procedure due to Huffman code performs according to selected Huffman code table, therefore, in decode procedure, also need to use this selected Huffman code table to perform decoding, this selected Huffman code is current Huffman code table.
Because MP3 audio protocols defines several different Huffman code tables, the design feature of these Huffman code tables is all the same with generation principle, therefore, the embodiment of the present invention can after the Huffman code table of selected current use, according to the generation principle of this Huffman code table, by its recodification binary tree code table.
Illustrate that being recoded by Huffman code table is the principle of binary tree code table and process for two tuple Huffman code tables below.
The feature of two tuple Huffman code tables of MP3 audio protocols definition to need the data of coding to split into two parts, use the data representation in X-axis and Y-axis in XY coordinate system respectively, in such two tuple Huffman code tables, the code value of each Huffman code is to should a certain XY coordinate position of coordinate system.
Because two tuple Huffman code tables are according to binary tree Form generation, generate node downwards by the root node of most top layer, each node can generate at most two child nodes downwards, if node does not down generate child node, this node is exactly end-node.Due to from root node to each end-node the route of process be unique, so root node to an end-node binary coding corresponding to the path of process be exactly a Huffman code.
Fig. 2 is the rule generating binary tree.Consult shown in Fig. 2, the round dot represented by each English alphabet in this binary tree is all node, and in these nodes, A is root node, D, E, F, H and I are end-node, and the binary coding corresponding through path from these end-node to root node is exactly Huffman code.Such as, the path from root node A to end-node I, after root node, needs first through intermediate node C and intermediate node G, then just can arrive end-node I.And in the binary tree shown in Fig. 2, what the path of A to C was corresponding is encoded to 0, what the path of C to G was corresponding is encoded to 0, what the path of G to H was corresponding is encoded to 1, so the binary coding (i.e. Huffman code) of I is 3 ' b001, wherein, " 3 " represent the code length of the Huffman code that end-node I is corresponding, " ' b " represent scale-of-two, " 001 " represents the code value of the Huffman code that end-node I is corresponding.
In practical application, can be recoded by the Huffman code table of current use by following preferred mode is binary tree code table: in the mode generated according to binary tree, and the principle of compositionality of Huffman code, when Huffman code table is recoded into binary tree code table, no longer according to the data sequence arrangement Huffman code in Fig. 3, but arrange Huffman code according to the generating mode of binary tree, Huffman code is arranged from short to long according to code length, wherein, the Huffman code that code length is identical sorts successively according to the order that code value is ascending.
Below for the table 7 of the two tuple Huffman code tables defined in MP3 audio protocols, introduce the design feature of two tuple Huffman code tables, and his-and-hers watches 7 carry out the process of recoding.
Fig. 3 is table 7(and the Huffman code table7 of the two tuple Huffman code tables defined in MP3 audio protocols) sectional drawing.
In Fig. 3, the form needing the data of coding is that { X, Y}, wherein the maximal value of X and Y is all 5, and binary representation is 3 ' b101, and so the bit wide of X and Y is all 3.
Hlen in Fig. 3 represents the code length of Huffman code.In implementation procedure due to Huffman code Code And Decode, the bit wide of hlen is generally fixing, therefore, need the effective bit wide of the scale-of-two bit wide fixed value of hlen being set to the code length of the longest Huffman code, the bit wide fixed value by hlen is set to the effective bit wide of scale-of-two of the maximum hlen value in Huffman code table.Such as, in Fig. 1, the code length of the longest Huffman code is the value of 10(and maximum hlen is 10), its binary mode is 4 ' b1010, and bit wide is 4, and therefore, in Code And Decode process, the bit wide fixed value of hlen will be set to 4.
Hcod in Fig. 3 represents the code value of Huffman code, represents with binary form, and effective bit wide of different code value may be different.Bit wide due to the implementation procedure hcod at Huffman code Code And Decode must be fixing, therefore, needs the code length bit wide fixed value of hcod being set to the longest Huffman code.Such as, in Fig. 1, the code length of the longest Huffman code is 10, therefore, needs the bit wide fixed value of hcod to be set to 10.
Owing to there is the different Huffman code of code length in Huffman code table, therefore, the code value of each Huffman code shows by corresponding hcod value by Huffman code table respectively.Like this, in the Code And Decode process of the Huffman code of reality, hcod value corresponding to each data is exactly the code value form of expression of Huffman code corresponding to these data.For the ease of storing and reading, first the bit wide fixed value of hcod can be set to the code length of the longest Huffman code, then for any one Huffman code, when storing, by the code value of this any one Huffman code according to inserting in the correspondence position of corresponding hcod successively to the order of low level from a high position, if the code length of this any one Huffman code cannot reach the bit wide fixed value of hcod, then need after the high-order portion code value of this any one Huffman code all being inserted corresponding hcod, 0 is filled at the residue low portion of corresponding hcod, the length of the hcod of this Huffman code is made to reach bit wide fixed value.And when reading any one Huffman code, then the hlen value corresponding according to this Huffman code can determine the code length of this Huffman code, thus determine to be the effective value of this Huffman code from most significant digit to hlen position in hcod, other place value in hcod is then filler.
Such as, in Fig. 3, the data { 0 of X=0 and Y=2, the code value of the Huffman code that 2} is corresponding is 6 ' b00_1010, and in the table 7 of Huffman table, the bit wide fixed value of hcod is 10, therefore, hcod value corresponding to these data is { 6 ' b00_1010,4 ' b0000}, its first 6 is effective code value, and latter 4 is fill with content.
According to the generating mode of binary tree and the principle of compositionality of Huffman code, the Huffman code table table 7 in Fig. 3 can be recoded as the form (table 1 is binary tree code table) in table 1 below.
Table 1
0
|
0010
|
000010
|
0000010
|
0001100 |
00001000 |
000000100 |
1 |
0011 |
000011
|
0000011
|
0001101 |
00001001 |
000000101 |
00
|
00000
|
000100
|
0000100
|
00000000
|
00010000 |
000001010 |
01
|
00001
|
000101
|
0000101 |
00000001
|
00010001 |
000001011 |
000
|
00010
|
000110
|
0000110 |
00000010
|
00010010 |
000001110 |
001
|
00011
|
000111 |
0000111 |
00000011 |
00010011 |
000001111 |
010 |
00100 |
001010 |
0001000
|
00000100 |
000000000
|
0000000000 |
011 |
00101
|
001011 |
0001001
|
00000101
|
000000001
|
0000000001 |
0000
|
000000
|
0000000
|
0001010 |
00000110 |
000000010 |
0000000010 |
0001
|
000001
|
0000001
|
0001011 |
00000111
|
000000011 |
0000000011 |
Table 1 check that order is first from top to bottom, more from left to right, wherein, the Huffman code that underscore marks is the Huffman code that intermediate node is corresponding, and the Huffman code not marking underscore is Huffman code corresponding to end-node.
Have 34 intermediate nodes in the complete binary tree of table 1 correspondence, 36 end-node, intermediate node quantity is close to end-node quantity, and wherein, Huffman code corresponding to end-node has decoded result, and Huffman code corresponding to intermediate node does not have decoded result.If the information unification of intermediate node and end-node is stored, the twice that the storage space so taken will take up room close to actual decoded result, so do not store Huffman code corresponding to intermediate node in the embodiment of the present invention, only store Huffman code corresponding to end-node, like this, taking of storage space can be greatly reduced, save system resource.
In the embodiment of the present invention, the preferably mode storing each self-corresponding decoded result of Huffman code of each end-node corresponding in above-mentioned binary tree code table is successively: distinguish the code length of corresponding Huffman code from short to long according to each end-node in above-mentioned binary tree code table, code value order from small to large, store corresponding decoded result, that is, by each self-corresponding decoded result of Huffman code of each end-node corresponding in above-mentioned binary tree code table, according to the code length order arrangement from short to long of corresponding Huffman code, wherein, by decoded result identical for the code length of corresponding Huffman code, the order ascending according to the code value of corresponding Huffman code sorts successively.Below each self-corresponding decoded result of Huffman code of each end-node corresponding in table 1 is stored according to the storage mode of following table 2.In practical application, the code value of the Huffman code in table 2 can not store, and directly stores corresponding decoded result according to the memory address in table 2.
Table 2
Huffman code code value |
Memory address |
Decoded result (x, y) |
1 |
0 |
0,0 |
010 |
1 |
0,1 |
011 |
2 |
1,0 |
0011 |
3 |
1,1 |
00100 |
4 |
2,1 |
000111 |
5 |
1,2 |
001010 |
6 |
0,2 |
001011 |
7 |
2,0 |
0000101 |
8 |
1,4 |
0000110 |
9 |
4,1 |
0000111 |
10 |
4,0 |
0001010 |
11 |
1,3 |
0001011 |
12 |
3,1 |
0001100 |
13 |
3,0 |
0001101 |
14 |
2,2 |
00000011 |
15 |
1,5 |
00000100 |
16 |
5,1 |
00000110 |
17 |
5,0 |
00001000 |
18 |
2,4 |
00001001 |
19 |
4,2 |
00010000 |
20 |
0,4 |
00010001 |
21 |
2,3 |
00010010 |
22 |
3,2 |
00010011 |
23 |
0,3 |
000000010 |
24 |
3,5 |
000000011 |
25 |
4,4 |
000000100 |
26 |
2,5 |
000000101 |
27 |
5,2 |
000001010 |
28 |
0,5 |
000001011 |
29 |
3,4 |
000001110 |
30 |
4,3 |
000001111 |
31 |
3,3 |
0000000000 |
32 |
5,5 |
0000000001 |
33 |
4,5 |
0000000010 |
34 |
5,4 |
0000000011 |
35 |
53 |
The node type cataloged procedure provided in the embodiment of the present invention is provided.In this course, first can judge that in above-mentioned binary tree code table, each self-corresponding node of each Huffman code is end-node or intermediate node, namely know that (if node corresponding to Huffman code is intermediate node, the node type value of this Huffman code is exactly 1 for node type value that in above-mentioned binary tree code table, each Huffman code is corresponding; If the node that Huffman code is corresponding is end-node, the node type value of this Huffman code is exactly 0).Due to the code length of multiple Huffman code may be had in binary tree code table identical, therefore, same code length is corresponding multiple some Huffman codes probably, and the node type coding of some code lengths, then contain each self-corresponding node type value of all Huffman codes corresponding to this code length.
Said process is exactly the process of carrying out node type coding for the code length of each Huffman code.
Preferably, can encode according to the node type of code length each code length of sequential storage from short to long of Huffman code in above-mentioned binary tree code table, wherein, the node type encoded packets of any one code length contains each self-corresponding node type value of all Huffman codes corresponding to any one code length described.
That is, the node type value of each node that any one code length can be comprised, the order descending according to the code value of Huffman code corresponding to respective nodes is arranged in order, and the node type as this any one code length is encoded.Like this, in the node type coding of any one Huffman code code length, a high position is the node type value that Huffman code that code value is higher is corresponding, and low level is the node type value that Huffman code that code value is lower is corresponding.When the node type of the code length storing each Huffman code in above-mentioned binary tree code table becomes, then can according to the code length of Huffman code sequential storage from short to long.
If represent the code length of Huffman code with hlen, the code value of Huffman code is represented with hcod, represent that (the T value of intermediate node is 1 for the node type value of each Huffman code with T, the T value of end-node is 0), so, the node type that each hlen is corresponding is encoded then: by the T value of all Huffman codes corresponding for each hlen, according to what obtain after the order arrangement that corresponding hcod value is descending.
Such as, in table 1, code length be 3 Huffman code have 4, be respectively 011,010,001 and 000, wherein, what the first two Huffman code was corresponding is end-node, what latter two Huffman code was corresponding is intermediate node, so the node type coding of code length 3 is 4 ' b0011.
After being encoded according to node type by Huffman codes all in table 1, just can obtain table 3 below with binary form list:
Table 3
Huffman code code length |
Node type is encoded |
Bit wide |
1 |
2’b01 |
2 |
2 |
2’b11 |
2 |
3 |
4’b0011 |
4 |
4 |
4’b0111 |
4 |
5 |
6’b10_1111 |
6 |
6 |
10’b0001_1111_11 |
10 |
7 |
14’b0000_1100_0111_11 |
14 |
8 |
14’b0000_0010_1001_11 |
14 |
9 |
10’b0000_0000_11 |
10 |
10 |
4’b0000 |
4 |
Because the quantity of Huffman code corresponding to each code length is different, therefore, the length of the node type coding of each code length is also different, in implementation procedure, needs the bit wide of each node type being encoded to be set to fixed value.In actual applications, the mode of a node type code storage to a reference address stores by general employing, in order to reduce storage space, can also merge part of nodes type coding, then by merge after node type code storage in a reference address.When merging, the code length order from large to small of each node type coding needing to merge according to corresponding Huffman code is arranged.Like this, in the node type coded combination after merging, a high position is the code value of the node type coding of larger code length, and low level is the code value of the node type coding of less code length.
Consult table 4 below, the node type of code length 1 to code length 4 in table 3 coding is merged, the node type coding of code length in table 39 and code length 10 is merged.
Table 4
Memory address |
The code length of combination |
Coded combination |
Bit wide |
0 |
4,3,2,1 |
{4’b0000,4’b0111,4’b0011,2’b11,2’b01} |
14 |
1 |
5 |
{8’b0000_0000,6’b10_1111} |
14 |
2 |
6 |
{4’b0000,10’b0001_1111_11} |
14 |
3 |
7 |
14’b0000_1100_0111_11 |
14 |
4 |
8 |
14’b0000_0010_1001_11 |
14 |
5 |
10,9 |
{4’b0000,10’b0000_0000_11} |
14 |
Step 102: when often receiving data to be decoded, by the data to be decoded be currently received and the data merging to be decoded received before this, as current Huffman code, wherein, these data to be decoded be currently received are the lowest order of this current Huffman code, and the data to be decoded that first time receives are the most significant digit of this current Huffman code.
In practical application, the Huffman code of MP3 audio protocols inputs with the form of data stream, once inputs a data, and the order that each data to be decoded that each Huffman code comprises input, what be corresponding in turn to is that a high position for corresponding Huffman code is to low level.Above-mentioned rule, the principle of compositionality of corresponding is Huffman code itself, namely Huffman code by a high position to each place value of low level, respectively in corresponding binary tree accordingly root node to end-node.
Step 103: the node type value position offset in the node type coding of specifying corresponding according to the most significant digit of current Huffman code, iterative manner is adopted to obtain the decoded result memory address of current Huffman code, and therefrom read decoded result, wherein, the node type coding of specifying comprises the long corresponding each self-corresponding node type value of all Huffman codes of most short code.
Above-mentioned node type coding of specifying just refers to the long corresponding node type coding of most short code, i.e. the node type coding 01 of code length 1 correspondence.
Step 104: the decoded result of above-mentioned current Huffman code is exported as the multi-medium data got.
Preferably, step 103 can pass through following process implementation:
The node type value position offset in the node type coding of specifying corresponding according to the most significant digit of current Huffman code, adopts iterative manner to obtain the node type value of this current Huffman code and the decoded result memory address of above-mentioned current Huffman code,
In the node type value according to this current Huffman code, when judging that node that this current Huffman code is corresponding is as end-node, decoded result is read from the decoded result memory address of this current Huffman code, wherein, the node type coding of specifying comprises the long corresponding each self-corresponding node type value of all Huffman codes of most short code.
This is because the intermediate node of binary tree can generate two adjacent nodes downwards, so the number of node that next code length comprises is the twice of the number of the intermediate node that current code length comprises, if namely the node type of current code length is encoded in some node type values of comprising, numerical value be 1 node type value add up to N, so the sum of the Huffman code that next code length is corresponding is exactly 2 × N.
And, if be informed in the node type coding of current code length, the position of the node type value of the Huffman code of some corresponding intermediate nodes is BIT_N, so just can extrapolate, to should the position of node type value of the corresponding separately Huffman code of two child nodes of node of Huffman code, BIT_N+0 and BIT_N+1 in the node type coding of next code length respectively, wherein, to should two child nodes of node of Huffman code refer to, in binary tree, to should the adjacent child node of the node of Huffman code two of generating downwards.
Such as, the node type of code length 5 is encoded to 6 ' 10_1111, in the node type value of each Huffman code of code length 5 correspondence, numerical value be the node type value of 1 add up to 5, therefore, the number of the Huffman code of code length 6 correspondence is 10.Suppose, the node type value of the Huffman code of corresponding node a is 1, be arranged in the bit5 position of the node type coding of code length 5 (namely at " 6 ' 10_1111 ", from high-order toward the 5th place value of lower-order digit, " 1 " that indicates mark of emphasis is below the node type value of the Huffman code of corresponding node a), and be in the node type value of 1 at the node type coding median of code length 5, the arrangement position of the node type value of corresponding node a is bit4 position.Just can release according to above-mentioned rule like this, the node type value of each self-corresponding Huffman code of two nodes that node a generates downwards, lay respectively at code length 6 node type coding bit8 position and bit9 position on.
Below for the table 7 that current use MP3 audio protocols specifies, the more excellent implementation of the multi-medium data acquisition methods that the embodiment of the present invention provides is described, as shown in Figure 4, the flow process of the method comprises:
Step 401: according to the Huffman code table table 7 specified in MP3 audio protocols, the binary tree code table table 1 arranged is carried out in generation according to the generating mode of binary tree, Huffman code arranges according to code length order from short to long by this binary tree code table 1, wherein, the Huffman code that code length is identical arranges according to the order that code value is ascending.
Step 402: the Huffman code storing each end-node corresponding in binary tree code table table 1, its arrangement mode is that wherein, the Huffman code that code length is identical arranges from small to large according to code value according to code length order arrangement from small to large.
Step 403: the node type coding storing the code length of each Huffman code in binary tree code table table 1 successively, wherein, contain the node type value of all Huffman codes corresponding to this any one code length in the node type coding of any one code length, and its arrangement is according to the descending order of the code value of corresponding Huffman code.
Step 404: to the Huffman code X inputted with the form of data stream
1x
2x
3x
ndecode, wherein, n is positive integer.
Step 405: the decoded result got in step 404 is exported as the multi-medium data obtained.
In practical application, in multi-medium data acquisition process, become the decode procedure of decoded result can be realized by demoder data transformations to be decoded.
Illustrate below and how to adopt the mode of iteration to realize, to the Huffman code X inputted with the form of data stream
1x
2x
3x
ndecoding, wherein, n is positive integer.
From first data to be decoded of input, often input data to be decoded, the data to be decoded of record before current data to be decoded and this are merged as a Huffman code, then obtain next bit data to be decoded, until judge the Huffman code of current generation corresponding be end-node.
1st takes turns iterative process:
When getting the 1st data X1 to be decoded of input, current Huffman code is the 1st data X1 to be decoded, current Huffman code code length i=1, if the value of the data to be decoded of current input is IN:
(1) in the node type value of each Huffman code of code length 1 correspondence, numerical value is the node type value sum C_V1_1_ALL=1 of 1, and namely the initial value of C_V1_N_ALL is 1.
(2) current Huffman code X is calculated
1node type value Huffman code code code length 1 node type coding in position C_P, C_P=P_P_V1+IN.
Now, there is no a upper code length, if the initial value of P_P_V1 is 1, therefore, its position C_P=1+IN, wherein, IN is the value of the data to be decoded of input, if the value IN=1 of the data to be decoded of input, then C_P=2, if the value IN=0 of the data to be decoded of input, then C_P=1.
(3) obtaining numerical value in the node type coding of code length 1 is the number C_V0_1_ALL=1 of the node type value of 0, and namely the initial value of C_V0_N_ALL is 1.
(4) obtaining numerical value in the node type coding of code length 1 is the extreme higher position C_P_V1=0 of the node type value of 1, and namely the initial value of C_P_V1 is 0.
(5) the Huffman code sum 2_ALL=2*C_V1_1_ALL=2 of code length 2 correspondence is calculated.
(6) the reference address ADDR_CODE_2 of the node type coding of code length 2 correspondence is calculated.
The reference address ADDR_CODE_1=0 of the node type coding of code length 1 correspondence.
Because, ADDR_CODE_1_UPDATE=0, so, C_ALL_CAL=1_ALL_CAL, and 1_ALL_CAL=2, so, 2_ALL_CAL=C_ALL_CAL+N_ALL=2+2=4.Because the CODE_WIDTH preset is 14, so 2_ALL_CAL is less than CODE_WIDTH, so, next reference address need not be accessed, now, ADDR_CODE_2=0.
(7) the content RD_CODE_1 stored in the reference address of the node type coding of code length 1 is read.
RD_CODE_1=BUFFER_CODE[ADDR_CODE_1]
(8) node type of calculating code length 2 is coded in the reference position 2_ADDR_S in RD_CODE_2.
Because now ADDR_CODE_1_UPDATE is 0,
So 2_ADDR_S=1_ADDR_S+C_ALL=0+2=2, namely in current accessed address, the reference position of code length 1 is 0, the reference position 2_ADDR_S=2 of code length 2.
(9) the end position 2_ADDR_E of the node type coding of code length 2 is calculated.
The initial value of N_ADDR_E is 1, and namely the node type end-of-encode position of code length 1 is 1.2_ADDR_E=1_ADDR_S+1_ALL-1=2+2-1=3。
(10) read the node type coding CODE_N of code length 2, the reference position of encoding from the node type of code length 2 reads end position, CODE_2=RD_CODE_2 [2_ADDR_E:2_ADDR_S].
(11) the decoded result reference address ADDR_DATA_HEAD_2 of the minimum Huffman code of budget code length 2 correspondence.
Because first decoded result of code length 1 correspondence leaves address 0 place in, therefore, the initial value of ADDR_DATA_HEAD_N is 0, i.e. ADDR_DATA_HEAD_1=0.
ADDR_DATA_HEAD_2=ADDR_DATA_HEAD_1+C_ALL-C_V1_1_ALL
=0+2-1=1, wherein, C_ALL is the N_ALL that a upper code length calculates, i.e. the sum of the Huffman code of code length 1 correspondence, and C_V1_1_ALL is that in the node type coding of code length 1, numerical value is the number of the node type value of 1.
(12) according to RD_CODE_1 and C_P, judge whether CODE_C [C_P] is 0, if so, directly enters next step (13), otherwise, enter the 2nd and take turns iterative process.
(13) X is calculated
1the reference address ADDR_DATA of decoded result.
ADDR_DATA=C_V0_1_ALL-1+ADDR_DATA_HEAD_C=1-1+1=1。
2nd to take turns iterative process as follows:
When getting the 2nd data X2 to be decoded of input, current Huffman code is X
1x
2, current code length i=2, Huffman code X
1for with Huffman code X
1x
2the Huffman code that the upper code length be associated is corresponding.
(1) obtaining numerical value in the node type coding of code length 2 according to the CODE_2 read in last round of iterative process is the number C_V1_2_ALL=2 of the node type value of 1.
C_V1_N_ALL is the result that all place values of CODE_C are added.
(2) current Huffman code X is calculated
1x
2node type value code length 2 node type coding in position C_P.
The value of P_P_V1 equals the C_P_V1 calculated when code length is 1, P_P_V1=0,
C_P=P_P_V1+IN=0+X
2
(3) the number C_V0_2_ALL of node type value of numerical value 0 in the node type coding of code length 2.
C_V0_2_ALL=(~ CODE_C [C_P:0]) the result that is added of all place values, after CODE_2 negate, the result after each place value encoded packets after negate contained is added.
(4) obtaining numerical value in the node type coding of code length 2 is result-1 after all place values of the extreme higher position C_P_V1=CODE_C [C_P:0] of the node type value of 1 are added.
(5) the node total number 3_ALL=2*C_V1_2_ALL=4 that Huffman code code length 3 comprises is calculated.
(6) the reference address ADDR_CODE_3=ADDR_CODE_2+ADDR_CODE_2_UPDATE of the node type coding of Huffman code code length 3 correspondence is calculated.
ADDR_CODE_2=2, judges whether N_ALL_CAL is more than or equal to CODE_WIDCH, if ADDR_CODE_2_UPDATE=1, otherwise ADDR_CODE_2_UPDATE=0.
N_ALL_CAL=C_ALL_CAL+N_ALL, judge whether ADDR_CODE_C_UPDATE is 1, if, C_ALL_CAL=C_ALL, C_ALL is the N_ALL calculated in last round of iterative process, otherwise, the N_ALL_CAL value calculated in the last round of iterative process of C_ALL_CAL=, ADDR_CODE_2_UPDATE=0.
Because, the last round of ADDR_CODE_2_UPDATE=0 calculated, so, 3_ALL_CAL=2_ALL_CAL+2_ALL=4+2=6.Because 3_ALL_CAL is less than CODE_WIDTH, so next reference address need not be accessed, ADDR_CODE_2_UPDATE=0.
(7) the storage content RD_CODE_2 of BUFFR_CODE is read.
RD_CODE_2=BUFFER_CODE[ADDR_CODE_2]
(8) node type of calculating code length 3 is coded in the reference position 3_ADDR_S in RD_CODE_N.
Due to the ADDR_CODE_2_UPDATE=0 that this calculates, so 3_ADDR_S=2_ADDR_S+C_ALL=2+2=4, namely the node type of code length 3 is coded in the reference position in the reference address that epicycle calculates is 4.
(9) the end position 3_ADDR_E of the node type coding of code length 3 is calculated.
3_ADDR_E=3_ADDR_S+4_ALL-1=4+4-1=7。
(10) according to reference position and the end position of the node type coding of the code length 3 calculated, node type coding CODE_3=RD_CODE_3 [3_ADDR_E:3_ADDR_S] of code length 3 is read.
(11) the decoded result reference address ADDR_DATA_HEAD_3=of the minimum Huffman code of budget code length 3 correspondence
ADDR_DATA_HEAD_2+C_ALL-C_V1_2_ALL=1+2-2=1。
(12) according to RD_CODE_2 and C_P, judge that CODE_C [C_P] is as 0, enters the 3rd and takes turns iterative process.
In the Huffman table table 7 that MP3 audio protocols specifies, code length be 2 node corresponding to Huffman code be all intermediate node, there is not corresponding decoded result.
N takes turns iterative process:
During input n-th data Xn to be decoded, current Huffman code is X
1x
2x
3x
n, current Huffman code code length i=N.
(1) the node type coding interior joint types value calculating code length N according to the CODE_N-1 that reads in last round of iterative process is the node total number C_V1_N_ALL of 1.
C_V1_N_ALL is the result that all place values of CODE_C are added.
(2) current Huffman code X is calculated
1x
2x
3x
nnode type value code length N node type coding in position C_P.
C_P={P_P_V1, IN}, the wherein value of P_P_V1 to be the C_P_V1 calculated in last round of iterative process, IN the be data to be decoded of current input.
The i.e. C_P_V1+X of the last round of acquisition of C_P=P_P_V1+IN=
n
(3) in the node type coding of code length N, numerical value is the number C_V0_N_ALL of the node type value of 0.
C_V0_N_ALL=(~ CODE_C [C_P:0]) the result that is added of all place values, put in place by position C_P and set to 0 the coding negate of middle storage, the result after each the place value then encoded packets after negate contained is added.
Like this, just can calculate in the node type coding of current code length according to C_V0_N_ALL in step afterwards, the position C_P of the node type value of current Huffman code to this node type value lowest order between distance, because each node type value that the node type encoded packets of each code length contains is according to descending tactic of the code value of corresponding Huffman code.
(4) obtaining numerical value in the node type coding of code length N is result-1 after all place values of the extreme higher position C_P_V1=CODE_C [C_P:0] of the node type value of 1 are added, and all place values of the coding setting to 0 middle storage that puts in place by position C_P are added.
(5) the total N_ALL=2*C_V1_N+1_ALL of the Huffman code that budget code length N+1 is corresponding.
The sum of the Huffman code that code length N+1 is corresponding, the sum of the node type value that the node type encoded packets equaling code length N+1 contains.
(6) the reference address ADDR_CODE_N+1=ADDR_CODE_N+ADDR_CODE_N_UPDATE of the node type coding that budget code length N+1 is corresponding.
Due in order to save storage space, have employed the storage mode memory node type coding of table 4 correspondence, therefore, the node type coding of one or more code length is might have stored in a reference address (i.e. storage unit), therefore, need the reference address of the node type coding judging current code length the need of renewal, also need the node type coding position in the memory unit of the next code length of budget.
Judge whether N_ALL_CAL is more than or equal to CODE_WIDCH, if ADDR_CODE_N_UPDATE=1, otherwise ADDR_CODE_N_UPDATE=0, wherein, CODE_WIDCH is in the reference address of node type coding, and reference address can the preset maximum value of number of memory node types value.
N_ALL_CAL=C_ALL_CAL+N_ALL, judges whether ADDR_CODE_C_UPDATE is 1, if, C_ALL_CAL=C_ALL, wherein, C_ALL is the N_ALL calculated in last round of iterative process, otherwise, the N_ALL_CAL value calculated in the last round of iterative process of C_ALL_CAL=.
(7) the storage content RD_CODE_N of BUFFR_CODE is read.
RD_CODE_N=BUFFER_CODE[ADDR_CODE_N]
(8) node type of budget code length N+1 is coded in the reference position N+1_ADDR_S in RD_CODE_N+1.
Judge whether the ADDR_CODE_N_UPDATE calculated in epicycle iterative process equals 1, if so, N+1_ADDR_S=0, otherwise, N+1_ADDR_S=N_ADDR_S+C_ALL, wherein.
(9) the end position N+1_ADDR_E of the node type coding of budget code length N+1.
N+1_ADDR_E=N_ADDR_S+N_ALL-1。
(10) basis calculates reference position and the end position of the node type coding of code length N before, reads node type coding CODE_N+1=RD_CODE_N+1 [N+1_ADDR_E:N_ADDR_S] of code length N+1.
(11) the decoded result reference address ADDR_DATA_HEAD_N+1=ADDR_DATA_HEAD_N+C_ALL-C_V1_N_ALL of the minimum Huffman code that budget code length N+1 is corresponding, wherein C_ALL is the sum of the Huffman code that code length N is corresponding, and C_V1_N_ALL is that in the node type coding of code length N, numerical value is the number of the node type value of 1.
(12) according to RD_CODE_N and C_P, judge whether CODE_C [C_P] is 1, if so, continue next round iterative process, otherwise, perform step (13).
(13) ADDR_DATA=C_V0_N_ALL-1+ADDR_DATA_HEAD_N-1, wherein, ADDR_DATA_HEAD_N-1 is the decoded result reference address that minimum Huffman code that the code length N calculated in last round of iterative process comprises is corresponding.
It is 0 that above-mentioned iterative process performs CODE_C [C_P] always, reads out the reference address of decoded result, and till therefrom getting decoded result.
The decode operation flow process of the Huffman code of the table 7 of the Huffman code table that table 5 below adopts the form of code to describe to specify based on MP3 audio protocols, supposes that the code value of a Huffman code that will input is 00000110, in corresponding decoded data X be 5 and Y be 0.
1st step, generates a binary tree code table as shown in table 1.
2nd step, as shown in table 2, decoded data is stored in BUFFER_DATA.
3rd step, as shown in table 3, by the node type code storage of each code length in BUFFER_CODE.
4th step, reads each place value of the Huffman code of input successively, and performs iterative process according to table 5, until solve decoded result.
Table 5
There is provided thinking based on same, the embodiment of the present invention additionally provides a kind of multi-medium data acquisition device, consults shown in Fig. 5, comprising:
Recodification module 501 is binary tree code table for being recoded by the Huffman code table of current use;
Memory module 502, for storing each self-corresponding decoded result of Huffman code of each end-node corresponding in above-mentioned binary tree code table successively, and stores the node type coding of the code length of each Huffman code in above-mentioned binary tree code table successively;
Merge module 503, during for often receiving data to be decoded, by the data to be decoded be currently received and the data merging to be decoded received before this, as current Huffman code, wherein, the above-mentioned data to be decoded be currently received are the lowest order of above-mentioned current Huffman code, and the data to be decoded that first time receives are the most significant digit of above-mentioned current Huffman code;
Acquisition module 504, for the node type value position offset in the node type coding of specifying corresponding according to the most significant digit of above-mentioned current Huffman code, iterative manner is adopted to obtain the memory address of above-mentioned current Huffman code decoded result, and from this memory address, read above-mentioned current Huffman code decoded result, wherein, the node type coding of specifying comprises the long corresponding each self-corresponding node type value of all Huffman codes of most short code; And the decoded result of described current Huffman code is exported as the multi-medium data got.
Said apparatus be with method flow one to one, do not repeat them here.
The embodiment of the present invention utilizes the design feature of Huffman code, Huffman code table is recoded into binary tree code table, the feature that when decoding in conjunction with Huffman code, data to be decoded input with the form of data stream, utilize the corresponding relation in the node type of each code length coding and binary tree code table and between the decoded result memory address of end-node each Huffman code corresponding, by the mode of iteration, calculate the memory address of the decoded result of the Huffman code to be decoded of corresponding end-node, therefrom obtain Huffman code decoded result, larger with the storage capacity requirement of the coding/decoding method solving Huffman code in prior art, the problem that system resources consumption is more.
The present invention describes with reference to according to the process flow diagram of the method for the embodiment of the present invention, equipment (system) and computer program and/or block scheme.Should understand can by the combination of the flow process in each flow process in computer program instructions realization flow figure and/or block scheme and/or square frame and process flow diagram and/or block scheme and/or square frame.These computer program instructions can being provided to the processor of multi-purpose computer, special purpose computer, Embedded Processor or other programmable data processing device to produce a machine, making the instruction performed by the processor of computing machine or other programmable data processing device produce device for realizing the function of specifying in process flow diagram flow process or multiple flow process and/or block scheme square frame or multiple square frame.
These computer program instructions also can be stored in can in the computer-readable memory that works in a specific way of vectoring computer or other programmable data processing device, the instruction making to be stored in this computer-readable memory produces the manufacture comprising command device, and this command device realizes the function of specifying in process flow diagram flow process or multiple flow process and/or block scheme square frame or multiple square frame.
These computer program instructions also can be loaded in computing machine or other programmable data processing device, make on computing machine or other programmable devices, to perform sequence of operations step to produce computer implemented process, thus the instruction performed on computing machine or other programmable devices is provided for the step realizing the function of specifying in process flow diagram flow process or multiple flow process and/or block scheme square frame or multiple square frame.
Although describe the preferred embodiments of the present invention, those skilled in the art once obtain the basic creative concept of cicada, then can make other change and amendment to these embodiments.So claims are intended to be interpreted as comprising preferred embodiment and falling into all changes and the amendment of the scope of the invention.
Obviously, those skilled in the art can carry out various change and modification to the embodiment of the present invention and not depart from the spirit and scope of the embodiment of the present invention.Like this, if these amendments of the embodiment of the present invention and modification belong within the scope of the claims in the present invention and equivalent technologies thereof, then the present invention is also intended to comprise these change and modification.