Specific embodiment
The embodiment of the present invention provides a kind of multi-medium data acquisition methods and device, using the design feature of Huffman code,
The data to be decoded being input in the form of data flow are changed into the multi-medium data for needing to obtain, in this course, will be breathed out
Binary tree code table recoded into by the graceful code table of husband, the spy that data to be decoded are input in the form of data flow when decoding in conjunction with Huffman code
Point, is tied with the decoding of each Huffman code corresponding with end-node in binary tree code table using the node type coding of each code length
Corresponding relation between fruit storage address, by way of iteration, calculates the solution of the Huffman code to be decoded of corresponding end-node
Code result storage address, therefrom obtains the decoded result of Huffman code, as the multi-medium data for getting, to solve existing skill
In art, the storage capacity requirement of the coding/decoding method of Huffman code is larger, the more problem of system resources consumption.
The preferred embodiments of the present invention are described below in conjunction with the accompanying drawings.
Fig. 1 is the flow chart of multi-medium data acquisition methods provided in an embodiment of the present invention, comprises the steps:
Step 101:It is binary tree code table that currently used Huffman code table is recoded, and stores the binary tree code table successively
In each end-node corresponding each self-corresponding decoded result of Huffman code, and store successively each in the binary tree code table
The node type coding of the code length of individual Huffman code.
Several different Huffman code tables defined in MP3 audio protocols, as the cataloged procedure of Huffman code is root
Execute according to selected Huffman code table, therefore, in decoding process, it is also desirable to execute solution using the selected Huffman code table
Code, the selected Huffman code are current Huffman code table.
As MP3 audio protocols define several different Huffman code tables, the design feature of these Huffman code tables
It is just as with principle is produced, therefore, the embodiment of the present invention can be after currently used Huffman code table be selected, according to this
The generation principle of Huffman code table, by its recodification binary tree code table.
Illustrate by taking two tuple Huffman code tables as an example below by Huffman code table recode for binary tree code table principle and
Process.
The characteristics of two tuple Huffman code table of MP3 audio protocols definition is that the data for needing coding are splitted into two parts,
Represented with the data in X-axis and Y-axis in XY coordinate systems respectively, the code value of each Huffman code in such two tuples Huffman code table
All to should coordinate system a certain XY coordinate positions.
As two tuple Huffman code tables are according to binary tree Form generation, section is generated downwards by the root node of top
Point, each node at most can generate downwards two child nodes, if node does not down generate child node, the node is exactly end
Node.Due to being unique from root node to the route passed through by each end-node, so root node is to an end-node
The corresponding binary coding of paths traversed is exactly a Huffman code.
Fig. 2 is the rule for generating binary tree.Refering to the circle represented by each English alphabet shown in Fig. 2, in the binary tree
Point is all node, and in these nodes, A is root node, and D, E, F, H and I are end-nodes, passes through from these end-nodes to root node
It is exactly Huffman code to cross the corresponding binary coding in path.For example, from root node A to end-node I path, from root node
Afterwards, need to first pass through intermediate node C and intermediate node G, then can just reach end-node I.And in the binary tree shown in Fig. 2, A is arrived
The path of C is corresponding to be encoded to 0, and the path of C to G is corresponding to be encoded to 0, and the path of G to H is corresponding to be encoded to 1, so, I
Binary coding(That is Huffman code)It is 3 ' b001, wherein, " 3 " represent the code length of the corresponding Huffman code of end-node I, " ' b "
Represent that binary system, " 001 " represent the code value of the corresponding Huffman code of end-node I.
In practical application, it is the y-bend scion that currently used Huffman code table can be recoded by following preferred modes
Table:In the mode generated according to binary tree, and the principle of compositionality of Huffman code, Huffman code table is recoded into the y-bend scion
During table, not according still further to Fig. 3 in data order arrangement Huffman code, but according to binary tree generating mode arrangement Huffman
Code, Huffman code is arranged from short to long according to code length, and wherein, code length identical Huffman code is according to ascending suitable of code value
Sequence is sorted successively.
Below by taking the table 7 of two tuple Huffman code tables defined in MP3 audio protocols as an example, two tuple Huffman codes are introduced
The design feature of table, and the process recoded by table 7.
Fig. 3 is the table 7 of two tuple Huffman code tables defined in MP3 audio protocols(That is Huffman code
table7)Sectional drawing.
In Fig. 3, the form for needing the data of coding is { X, Y }, and the maximum of wherein X and Y is all 5, and binary representation is
3 ' b101, then the bit wide of X and Y is all 3.
Hlen in Fig. 3 represents the code length of Huffman code.During due to the realization of Huffman code coding and decoding, hlen
Bit wide be usually fixed, accordingly, it would be desirable to the bit wide fixed value of hlen is set to the code length of most long Huffman code two enter
Be formed with effect bit wide, will the bit wide fixed value of hlen be set to the binary system significance bit of the maximum hlen values in Huffman code table
Wide.For example, in Fig. 1, the code length of most long Huffman code is 10(I.e. the value of maximum hlen is 10), its binary form is 4 '
B1010, bit wide are 4, and therefore, during coding and decoding, the bit wide fixed value of hlen will be arranged to 4.
Hcod in Fig. 3 represents the code value of Huffman code, is represented with binary form, and effective bit wide of different code values can
Can be different.As the bit wide for realizing process hcod in Huffman code coding and decoding must be fixed, accordingly, it would be desirable to will
The bit wide fixed value of hcod is set to the code length of most long Huffman code.For example, in Fig. 1, the code length of most long Huffman code is 10, because
This, needs for the bit wide fixed value of hcod to be set to 10.
Due to there is the different Huffman code of code length in Huffman code table, therefore, Huffman code table is by each Huffman
The code value of code is showed with corresponding hcod values respectively.So, during the coding of actual Huffman code and decoding, per
The corresponding hcod values of one data are exactly the code value form of expression of the corresponding Huffman code of the data.For the ease of storing and reading
Take, the bit wide fixed value of hcod first can be set to the code length of most long Huffman code, be then directed to any one Huffman code,
In storage, the code value of any one Huffman code is inserted the right of corresponding hcod successively according to the order from a high position to low level
Answer in position, if the code length of any one Huffman code is unable to reach the bit wide fixed value of hcod, need by this
After the code value of one Huffman code of meaning all inserts the high-order portion of corresponding hcod, in the remaining low portion filling of corresponding hcod
0, make the length of the hcod of the Huffman code reach bit wide fixed value.And when any one Huffman code is read, then can be with root
According to the code length that the corresponding hlen values of the Huffman code determine the Huffman code, so that it is determined that in hcod from highest order to hlen
Position is the virtual value of the Huffman code, and other place values in hcod are then fillers.
For example, in Fig. 3, the code value of the corresponding Huffman code of the data { 0,2 } of X=0 and Y=2 is 6 ' b00_1010, and Hough
In the table 7 of graceful table the bit wide fixed value of hcod be 10, therefore, the corresponding hcod values of the data be 6 ' b00_1010,4 '
B0000 }, its first 6 is effective code value, and 4 is filling content afterwards.
According to the principle of compositionality of the generating mode and Huffman code of binary tree, can be by 7 weight of Huffman code table table in Fig. 3
The form being encoded in table 1 below(Table 1 is binary tree code table).
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 checks that order is that first from top to bottom then from left to right, wherein, the Huffman code that underscore is marked is middle
The corresponding Huffman code of node, the Huffman code for not marking underscore are the corresponding Huffman codes of end-node.
There are 34 intermediate nodes, 36 end-nodes, intermediate node quantity to be close to end-node in the corresponding complete binary tree of table 1
Quantity, wherein, the corresponding Huffman code of end-node has decoded result, and the corresponding Huffman code of intermediate node does not have decoding
As a result.If the information unification of intermediate node and end-node is stored, then the memory space of occupancy can be closer to actual decoding
As a result the twice for taking up room, so not storing the corresponding Huffman code of intermediate node in the embodiment of the present invention, only stores minor details
The corresponding Huffman code of point, as such, it is possible to greatly reduce the occupancy of memory space, saves system resource.
In the embodiment of the present invention, the Huffman code of each end-node corresponding in above-mentioned binary tree code table is stored successively each
The preferably mode of corresponding decoded result is:Corresponding Huffman code is distinguished according to each end-node in above-mentioned binary tree code table
Code length from short to long, code value order from small to large, store corresponding decoded result, that is to say, that by the above-mentioned y-bend scion
The each self-corresponding decoded result of the Huffman code of each end-node corresponding in table, the code length according to corresponding Huffman code is by being short to
Long order arrangement, wherein, by the code length identical decoded result of corresponding Huffman code, according to corresponding Huffman code code value by
Little sorted to big order successively.Below by each for the Huffman code of each end-node corresponding in table 1 self-corresponding decoded result
Storage mode according to table 2 below is stored.In practical application, the code value of the Huffman code in table 2 can not be stored, directly according to
Storage address in table 2 stores corresponding decoded result.
Table 2
Huffman code code value |
Storage 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 for providing in the explanation embodiment of the present invention below.In this course, first can judge
In above-mentioned binary tree code table, each self-corresponding node of each Huffman code is end-node or intermediate node, that is, know above-mentioned two
The corresponding node type value of each Huffman code in fork scion table(If the corresponding node of Huffman code is intermediate node, the Kazakhstan
The node type value of the graceful code of husband is exactly 1;If the corresponding node of Huffman code is end-node, the node type value of the Huffman code is just
It is 0).Due to there is the code length of multiple Huffman codes identical in binary tree code table, therefore, same code length is likely to correspondingly multiple
Some Huffman codes, the node type coding of some code length, then contain the corresponding all Huffman codes of the code length each right
The node type value that answers.
Said process is aiming at the code length of each Huffman code and carries out the process of node type coding.
It is preferred that can according to the code length of Huffman code in above-mentioned binary tree code table sequential storage from short to long each
The node type coding of code length, wherein, the node type coding of any one code length contains any one code length described and corresponds to
The each self-corresponding node type value of all Huffman codes.
That is, the node type value of each node that any one code length can be included, according to respective nodes pair
The order that the code value of the Huffman code that answers is descending is arranged in order, and the node type as any one code length is encoded.This
Sample, in the node type coding of any one Huffman code code length, a high position is the corresponding node of the higher Huffman code of code value
Types value, low level are the corresponding node type values of the relatively low Huffman code of code value.Each in above-mentioned binary tree code table is stored
When the node type of the code length of individual Huffman code becomes, then sequential storage that can be according to the code length of Huffman code from short to long.
If the code length for representing Huffman code with hlen, the code value for representing Huffman code with hcod represents each Kazakhstan with T
The node type value of the graceful code of husband(The T values of intermediate node are 1, and the T values of end-node are 0), then, the corresponding nodes of each hlen
Type coding is then:By the T values of corresponding for each hlen all Huffman codes, according to descending suitable of corresponding hcod values
Obtain after sequence arrangement.
For example, in table 1, code length is that 3 Huffman code has 4, respectively 011,010,001 and 000, wherein, front two
It is end-node that individual Huffman code is corresponding, and it is intermediate node that latter two Huffman code is corresponding, so, the node type of code length 3
Coding is 4 ' b0011.
After in table 1, all of Huffman code is encoded according to node type, just can be with binary form list
Obtain Table 3 below:
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 |
Due to the quantity difference of the corresponding Huffman code of each code length, therefore, the length of the node type coding of each code length
Difference, during realization, needs for the bit wide of each node type coding to be set to fixed value.In actual applications, typically
Store by the way of by a node type code storage a to reference address, in order to reduce memory space, can also be right
Part of nodes type coding is merged, then by merging after node type code storage in a reference address.Entering
When row merges, it would be desirable to code length order arrangement from large to small of each node type coding of merging according to corresponding Huffman code.
So, in the node type coded combination after merging, the code value that the high-order node type for larger code length is encoded, low level is less
The code value of the node type coding of code length.
Table 4 below is referred to, the node type coding of code length 1 in table 3 to code length 4 is merged, by code length 9 in table 3
Merge with the node type coding of code length 10.
Table 4
Storage 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, will connect before the data to be decoded being currently received and this
The data to be decoded that receives merge, and used as current Huffman code, wherein, the data to be decoded that this is currently received are the current Hough
The lowest order of graceful code, the data to be decoded for receiving for the first time are the highest order of the current Huffman code.
In practical application, the Huffman code of MP3 audio protocols is input in the form of data flow, is once input into one digit number
According to, and the order of each data input to be decoded that each Huffman code includes, be corresponding in turn to is corresponding Huffman code
A high position to low level.Above-mentioned rule, corresponding be Huffman code itself principle of compositionality, i.e., Huffman code by a high position to low level
Each place value, respectively correspondingly in binary tree corresponding root node to end-node.
Step 103:Encoded in specified node type according to the corresponding node type value of the highest order of current Huffman code
In position offset, the decoded result storage address that current Huffman code is obtained using iterative manner, and therefrom read decoding
As a result, wherein, it is intended that node type coding include each self-corresponding node type of the corresponding all Huffman codes of most short code length
Value.
The above-mentioned node type coding that specifies just refers to the corresponding node type coding of most short code length, i.e., code length 1 is corresponding
Node type coding 01.
Step 104:Using the decoded result of above-mentioned current Huffman code as the multi-medium data output for getting.
It is preferred that step 103 can be realized by following processes:
According to position of the corresponding node type value of the highest order of current Huffman code in specified node type coding
Side-play amount, obtains the node type value of the current Huffman code and the decoded result of above-mentioned current Huffman code using iterative manner
Storage address,
In the node type value according to the current Huffman code, judge the corresponding node of the current Huffman code as end-node
When, from the decoded result storage address of the current Huffman code read decoded result, wherein, it is intended that node type coding bag
Include each self-corresponding node type value of the corresponding all Huffman codes of most short code length.
This is because the intermediate node of binary tree can generate downwards two adjacent nodes, so what next code length was included
The number of node is the twice of the number of the intermediate node included by current code length, if the node type coding of that is, current code length
Comprising some node type values in, numerical value be 1 node type value sum for N, then the corresponding Huffman of next code length
The sum of code is exactly 2 × N.
And, knowing how in the node type coding of current code length, the Huffman code of some corresponding intermediate node
Node type value position be BIT_N, then can just extrapolate, to should Huffman code node two child nodes each
The position of the node type value of self-corresponding Huffman code, is the BIT_N+0 during the node type of next code length is encoded respectively
And BIT_N+1, wherein, to should two child nodes of node of Huffman code refer to, in binary tree, to should Huffman code
Two adjacent child nodes generating downwards of node.
For example, the node type of code length 5 is encoded to 6 ' 10_1111, in the node class of 5 each Huffman code corresponding of code length
In offset, it is 5 that numerical value is the sum of 1 node type value, and therefore, the number of 6 corresponding Huffman code of code length is 10.It is assumed that
The node type value of the Huffman code of corresponding node a is 1, the bit5 positions in the node type coding of code length 5(I.e. " 6 '
In 10_1111 ", from high-order toward the 5th place value of lower-order digit, " 1 " for indicating mark of emphasis below is the Huffman of corresponding node a
The node type value of code), and the node type coding median in code length 5 is in 1 node type value, corresponding node a
The arrangement position of node type value is bit4 positions.So can just be released according to above-mentioned rule, two sections that node a is generated downwards
The node type value of each self-corresponding Huffman code of point, is located at bit8 positions and bit9 positions that the node type of code length 6 is encoded respectively
On.
Below by taking the table 7 that currently used MP3 audio protocols specify as an example, multimedia number provided in an embodiment of the present invention is described
According to the more excellent implementation of acquisition methods, as shown in figure 4, the flow process of the method includes:
Step 401:Huffman code table table 7 according to specified in MP3 audio protocols, generates the generating mode according to binary tree
The binary tree code table table 1 for being arranged, the order of the binary tree code table 1 by Huffman code according to code length from short to long are arranged
Row, wherein, code length identical Huffman code is arranged according to the ascending order of code value.
Step 402:The Huffman code of each end-node corresponding in storage binary tree code table table 1, its arrangement mode be by
According to code length order arrangement from small to large, wherein, code length identical Huffman code is arranged from small to large according to code value.
Step 403:In storage binary tree code table table 1, the node type of the code length of each Huffman code is encoded successively, its
In, the node class of the corresponding all Huffman codes of any one code length is contained in the node type coding of any one code length
Offset, and its arrangement is according to the descending order of the code value of corresponding Huffman code.
Step 404:To the Huffman code X being input in the form of data flow1X2X3…XnIt is decoded, wherein, n is just whole
Number.
Step 405:Using the decoded result got in step 404 as the multi-medium data output for obtaining.
In practical application, in multi-medium data acquisition process, decoding process that data to be decoded are changed into decoded result
Can be realized by decoder.
It is exemplified below and how is realized by the way of iteration, to the Huffman code being input in the form of data flow
X1X2X3…XnDecoding, wherein, n is positive integer.
From input first data to be decoded from the beginning of, often be input into data to be decoded, will currently data to be decoded and
The data to be decoded recorded before this are incorporated as a Huffman code, then obtain next bit data to be decoded, until sentencing
Break the Huffman code being currently generated corresponding be end-node till.
1st wheel iterative process:
Get input the 1st data X1 to be decoded when, current Huffman code be the 1st data X1 to be decoded, when
Front 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 1 each Huffman code corresponding of code length, numerical value is 1 node type value sum C_V1_
The initial value of 1_ALL=1, i.e. C_V1_N_ALL is 1.
(2)Calculate current Huffman code X1Node type value Huffman code code code length 1 node type coding in
Position C_P, C_P=P_P_V1+IN.
Now, without 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 value IN=1 of the data to be decoded of input, C_P=2, if the data to be decoded of input
Value IN=0, then C_P=1.
(3)The number C_V0_1_ALL=1 of the node type value that numerical value in the node type coding of code length 1 is 0 is obtained, i.e.,
The initial value of C_V0_N_ALL is 1.
(4)The extreme higher position C_P_V1=0 of the node type value that numerical value in the node type coding of code length 1 is 1 is obtained, i.e.,
The initial value of C_P_V1 is 0.
(5)Calculate 2 corresponding Huffman code sum 2_ALL=2*C_V1_1_ALL=2 of code length.
(6)Calculate the reference address ADDR_CODE_2 of 2 corresponding node type of code length coding.
The reference address ADDR_CODE_1=0 of 1 corresponding node type of code length coding.
Because, ADDR_CODE_1_UPDATE=0, so, C_ALL_CAL=1_ALL_CAL, and 1_ALL_CAL=2, that
, 2_ALL_CAL=C_ALL_CAL+N_ALL=2+2=4.As default CODE_WIDTH is 14, so, 2_ALL_CAL ratios
CODE_WIDTH is little, so, without accessing next reference address, now, ADDR_CODE_2=0.
(7)Content RD_CODE_1 stored in the reference address for reading the node type coding of code length 1.
RD_CODE_1=BUFFER_CODE[ADDR_CODE_1]
(8)The node type for calculating code length 2 encodes original position 2_ADDR_S in RD_CODE_2.
As now ADDR_CODE_1_UPDATE is 0,
So, 2_ADDR_S=1_ADDR_S+C_ALL=0+2=2, i.e., in current accessed address, the original position of code length 1
It is 0, original position 2_ADDR_S=2 of code length 2.
(9)Calculate the end position 2_ADDR_E of the node type coding of code length 2.
The initial value of N_ADDR_E is 1, i.e. 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)The node type coding CODE_N of code length 2 is read, the original position encoded from the node type of code length 2 reads
Arrive 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 corresponding minimum Huffman code of budget code length 2.
As at address 0, therefore 1 corresponding first decoded result of code length is stored in, ADDR_DATA_HEAD_N's is first
Initial value 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 is calculated, the i.e. sum of 1 corresponding Huffman code of code length,
C_V1_1_ALL be code length 1 node type coding in numerical value be 1 node type value number.
(12)According to RD_CODE_1 and C_P, judge whether CODE_C [C_P] is 0, be if so, directly entered next step
(13), otherwise, enter the 2nd and take turns iterative process.
(13)Calculate X1The reference address ADDR_DATA of decoded result.
ADDR_DATA=C_V0_1_ALL-1+ADDR_DATA_HEAD_C=1-1+1=1.
2nd wheel iterative process is as follows:
Get input the 2nd data X2 to be decoded when, current Huffman code is X1X2, current code length i=2, Hough
Graceful code X1It is and Huffman code X1X2The corresponding Huffman code of an associated upper code length.
(1)It is 1 to obtain numerical value in the node type coding of code length 2 according to the CODE_2 read in last round of iterative process
The number C_V1_2_ALL=2 of node type value.
Results of the C_V1_N_ALL for all place values additions of CODE_C.
(2)Calculate current Huffman code X1X2Node type value code length 2 node type coding in position C_P.
C_P_V1, P_P_V1=0 that the value of P_P_V1 is calculated when being 1 equal to code length,
C_P=P_P_V1+IN=0+X2
(3)The number C_V0_2_ALL of the 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, will be after CODE_2 negates, will
Result after each place value addition that coding of the inverted includes.
(4)Obtain the extreme higher position C_P_V1=CODE_ of the node type value that numerical value in the node type coding of code length 2 is 1
C[C_P:0] the result -1 after all place values additions.
(5)Calculate node total number 3_ALL=2*C_V1_2_ALL=4 that Huffman code code length 3 includes.
(6)Calculate the reference address ADDR_CODE_3=ADDR_ of 3 corresponding node type coding of Huffman code code length
CODE_2+ADDR_CODE_2_UPDATE.
Whether ADDR_CODE_2=2, judge N_ALL_CAL 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, judges whether ADDR_CODE_C_UPDATE is 1, if so, C_ALL_
CAL=C_ALL, C_ALL are the N_ALL calculated in last round of iterative process, otherwise, in the last round of iterative process of C_ALL_CAL=
The N_ALL_CAL values for calculating, ADDR_CODE_2_UPDATE=0.
Because, the last round of ADDR_CODE_2_UPDATE=0 for calculating, so, 3_ALL_CAL=2_ALL_CAL+2_
ALL=4+2=6.Due to 3_ALL_CAL less than CODE_WIDTH, so without accessing next reference address, ADDR_CODE_2_
UPDATE=0.
(7)Read storage content RD_CODE_2 of BUFFR_CODE.
RD_CODE_2=BUFFER_CODE[ADDR_CODE_2]
(8)The node type for calculating code length 3 encodes original 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,
That is the original position that the node type of code length 3 is encoded in the reference address that epicycle is calculated is 4.
(9)Calculate the end position 3_ADDR_E of the node type coding of code length 3.
3_ADDR_E=3_ADDR_S+4_ALL-1=4+4-1=7.
(10)According to original position and the end position of the node type of the code length 3 for calculating coding, the section of code length 3 is read
Vertex type encodes CODE_3=RD_CODE_3 [3_ADDR_E:3_ADDR_S].
(11)The decoded result reference address ADDR_DATA_HEAD_3=of the corresponding minimum Huffman code of budget code length 3
ADDR_DATA_HEAD_2+C_ALL-C_V1_2_ALL=1+2-2=1.
(12)According to RD_CODE_2 and C_P, CODE_C [C_P] is judged as 0, enter the 3rd and take turns iterative process.
In the Huffman table table 7 that MP3 audio protocols specify, it is all middle node that code length is the 2 corresponding node of Huffman code
, there is no corresponding decoded result in point.
N takes turns iterative process:
During n-th data Xn to be decoded of input, current Huffman code is X1X2X3…Xn, current Huffman code code length i=N.
(1)According to the node type coding interior joint class that the CODE_N-1 read in last round of iterative process calculates code length N
Offset is 1 node total number C_V1_N_ALL.
Results of the C_V1_N_ALL for all place values additions of CODE_C.
(2)Calculate current Huffman code X1X2X3…XnNode type value code length N node type coding in position
C_P.
C_P={ P_P_V1, IN }, wherein P_P_V1 are calculated C_P_V1 in last round of iterative process, and IN is current
The value of the data to be decoded of input.
That is the C_P_V1+X of the last round of acquisitions 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 0 node type value.
C_V0_N_ALL=(~CODE_C [C_P:0])The result that is added of all place values, will be during position C_P be set to 0 in place
The coding of storage is negated, then by the result after each place value addition for encoding and including of the inverted.
In this manner it is possible to calculate the node type coding of current code length in the step of afterwards according to C_V0_N_ALL
In, the distance between lowest order of the position C_P of the node type value of current Huffman code to the node type value, because, per
Each node type value that the node type coding of one code length includes all is descending according to the code value of corresponding Huffman code
Tactic.
(4)Obtain the extreme higher position C_P_V1=CODE_ of the node type value that numerical value in the node type coding of code length N is 1
C[C_P:0] all place values be added after result -1, will position C_P set to 0 in place middle storage coding all place value phases
Plus.
(5)The total N_ALL=2*C_V1_N+1_ALL of the corresponding Huffman code of budget code length N+1.
The sum of the corresponding Huffman code of code length N+1, equal to the node type node type value that includes of coding of code length N+1
Sum.
(6)The reference address ADDR_CODE_N+1=ADDR_CODE_N+ of the corresponding node type coding of budget code length N+1
ADDR_CODE_N_UPDATE.
Due in order to save memory space, employing 4 corresponding storage mode memory node type coding of table, therefore, one
Individual reference address(That is memory cell)In might have stored one or more code lengths node type coding, accordingly, it would be desirable to judge
Whether the reference address of the node type coding of current code length needs to update, in addition it is also necessary to which the node type of budget next one code length is compiled
Code position in the memory unit.
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 that a reference address can in the reference address of node type coding
The preset maximum value of the number of memory node types value.
N_ALL_CAL=C_ALL_CAL+N_ALL, judges whether ADDR_CODE_C_UPDATE is 1, if so, C_ALL_
CAL=C_ALL, wherein, C_ALL is the N_ALL calculated in last round of iterative process, otherwise, the last round of iteration mistakes of C_ALL_CAL=
The N_ALL_CAL values calculated in journey.
(7)Read storage content RD_CODE_N of BUFFR_CODE.
RD_CODE_N=BUFFER_CODE[ADDR_CODE_N]
(8)The node type of budget code length N+1 encodes original position N+1_ADDR_S in RD_CODE_N+1.
Judge whether the ADDR_CODE_N_UPDATE calculated in epicycle iterative process is equal to 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)According to original position and the end position that the node type of code length N is encoded is calculated before, code length N+1 is read
Node type coding CODE_N+1=RD_CODE_N+1 [N+1_ADDR_E:N_ADDR_S].
(11)The decoded result reference address ADDR_DATA_HEAD_N+1 of the corresponding minimum Huffman code of budget code length N+1
=ADDR_DATA_HEAD_N+C_ALL-C_V1_N_ALL, wherein C_ALL are the sums of the corresponding Huffman code of code length N, C_V1_
N_ALL be code length N node type coding in numerical value be 1 node type value number.
(12)According to RD_CODE_N and C_P, judge whether CODE_C [C_P] is 1, if so, continue next round iteration mistake
Journey, otherwise, execution step(13).
(13)ADDR_DATA=C_V0_N_ALL-1+ADDR_DATA_HEAD_N-1, wherein, ADDR_DATA_HEAD_N-1
It is the corresponding decoded result reference address of minimum Huffman code that code length N calculated in last round of iterative process includes.
Above-mentioned iterative process goes to CODE_C [C_P] always for 0, reads out the reference address of decoded result, and therefrom
Till getting decoded result.
Table 5 below illustrates the Kazakhstan of the table 7 of the Huffman code table specified based on MP3 audio protocols in the form of code
The decoding operate flow process of the graceful code of husband, it is assumed that the code value of a Huffman code to be input into is 00000110, corresponding decoding data
Middle X is 0 for 5 and Y.
1st step, generates a binary tree code table as shown in table 1.
2nd step, as shown in table 2, decoding 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, is successively read each place value of the Huffman code of input, and executes iterative process according to table 5, until solution
Go out decoded result.
Table 5
Same offer thinking is based on, the embodiment of the present invention additionally provides a kind of multi-medium data acquisition device, refering to Fig. 5 institutes
Show, including:
Recodification module 501, is binary tree code table for currently used Huffman code table is recoded;
Memory module 502, the Huffman code for storing each end-node corresponding in above-mentioned binary tree code table successively are each
Self-corresponding decoded result, and store the node type of the code length of each Huffman code in above-mentioned binary tree code table successively and compile
Code;
Merging module 503, for often receiving during data to be decoded, by the data to be decoded being currently received and originally
The data to be decoded received before secondary merge, and as current Huffman code, wherein, the above-mentioned data to be decoded that are currently received are
The lowest order of above-mentioned current Huffman code, the data to be decoded for receiving for the first time are the highest order of above-mentioned current Huffman code;
Acquisition module 504, for the corresponding node type value of highest order according to above-mentioned current Huffman code specified
Position offset in node type coding, the storage that above-mentioned current Huffman code decoded result is obtained using iterative manner
Location, and read above-mentioned current Huffman code decoded result from the storage address, wherein, it is intended that node type coding include most
The each self-corresponding node type value of the corresponding all Huffman codes of short code length;And the decoded result by the current Huffman code
As the multi-medium data output for getting.
Said apparatus are one-to-one with method flow, will not be described here.
Huffman code table is recoded into binary tree code table using the design feature of Huffman code by the embodiment of the present invention, is tied
The characteristics of data to be decoded are input in the form of data flow when Huffman code is decoded is closed, is compiled using the node type of each code length
Corresponding relation in code and binary tree code table and between the decoded result storage address of end-node each Huffman code corresponding, passes through
The mode of iteration, calculates the storage address of the decoded result of the Huffman code to be decoded of corresponding end-node, therefrom obtains Hough
Graceful code decoded result, larger with the storage capacity requirement for solving the coding/decoding method of Huffman code in prior art, system resource disappears
The more problem of consumption.
The present invention is with reference to method according to embodiments of the present invention, equipment(System), and computer program flow process
Figure and/or block diagram are describing.It should be understood that can be by computer program instructions flowchart and/or each stream in block diagram
Journey and/or the combination of square frame and flow chart and/or the flow process in block diagram and/or square frame.These computer programs can be provided
Instruct the processor of all-purpose computer, special-purpose computer, Embedded Processor or other programmable data processing devices to produce
A raw machine so that produced for reality by the instruction of computer or the computing device of other programmable data processing devices
The device of the function of specifying in present one flow process of flow chart or one square frame of multiple flow processs and/or block diagram or multiple square frames.
These computer program instructions may be alternatively stored in and can guide computer or other programmable data processing devices with spy
Determine in the computer-readable memory that mode works so that the instruction being stored in the computer-readable memory is produced to be included referring to
Make the manufacture of device, the command device realize in one flow process of flow chart or one square frame of multiple flow processs and/or block diagram or
The function of specifying in multiple square frames.
These computer program instructions can be also loaded in computer or other programmable data processing devices so that in meter
Series of operation steps is executed on calculation machine or other programmable devices to produce computer implemented process, so as in computer or
The instruction executed on other programmable devices is provided for realization in one flow process of flow chart or multiple flow processs and/or block diagram one
The step of function of specifying in individual square frame or multiple square frames.
, but those skilled in the art once know basic creation although preferred embodiments of the present invention have been described
Property concept, then can make other change and modification to these embodiments.So, claims are intended to be construed to include excellent
Select embodiment and fall into the had altered of the scope of the invention and change.
Obviously, those skilled in the art can carry out various changes and modification without deviating from this to the embodiment of the present invention
The spirit and scope of bright embodiment.So, if these modifications of the embodiment of the present invention and modification belong to the claims in the present invention
And its within the scope of equivalent technologies, then the present invention is also intended to comprising these changes and modification.