A variable word length code decoding method, and a decoder for performing the same

Abstract: At least two code tables are used to decode a variable word length code sequence. A first code table (41) stores code information of variable word length codes having code lengths shorter than or equal to 8 bits. In addresses of the first code table (41) corresponding to longer variable word length code than 8 bits, data is stored indicative of longer codes than 8 bits. At first, the first code table is accessed. If the data being read from the first code table (41) indicates a code length not more than 8 bits, an input variable word length code is identified and decoded. If the data being read from the first code table indicates a code length longer than 8 bits, the second code table (42) is accessed and the input variable word length code is identified and decoded.

Description: The invention relates to a variable word length code decoding method and apparatus for decoding an input variable word length code sequence, and more particularly relates to a decoding method which decodes the input variable word length code sequence quickly by using relatively small capacity code tables. As is well known in the art, an amount of data to be transmitted or to be stored can be reduced by using a variable word length coding technique. In this technique, a variable word length code set is determined based on a generation probability distribution of symbols to be outputted from an information source. More specifically, shorter length codes are assigned to symbols with higher generation probabilities while longer length codes are assigned to symbols with lower generation probabilities. Thus, the amount of data can be reduced. Three conventional methods are known for decoding the input variable word length code sequence. The first conventional method uses a single code table which stores a binary code tree representing a variable word length code set. In the method, a variable word length code which coincides with a part of the input variable word length code sequence is searched by tracing the binary code tree on a bit-by-bit basis. The second conventional method uses another type of code table which stores bit patterns of variable word length codes and the corresponding decoded values. In that method, each variable word length code stored in the code table is compared with the input variable word length code sequence on a code-by-code basis. The third conventional method uses still another type of code table having addresses that represent data associated with bit patterns of variable word length codes and which stores a decoded value and a code length in the corresponding address. In that table, the required number of address bits corresponds to the maximum code length in a variable word length code set. The third conventional method is described, for example, in U.S. patent 4,509,038. However, the conventional methods have the following disadvantages. The first conventional method requires a long decoding time because the method performs bit-by-bit operations. The second conventional method also requires a long decoding time because each code in the table is compared code-by-code with the input sequence. The third method, on the other hand, requires a huge capacity memory though the method requires a short decoding time. It is therefore a principal object of the invention to provide a variable word length code decoding method and apparatus which decode a variable word length code sequence quickly by using relatively small capacity tables. According to the invention, there is provided a variable word length code decoding method for decoding an input variable word length code sequence, comprising the steps of: (A) storing first N bits of an undecoded variable word length code sequence into a first register; (B) generating a first value by shifting rightward a value of the first register by N-n 1 bits, wherein n 1 is less than N, and storing the first value into a second register; (C) reading a first code table based on an address which is indicated by the second register, wherein addresses of the first code table either represent first data associated with variable word length codes which belong to a first group of a variable word length code set having code lengths less than or equal to n 1 or represent first remaining data; the first code table stores a decoded value and a code length in each address corresponding to the first data; and the first code table stores data representing a code length longer than n 1 in each address corresponding to the first remaining data; (D) proceeding to the next step (E) if a code length read in the step (C) is longer than n 1 , otherwise proceeding to the following step (G); (E) generating a second value by changing the first m 1 bits of the value of the first register to zero values, wherein m 1 is less than n 1 , and by shifting rightwards the changed value by ( N-n 1 -m 1 ) bits and storing the second value into the second register; (F) reading a second code table based on an address indicated by the second register, wherein addresses of the second code table represent second data associated with variable word length codes which belong to a second group of the variable word length code set, the code lengths of which are longer than n 1 and the first m 1 bits of which are removed; and the second code table stores a decoded value and a code length in each address corresponding to said second data; (G) outputting a decoded value read in the step (C) or the step (F) to an output memory and returning to said step (A). The invention also provides a decoder for performing the above method. BRIEF DESCRIPTION OF THE DRAWINGS Figure 1 shows a block diagram of an apparatus which performs the invention; Figure 2A shows a first group of a variable word length code set used in preferred embodiments; Figure 2B shows a second group of the variable word length code set used in the preferred embodiments; Figure 2C shows a third group of the variable word length code set used in a second preferred embodiment; Figure 3A shows contents of a first code table 41 in Fig. 1; Figure 3B shows contents of a second code table 42 in Fig. 1; Figure 3C shows contents of a third code table 43 in Fig. 1; Figure 4 shows a flow chart indicating operations of a CPU 20 of Fig. 1 in the first preferred embodiment. Figures 5A and 5B show flow charts indicating operations of a CPU 20 of Fig. 1 in the second preferred embodiment. DETAILED DESCRIPTION OF PREFERRED EMBODIMENTS Fig. 1 shows a block diagram of an apparatus which performs the invention. The apparatus comprises an input memory 10 connected to a bus 30 for temporarily storing an input variable word length code sequence 1; a central processing unit (CPU) 20 being connected to the bus 30 and including three registers (VD, ADRS and RADR) for performing operations which will be described later; first to third code tables 41-43 connected to the bus 30 for storing first to third groups of variable word length code information, respectively; and an output memory 50 connected to the bus 30 for temporarily storing decoded values decoded by a combination of CPU 20 and first to third code tables 41-43 and outputting the decoded values to an external apparatus (not shown) via line 2. Before further describing preferred embodiments of the invention, a variable word length code set used in these embodiments will first be described. Figs. 2A and 2B show respectively an example of a first group and a second group of variable word length codes of a variable word length code set used in the first preferred embodiment of the invention while Figs. 2A, 2B and 2C show respectively an example of a first to third group of variable word length codes of a variable word length code set used in the second preferred embodiment of the invention. As shown in Figs. 2A and 2B, the first group of the variable word length code set consists of codes which have code lengths (l 1 ) not more than 8, (i.e., n 1 =8) and the second group consists of codes which have code lengths (l 2 ) greater than n 1 and not more than 12 (i.e., n 2 =12). In addition to the variable word length code set in the first embodiment, a variable word length code set in the second embodiment further includes the third group of codes which have code lengths (l 3 ) longer than n 2 (=12) and not longer than N(=16) as shown in Fig. 2C. In addition, it should be noted that first m 1 (=4) bits of the second group codes are common to each other (see Fig. 2B) and that first m 2 (=8) bits of the third group codes are common to each other (see Fig. 2C). Since the present invention features internal embodiments of code tables, the internal embodiments of the code tables are explained next. Figs. 3A to 3C show a first to third code table 41-43, respectively. In Figs. 3A to 3C, "X" indicates either bit value "0" or "1". As is clear from a comparison of Fig. 2A and Fig. 3A, addresses of the first code table represent first data associated with the first group codes. In other words, each of first data belongs to an n 1 (=8) length bit pattern set consisting of each of l 1 length first group codes and each of (n 1 - l 1 ) length arbitrary bit patterns. In each address corresponding to the first data, a code length and a decoded value of the corresponding variable word length code is stored. In addresses not corresponding to the first data ("THE OTHERS" in Fig. 3A), a code length longer than n 1 (=8) is stored therein. It should be noted that Fig. 3A is substantially the same as the code table of the third conventional method except for "THE OTHERS" addresses in Fig. 3A. In the second code table of Fig. 3B, addresses represent second data associated with the second group codes in which first m 1 (=4) bits are removed. In other words, each of the second data belongs to an (n 2 - m 1 ) length bit pattern set consisting of each of (l 2 - m 1 ) length bit patterns and each of (n 2 - l 2 ) length arbitrary bit patterns, and each (l 2 - m 1 ) length bit pattern is formed by removing the first m 1 bits from each of the second group codes. The reason for the removal of the first m 1 bits is that these bits can be identified in the first code table. In addresses indicated by "1111 1XXX" which may correspond to third group codes, a code length longer than n 2 (=12) is stored therein. In addition, addresses indicated by "0XXX XXXX" are not used because these addresses do not correspond to any variable word length codes. In the third code table of Fig. 3C, addresses represent third data associated with the third group codes, the first m 2 (=8) bits of which are removed. In other words, each of the third data belongs to an (N-m 2 ) length bit pattern set consisting of each of (l 3 - m 2 ) length bit patterns and each of (N-l 3 ) length arbitrary bit patterns, and each (l 3 - m 2 ) length bit pattern is formed by removing the first m 2 bits from each of the third group variable word length codes. The reason for the removal of the first m 2 bits is that these bits can be identified in the first and second code tables. In the third code table, addresses indicated by "THE OTHERS" are not used because these addresses do not correspond to any variable word length codes. Next, referring to Fig. 4, a preferred embodiment of the invention is hereinafter described. Fig. 4 is a flow chart indicating a process of the CPU 20 in the first embodiment. It should be noted that the third code table 43 is not necessary in the first embodiment because a variable word length code set of the first embodiment consists of the group 1 codes and the group 2 codes. In step S1, first N(=16) bit data of an undecoded variable word length code sequence, a top address of which is identified by the register RADR, are read out from the input memory 10 to the register VD via the bus 30. In step S2, a value of the register VD is read out and shifted rightward by (N-n 1 ) bits, or 8 bits. Thus, an address data of the first code table 41 corresponding to an input variable word length code is generated. The address data is stored in the register ADRS. In step S3, the CPU 20 accesses the first code table, an address of which is indicated by the register ADRS, and reads out a code length and a decoded value in the address. In step S4, the CPU 20 compares the code length being read in the step S3 with n 1 (=8), or the maximum code length among the first group codes. If the code length is shorter than or equal to n 1 , the process of the CPU 20 proceeds to step S7. This comparison result indicates that a variable word length code of the first group is identified. If the code length being read in the step S3 is longer than 8, the process of the CPU 20 proceeds to step S5. This comparison result indicates that one of a longer variable word length code than n 1 (=8) bits is inputted though it is not identified yet. Therefore, the CPU 20 must access the second code table 42. In step S5, the CPU 20 shifts rightward a value read from the register VD by (N-n 1 -m 1 ) bits, or 4 bits and masks the shifted value by a hexadecimal number (00FF) 16 (=0000 0000 1111 1111) to generate a masked data, which is the second data associated with the second code groups codes, the first m 1 (=4) bits of which are removed. The second data is stored in the register ADRS. In step S6, the CPU 20 accesses the second code table 42, an address of which is identified by the register ADRS, and reads out a code length and a decoded value in the address. Thus, a variable word length code of the second group is identified. In step S7, the register RADR is incremented by the code length being read in step S3 or step S5. The new value of the register RADR indicates an address of the input memory where a first bit of an undecoded variable word length code sequence is stored. In step S8, the CPU 20 transfers the decoded value being read in step S3 or step S5 to the output memory 50, which is read out by an external circuit (not shown) via line 2. After completing this operation, the process of the CPU 20 returns to step S1 and starts to decode a next variable word length code. The first preferred embodiment of the invention decodes an input variable word length code sequence quickly because required access frequencies to code tables are at most 2 per a variable word length code. Moreover, the first embodiment does not require a huge capacity of the code table. As is clear from Figs. 3A and 3B, the number of addresses required for the first and second code tables 41, 42 is 2 X 2 8 = 512 addresses. On the other hand, a code table of the third conventional method discussed earlier requires 2 12 (=4096) addresses when the maximum code length of a code set is 12. Next, referring to Figs. 5A and 5B, a second preferred embodiment of the invention will now be described. In the second embodiment, the third group codes listed in Fig. 2C are also inputted therein as the variable word length code sequence. Therefore, the third code table 43, the contents of which are shown in Fig. 3C, is also used in the second embodiment. Figs. 5A and 5B show flow charts indicating the process of the CPU 20 in the second embodiment. Since operations of steps S11, S12, S13, S14, S15, S16, S20 and S21 are same as those of steps S1, S2, S3, S4, S5, S6, S7 and S8 of the first embodiment, respectively, duplicated explanation will be unnecessary. In step S17, the CPU 20 compares the code length read in the step S16 with n 2 , or the maximum code length among the second group codes (in this embodiment, n 2 is 12). If the code length is less than or equal to n 2 , the process of the CPU 20 proceeds to step S20, which is the same operation as that of the step S7 of Fig. 4. This means a variable word length code of the second group is identified. If the code length being read in the step S16 is longer than n 2 , the process of the CPU 20 proceeds to step S18. This comparison result indicates that a variable word length code longer than n 2 is inputted through it and has not yet been identified. Therefore, the CPU 20 has to access the third code table 42. In step S18, the CPU 20 masks the value of the register VD by a hexadecimal number (00FF) 16 . By such masking, the CPU 20 changes first m 2 (in the embodiment, m 2 =8) bits of the value to zero values and gets the third data associated with the third group codes, the first m 2 bits of which are removed. Thus, an address data of the third code table is generated. The address data is stored in the register ADRS. In step S19, the CPU 20 accesses the third code table, an address of which is identified by the register ADRS, and reads out a code length and a decoded value in the address. Thus, a variable word length code of the third group is identified. After completing this operation, the process of the CPU 20 proceeds to the step S20. As stated before, explanations on steps S20 and S21 are skipped in order to avoid duplicated explanations. The second preferred embodiment of the invention also decodes an input variable word length code sequence quickly because required access frequencies to code tables are at most 3 per a variable word length code. The second preferred embodiment also does not require a huge capacity of a code table. As is clear from Figs. 3A, 3B and 3C, the number of addresses required to the first-to-third code table 41-43 is 3 X 2 8 = 768 addresses. On the other hand, a code table of the third conventional method discussed earlier requires 2 16 (=65536) addresses when the maximum code length of a code set is 16. As is described in detail, the invention provides a variable word length code decoding method which decodes a variable word length code sequence quickly by using code tables with relatively small capacity.

Claims: A variable word length code decoding method for decoding an input variable word length code sequence, comprising the steps of: (A) storing first N bits of an undecoded variable word length code sequence of said input variable word length code sequence into a first register; (B) generating a first value by shifting rightward a value being read out from said first register by N-n 1 bits, wherein n 1 is less than N, and storing the first value into a second register; (C) reading a first code table based on an address indicated by said second register, wherein addresses of said first code table either represent first data associated with first group variable word length codes having code lengths (l 1 ) less than or equal to n 1 or represent first remaining data; said first code table stores a decoded value and a code length in each address corresponding to each of said first data; and said first code table also stores data representing a code length larger than n 1 in each address corresponding to the first remaining data; (D) proceeding to next step (E) if a code length being read in said step (C) is longer than n 1 or proceeding to step (G) if not; (E) generating a second value by changing first m 1 bits of the value being read from the first register to zero values, wherein m 1 is less than n 1 , and by shifting rightward the changed value by ( N-n 1 -m 1 ) bits; and storing the second value into said second register; (F) reading a second code table based on an address indicated by said second register, wherein addresses of said second code table represent second data associated with second group variable word length codes having code lengths (l 2 ) longer than n 1 and m 1 bits of which are removed; and said second table stores a decoded value and a code length in each address corresponding to said second data; (G) outputting a decoded value being read in said step (C) or said step (F) to an output memory and returning to said step (A). The variable word length code decoding method, as claimed in claim 1, wherein said first m 1 bits are common to each other in said second group variable word length codes. The variable word length code decoding method, as claimed in claim 1, wherein each of said first data belongs to an n 1 length bit pattern set consisting of each of (l 1 ) length bit patterns of said first group variable word length codes and each of (n 1 -l 1 ) length arbitrary bit patterns; each of said second data is an (n 2 -m 1 ) length bit pattern consisting of each of (l 2 -m 1 ) length bit patterns and each of (n 2 -l 2 ) length arbitrary bit patterns; and each of said (l 2 -m 1 ) length bit patterns is formed by removing first m 1 bits from each of said second group variable word length codes. A variable word length code decoding method for decoding an input variable word length code sequence, comprising the steps of: (A) storing first N bits of an undecoded variable word length code sequence of said input variable word length code sequence into a first register; (B) generating a first value by shifting rightward a value being read out from said first register by N-n 1 bits, wherein n 1 is less than N, and storing the first value into a second register; (C) reading a first code table based on an address indicated by said second register, wherein addresses of said first code table either represent first data associated with first group variable word length codes having code lengths (l 1 ) less than or equal to n 1 or represent first remaining data; said first code table stores a decoded value and a code length in each address corresponding to each of said first data; and said first code table stores data representing a code length larger than n 1 in each address corresponding to the first remaining data; (D) proceeding to next step (E) if a code length being read in said step (C) is longer than n 1 or proceeding to step (G) if not; (E) generating a second value by changing first m 1 bits of the value being read from the first register to zero values, wherein m 1 is less than n 1 , and by shifting rightward the changed value by ( N-n 1 -m 1 ) bits; and storing the second value into said second register; (F) reading a second code table based on an address indicated by said second register, wherein addresses of said second code table either represent second data associated with second group variable word length codes having code lengths l 2 longer than n 1 and m 1 bits of which are removed or represent second remaining data; said second table stores a decoded value and a code length in each address corresponding to said second data; and said second table also stores data representing a code length longer than n 2 ; (G) proceeding to next step (H) if a code length being read in said step (F) is longer than n 2 or proceeding to the following step (J) if not; (H) generating a third value by changing first m 2 bits of said value from said first register to zero values and storing said third value into said second register; (I) reading a third code table based on an address indicated by said second register, wherein addresses of said third code table represent third data associated with third group variable word length codes having code lengths l 3 longer than n 2 and first m 2 bits of which are removed; said third code table stores a decoded value and a code length in each address corresponding to said third data; and (J) outputting a decoded value being read in said step (C), said step (F) or said step (I) to an output memory and returning to said step (A). The variable word length code decoding method as claimed in claim 4, wherein said first m 1 bits are common to each other in said second group variable word length codes; and said first m 2 bits are common to each other in said third group variable word length codes. The variable word length code decoding method, as claimed in claim 5, wherein each of said first data belongs to an n 1 length bit pattern set consisting of each of l 1 length bit patterns of said first group variable word length codes and each of (n 1 -l 1 ) length arbitrary bit patterns; each of said second data is an (n 2 -m 1 ) length bit pattern consisting of each of (l 2 -m 1 ) length bit patterns and each of (n 2 -l 2 ) length arbitrary bit patterns; each of said (l 2 -m 1 ) length bit patterns is formed by removing first m 1 bits from each of the second group variable length codes; each of said third data belong to an (N-m 2 ) length bit pattern set consisting of each of (l 3 -m 2 ) length bit patterns and each of (N-l 3 ) length arbitrary bit patterns; and each of said (l 3 -m 2 ) length bit pattern is formed by removing first m 2 bit from each of the third group variable word length codes. A variable word length code decoder for decoding an input variable word length code sequence, comprising: (A) means for storing first N bits of an undecoded variable word length code sequence of said input variable word length code sequence into a first register; (B) means for generating a first value by shifting rightward a value being read out from said first register by N-n 1 bits, wherein n 1 is less than N, and storing the first value into a second register; (C) means for reading a first code table based on an address indicated by said second register, wherein addresses of said first code table either represent first data associated with first group variable word length codes having code lengths (l 1 ) less than or equal to n 1 or represent first remaining data; said first code table stores a decoded value and a code length in each address corresponding to each of said first data; and said first code table also stores data representing a code length larger than n 1 in each address corresponding to the first remaining data; (D) means for generating a second value by changing first m, bits of the value being read from the first register to zero values, wherein m 1 is less than n 1 , and by shifting rightward the changed value by (N-n 1 -m 1 ) bits; and storing the second value into said second register; (E) means for reading a second code table based on an address indicated by said second register, wherein addresses of said second code table represent second data associated with second group variable word length codes having code lengths (l 2 ) longer than n 1 and m 1 bits of which are removed; and said second table stores a decoded value and a code length in each address corresponding to said second data; (F) means for outputtting a decoded value being read by said means (C) or said means (E) to an output memory. The variable word length code decoder, as claimed in claim 7, wherein said first m 1 bits are common to each other in said second group variable word length codes. The variable word length code decoder, as claimed in claim 7, wherein each of said first data belongs to an n 1 length bit pattern set consisting of each of (l 1 ) length bit patterns of said first group variable word length codes and each of (n 1 -l 1 ) length arbitrary bit patterns; each of said second data is an (n 2 -m 1 ) length bit pattern consisting of each of (l 2 -m 1 ) length bit patterns and each of (n 2 -l 2 ) length arbitrary bit patterns; and each of said (l 2 -m 1 ) length bit patterns is formed by removing first m 1 bits from each of said second group variable word length codes. A variable word length code decoder for decoding an input variable word length code sequence, comprising: (A) means for storing first N bits of an undecoded variable word length code sequence of said input variable word length code sequence into a first register; (B) means for generating a first value by shifting rightward a value being read out from said first register by N-n 1 bits, wherein n 1 is less than N, and storing the first value into a second register; (C) means for reading a first code table based on an address indicated by said second register, wherein addresses of said first code table either represent first data associated with first group variable word length codes having code lengths (l 1 ) less than or equal to n 1 or represent first remaining data; said first code table stores a decoded value and a code length in each address corresponding to each of said first data; and said first code table stores data representing a code length larger than n 1 in each address corresponding to the first remaining data; (D) means for generating a second value by changing first m 1 bits of the value being read from the first register to zero values, wherein m 1 is less than n 1 , and by shifting rightward the changed value by ( N-n 1 -m 1 ) bits; and storing the second value into said second register; (E) means for reading a second code table based on an address indicated by said second register, wherein addresses of said second code table either represent second data associated with second group variable word length codes having code lengths l 2 longer than n 1 and m 1 bits of which are removed or represent second remaining data; said second table stores a decoded value and a code length in each address corresponding to said second data; and said second table also stores data representing a code length longer than n 2 ; (F) means for generating a third value by changing first m 2 bits of said value from said first register to zero values and storing said third value into said second register; (G) means for reading a third code table based on an address indicated by said second register, wherein addresses of said third code table represent third data associated with third group variable word length codes having code lengths l 3 longer than n 2 and first m 2 bits of which are removed; said third code table stores a decoded value and a code length in each address corresponding to said third data; and (H) means for outputting a decoded value being read by said means (C), said means (E) or said means (G) to an output memory. The variable word length code decoder as claimed in claim 10, wherein said first m 1 bits are common to each other in said second group variable word length codes; and said first m 2 bits are common to each other in said third group variable word length codes. The variable word length code decoder, as claimed in claim 11, wherein each of said first data belongs to an n 1 length bit pattern set consisting of each of l 1 length bit patterns of said first group variable word length codes and each of (n 1 -l 1 ) length arbitrary bit patterns; each of said second data is an (n 2 -m 1 ) length bit pattern consisting of each of (l 2 -m 1 ) length bit patterns and each of (n 2 -l 2 ) length arbitrary bit patterns; each of said (l 2 -m 1 ) length bit patterns is formed by removing first m 1 bits from each of the second group variable length codes; each of said third data belong to an (N-m 2 ) length bit pattern set consisting of each of (l 3 -m 2 ) length bit patterns and each of (N-l 3 ) length arbitrary bit patterns: and each of said (l 3 -m 2 ) length bit pattern is formed by removing first m 2 bit from each of the third group variable word length codes.

Inventors: WATANABE MITSUHIRO, WATANABE, MITSUHIRO, WATANABE, MITSUHIRO, C/O NEC CORPORATION
Applicants: NIPPON ELECTRIC CO, NEC CORPORATION
Application year: 1994
Main classification: H03M7
IPC codes: H04N1, H03M7