CN102237878B - A Huffman decoding method - Google Patents
A Huffman decoding method Download PDFInfo
- Publication number
- CN102237878B CN102237878B CN201010151333.6A CN201010151333A CN102237878B CN 102237878 B CN102237878 B CN 102237878B CN 201010151333 A CN201010151333 A CN 201010151333A CN 102237878 B CN102237878 B CN 102237878B
- Authority
- CN
- China
- Prior art keywords
- codeword
- codewords
- specific
- auxiliary
- group
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
- 238000000034 method Methods 0.000 title claims abstract description 129
- 239000003550 marker Substances 0.000 claims description 16
- 230000005540 biological transmission Effects 0.000 abstract 2
- 230000008569 process Effects 0.000 description 48
- 230000006870 function Effects 0.000 description 7
- 238000010586 diagram Methods 0.000 description 6
- 238000013139 quantization Methods 0.000 description 6
- 238000004364 calculation method Methods 0.000 description 3
- 238000001914 filtration Methods 0.000 description 3
- 230000009286 beneficial effect Effects 0.000 description 1
- 230000008859 change Effects 0.000 description 1
- 230000006835 compression Effects 0.000 description 1
- 238000007906 compression Methods 0.000 description 1
- 230000007547 defect Effects 0.000 description 1
- 238000012986 modification Methods 0.000 description 1
- 230000004048 modification Effects 0.000 description 1
Landscapes
- Compression, Expansion, Code Conversion, And Decoders (AREA)
Abstract
Description
技术领域 technical field
本发明涉及霍夫曼解码方法,更具体地说,涉及一种具有较高搜寻速度以使用较少存储器资源的霍夫曼解码方法。 The present invention relates to a Huffman decoding method, more particularly, to a Huffman decoding method with higher search speed and less memory resources.
背景技术 Background technique
霍夫曼码是一种普遍使用于各种标准的压缩技术,例如动态影像专家群先进音讯编码(Moving Picture Experts Group Advanced Audio Coding,MPEGAAC)以及联合影像专家群(Joint Photographic Experts Group,JPEG),且可以大幅地降低音讯或是视讯媒体传输流的大小。然而,因为对音讯以及视讯解码器而言,霍夫曼码是目前计算量最密集的算法之一,因此,霍夫曼码对编码器,尤其是解码器而言会造成计算量上的很大负担。此外,许多的嵌入式系统虽然具有专用解码器,但是可使用的资源以及时钟速率却很有限,因此,这些嵌入式系统必须要使用这些有限的资源(例如有限的存储器空间)来处理霍夫曼码。 Huffman codes are a common compression technique used in various standards, such as Moving Picture Experts Group Advanced Audio Coding (MPEGAAC) and Joint Photographic Experts Group (JPEG), And can greatly reduce the size of the audio or video media transport stream. However, because Huffman codes are currently one of the most computationally intensive algorithms for audio and video decoders, Huffman codes will cause a lot of computation for encoders, especially decoders. Big burden. In addition, although many embedded systems have dedicated decoders, the available resources and clock rate are very limited. Therefore, these embedded systems must use these limited resources (such as limited memory space) to process Huffman code.
一些不同的霍夫曼解码方法在过去已经被提出,而这些现有的霍夫曼解码技术大致上可以被分为两类:单一位元法以及多位元法。单一位元法被使用于霍夫曼树(Huffman tree)搜寻法以及联合影像专家群标准之中;另外,相较于单一位元法使用一个位元接着一个位元(bit by bit)的搜寻方法,多位元法通常使用对照表或其它搜寻技术来搜寻霍夫曼码。 Several different Huffman decoding methods have been proposed in the past, and these existing Huffman decoding techniques can be roughly divided into two categories: single-bit methods and multi-bit methods. The single-bit method is used in the Huffman tree (Huffman tree) search method and the Joint Image Experts Group standard; in addition, compared to the single-bit method using a bit by bit (bit by bit) search method, the multi-bit method usually uses a look-up table or other search techniques to search for Huffman codes.
因为单一位元法使用一个位元接着一个位元(bit by bit)的搜寻方法,因此会具有很慢的搜寻速度,此外,因为目前嵌入式系统所处理的音讯串流或是联合影像专家群的影像均具有高的位元传输速率(bit rate)以及分辨率,再加上多数的嵌入式系统通常仅使用低速率的时钟讯号以降低功率消耗,因此,如上所述,因为单一位元法搜寻速度过慢,无法有效率的处理这些音讯 串流或是影像,因此并不适合用于大部分的嵌入式系统中。 Because the single-bit method uses a bit by bit (bit by bit) search method, it will have a very slow search speed. In addition, because the audio stream processed by the current embedded system or the joint image expert group The images have a high bit rate (bit rate) and resolution, plus most embedded systems usually only use low-speed clock signals to reduce power consumption, therefore, as mentioned above, because the single-bit method The search speed is too slow to efficiently process these audio streams or images, so it is not suitable for most embedded systems.
此外,多位元法是为了加速霍夫曼解码速度而开发出来的,大部分的多位元法,特别是对照表逼近法,解码的速度比单一位元法快非常多。然而,多位元法需要较多的存储器空间,因此,多位元法对嵌入式系统而言亦不完美,因为大部分的嵌入式系统为了降低芯片面积,所设计出的存储器大小很有限。 In addition, the multi-bit method was developed to speed up Huffman decoding. Most of the multi-bit methods, especially the look-up table approximation method, decode much faster than the single-bit method. However, the multi-bit method requires more memory space. Therefore, the multi-bit method is not perfect for embedded systems, because most embedded systems are designed with a limited memory size in order to reduce chip area.
发明内容 Contents of the invention
本发明要解决的技术问题在于,针对现有技术的上述缺陷,提供一种霍夫曼解码方法,其具有较快的搜寻速度以及较少的存储器空间使用量,且可以有效率地使用于大部分的嵌入式系统中,以解决上述的问题。 The technical problem to be solved by the present invention is to provide a Huffman decoding method for the above defects of the prior art, which has a faster search speed and less memory space usage, and can be efficiently used in large Part of the embedded system to solve the above problems.
本发明解决其技术问题所采用的技术方案是:构造一种用来对一传输流上的一编码数据进行霍夫曼解码的方法,其包含有:对一编码书中的码字进行处理以产生至少一辅助对照表,并将所产生的每一个辅助对照表储存至一储存装置中,其中该编码书为一预定的编码书或自该传输流中所撷取出;以及依据该编码书以及储存于该储存装置中的至少该辅助对照表,以搜寻出该编码数据中一目标码字的相对应解码值。 The technical solution adopted by the present invention to solve the technical problem is: to construct a method for carrying out Huffman decoding on a coded data on a transport stream, which includes: processing the codeword in a codebook to generating at least one auxiliary lookup table, and storing each generated auxiliary lookup table in a storage device, wherein the codebook is a predetermined codebook or extracted from the transport stream; and according to the codebook and At least the auxiliary look-up table stored in the storage device is used to search for a corresponding decoding value of a target codeword in the encoded data.
本发明所述的方法,其中对该编码书中的码字进行处理的步骤包含有: The method of the present invention, wherein the step of processing the codeword in the coding book includes:
将该编码书中的码字分为多个码字群组,并界定每一个码字群组的一上边界以及一下边界,其中该多个码字群组分别对应至多个不同的位元形态(bit pattern),且同一码字群组中的码字均具有一部分相同的位元形态;以及 Divide the codewords in the coding book into multiple codeword groups, and define an upper boundary and a lower boundary of each codeword group, wherein the multiple codeword groups correspond to a plurality of different bit forms respectively (bit pattern), and the codewords in the same codeword group all have a part of the same bit pattern; and
建立该辅助对照表,其中该辅助对照表 记录每一个码字群组的一上边界以及一下边界。 Set up the auxiliary comparison table, wherein the auxiliary comparison table records an upper boundary and a lower boundary of each code word group.
本发明所述的方法,其中搜寻出该目标码字的该相对应解码值的步骤包含有: In the method of the present invention, the step of searching for the corresponding decoding value of the target codeword includes:
依据该编码数据以自该辅助对照表中选择出一特定上边界以及一特定下边界; selecting a specific upper boundary and a specific lower boundary from the auxiliary comparison table according to the coded data;
参考该特定上边界以及该特定下边界以自该编码书中一或多个码字中搜寻出该目标码字;以及 searching for the target codeword from one or more codewords in the codebook with reference to the specified upper boundary and the specified lower boundary; and
输出对应于该目标码字且 记录于该编码书上的该解码值。 The decoded value corresponding to the target codeword and recorded on the codebook is output.
本发明所述的方法,其中参考该特定上边界以及该特定下边界以自该编码书中一或多个码字中搜寻出该目标码字的步骤包含有: In the method of the present invention, the step of searching for the target codeword from one or more codewords in the codebook with reference to the specific upper boundary and the specific lower boundary includes:
当该特定上边界以及该特定下边界之间仅具有一特定码字时,将该编码书中的该特定码字作为该目标码字。 When there is only a specific codeword between the specific upper boundary and the specific lower boundary, the specific codeword in the coding book is used as the target codeword.
本发明所述的方法,其中参考该特定上边界以及该特定下边界以自该编码书中一或多个码字中搜寻出该目标码字的步骤包含有: In the method of the present invention, the step of searching for the target codeword from one or more codewords in the codebook with reference to the specific upper boundary and the specific lower boundary includes:
当该特定上边界以及该特定下边界之间具有多个特定码字时,对该多个特定码字进行二元搜寻以找出该目标码字。 When there are multiple specific codewords between the specific upper boundary and the specific lower boundary, a binary search is performed on the multiple specific codewords to find the target codeword.
本发明所述的方法,其中将该编码书中的码字分为该多个码字群组,并界定每一个码字群组的一上边界以及一下边界的步骤包含有: In the method of the present invention, wherein the codewords in the coding book are divided into these multiple codeword groups, and the steps of defining an upper boundary and a lower boundary of each codeword group include:
针对该编码书中每一个码字,计算位于一标记位元之后且与该标记位元具有相同值的连续位元个数以得到一第一计数值,其中同一码字群组中的码字具有相同的第一计数值;以及 For each codeword in the codebook, calculate the number of consecutive bits that are located after a marker bit and have the same value as the marker bit to obtain a first count value, wherein the codewords in the same codeword group have the same first count value; and
依据该编码书中的码字的多个第一计数值来决定每一个码字群组的上边界以及下边界;以及 determining an upper boundary and a lower boundary for each group of codewords based on a plurality of first count values of the codewords in the codebook; and
依据该编码数据以自该辅助对照表中选择出该特定上边界以及该特定下边界的步骤包含有: The step of selecting the specific upper boundary and the specific lower boundary from the auxiliary look-up table according to the encoded data includes:
计算该编码数据中位于一标记位元之后且与该标记位元具有相同值的连续位元个数以得到一第二计数值;以及 calculating the number of consecutive bits in the coded data which are located after a mark bit and have the same value as the mark bit to obtain a second count value; and
自该辅助对照表中选择出对应于该第二计数值的该特定上边界以及该特定下边界。 The specific upper boundary and the specific lower boundary corresponding to the second count value are selected from the auxiliary lookup table.
本发明所述的方法,其中将该编码书中的码字分为该多个码字群组,并界定每一个码字群组的一上边界以及一下边界的步骤包含有: In the method of the present invention, wherein the codewords in the coding book are divided into these multiple codeword groups, and the steps of defining an upper boundary and a lower boundary of each codeword group include:
针对该编码书中每一个码字,计算位于一标记位元之后且与该标记位元具有相同值的连续位元个数以得到一第一计数值,其中同一码字群组中的码 字具有相同的第一计数值;以及 For each codeword in the codebook, calculate the number of consecutive bits that are located after a marker bit and have the same value as the marker bit to obtain a first count value, wherein the codewords in the same codeword group have the same first count value; and
依据该编码书中的码字的多个第一计数值来决定每一个码字群组的上边界以及下边界。 An upper boundary and a lower boundary of each codeword group are determined according to a plurality of first count values of the codewords in the codebook.
本发明所述的方法,其中对该编码书中的码字进行处理的步骤包含有: The method of the present invention, wherein the step of processing the codeword in the coding book includes:
对该编码书中的码字进行处理以得到一第一辅助对照表,且对该编码书中的码字以及该第一辅助对照表进行处理以得到一第二辅助对照表;以及 processing the codewords in the coding book to obtain a first auxiliary comparison table, and processing the codewords in the coding book and the first auxiliary comparison table to obtain a second auxiliary comparison table; and
搜寻出该编码数据中该目标码字的该相对应解码值的步骤包含有: The step of searching out the corresponding decoding value of the target codeword in the encoded data includes:
依据该编码书以及储存于该储存装置中的该第一、第二辅助对照表以搜寻出对应于该编码数据中该目标码字的该解码值。 The decoded value corresponding to the target codeword in the coded data is searched according to the code book and the first and second auxiliary comparison tables stored in the storage device.
本发明所述的方法,其中对该编码书中的码字进行处理以得到该第一辅助对照表的步骤包含有: The method of the present invention, wherein the step of processing the codeword in the coding book to obtain the first auxiliary comparison table includes:
对该编码书中的码字进行处理以将编码书中的码字分为多个第一码字群组,其中该多个第一码字群组分别对应至多个不同的码字长度(codewordlength),且同一第一码字群组中的码字均具有相同的码字长度; The codewords in the codebook are processed to divide the codewords in the codebook into multiple first codeword groups, wherein the multiple first codeword groups correspond to multiple different codeword lengths (codewordlength ), and the codewords in the same first codeword group all have the same codeword length;
建立该第一辅助对照表,其中该第一辅助对照表 记录该编码书中每一个码字所属的第一码字群组的一序号,另 记录每一个第一码字群组的一起始码字、每一个起始码字于编码书中的索引值以及每一个第一码字群组的码字长度,其中同一第一码字群组中的码字均具有相同的序号。 Establish the first auxiliary comparison table, wherein the first auxiliary comparison table records a sequence number of the first code word group to which each code word belongs in the coding book, and records a start code of each first code word group in addition word, the index value of each initial codeword in the coding book, and the codeword length of each first codeword group, wherein the codewords in the same first codeword group all have the same sequence number.
本发明所述的方法,其中对该编码书中的码字以及该第一辅助对照表进行处理以得到该第二辅助对照表的步骤包含有: The method of the present invention, wherein the step of processing the codeword in the coding book and the first auxiliary comparison table to obtain the second auxiliary comparison table includes:
参考该第一辅助对照表,将该编码书中的码字分为多个第二码字群组,并界定每一个第二码字群组的上下边界,其中每一个第二码字群组的上下边界分别为一或多个第一码字群组的序号的上下边界,且该一或多个第一码字群组与该第二码字群组具有至少一相同的码字;该多个第二码字群组分别对应至多个不同的位元形态(bit pattern),且同一码字群组中的码字均具有一部分相同的位元形态;以及 Referring to the first auxiliary comparison table, the codewords in the coding book are divided into a plurality of second codeword groups, and the upper and lower boundaries of each second codeword group are defined, wherein each second codeword group The upper and lower boundaries are respectively the upper and lower boundaries of the sequence numbers of one or more first codeword groups, and the one or more first codeword groups have at least one identical codeword with the second codeword group; A plurality of second codeword groups correspond to a plurality of different bit patterns respectively, and the codewords in the same codeword group all have a part of the same bit pattern; and
建立该第二辅助对照表,其中该第二辅助对照表 记录每一个第二码字群组的一上边界以及一下边界。 Establish the second auxiliary comparison table, wherein the second auxiliary comparison table records an upper boundary and a lower boundary of each second code word group.
本发明所述的方法,其中依据该编码书以及储存于该储存装置中的该第一、第二辅助对照表以搜寻出对应于该编码数据中该目标码字的该解码值的步骤包含有: In the method of the present invention, the step of searching for the decoding value corresponding to the target codeword in the encoded data according to the code book and the first and second auxiliary comparison tables stored in the storage device includes: :
依据该编码数据以自该第二辅助对照表中选择出一特定上边界以及一特定下边界; selecting a specific upper boundary and a specific lower boundary from the second auxiliary comparison table according to the coded data;
参考该特定上边界以及该特定下边界以自该第一辅助对照表中一或多个起始码字中搜寻出一目标起始码字;以及 referring to the specific upper boundary and the specific lower boundary to search for a target initial codeword from one or more initial codewords in the first auxiliary look-up table; and
依据该目标起始码字以输出对应于该目标码字且 记录于该编码书上的该解码值。 The decoded value corresponding to the target codeword and recorded on the coding book is output according to the target initial codeword.
本发明所述的方法,其中依据该目标起始码字以输出对应于该目标码字且 记录于该编码书上的该解码值的步骤包含有: The method of the present invention, wherein the step of outputting the decoded value corresponding to the target codeword and recorded on the coding book according to the target initial codeword comprises:
依据该编码数据以及该目标起始码字之间的差距以得到一偏移值;以及 Obtain an offset value according to the difference between the encoded data and the target initial codeword; and
依据该目标起始码字的一索引值以及该偏移值以对编码书进行搜寻,以得到一霍夫曼值。 The codebook is searched according to an index value of the target initial codeword and the offset value to obtain a Huffman value.
本发明所述的方法,其中参考该特定上边界以及该特定下边界以自该第一辅助对照表中一或多个起始码字中搜寻出一起始码字以作为该目标起始码字的步骤包含有: The method of the present invention, wherein referring to the specific upper boundary and the specific lower boundary to search for an initial codeword from one or more initial codewords in the first auxiliary look-up table as the target initial codeword The steps include:
当该特定上边界以及该特定下边界之间仅具有一特定起始码字时,将该第一辅助对照表中的该特定起始码字作为该目标起始码字。 When there is only a specific initial codeword between the specific upper boundary and the specific lower boundary, the specific initial codeword in the first auxiliary look-up table is used as the target initial codeword.
本发明所述的方法,其中参考该特定上边界以及该特定下边界以自该第一辅助对照表中一或多个起始码字中搜寻出一起始码字以作为该目标起始码字的步骤包含有: The method of the present invention, wherein referring to the specific upper boundary and the specific lower boundary to search for an initial codeword from one or more initial codewords in the first auxiliary look-up table as the target initial codeword The steps include:
当该特定上边界以及该特定下边界之间具有该第一辅助对照表所储存的多个特定起始码字时,对该多个特定起始码字进行二元搜寻以找出该目标起始码字。 When there are a plurality of specific start code words stored in the first auxiliary look-up table between the specific upper boundary and the specific lower boundary, a binary search is performed on the specific start code words to find the target start code. Start code word.
本发明所述的方法,其中参考该第一辅助对照表,将该编码书中的码字分为多个第二码字群组,并界定每一个第二码字群组的上下边界的步骤包含有: In the method of the present invention, wherein referring to the first auxiliary comparison table, the codewords in the coding book are divided into a plurality of second codeword groups, and the step of defining the upper and lower boundaries of each second codeword group Contains:
针对该编码书中每一个码字,计算位于一标记位元之后且与该标记位元具有相同值的连续位元个数以得到一第一计数值,其中同一第二码字群组中的码字具有相同的第一计数值;以及 For each codeword in the codebook, calculate the number of consecutive bits that are located after a marker bit and have the same value as the marker bit to obtain a first count value, wherein the same second codeword group the codewords have the same first count value; and
依据该编码书中的码字的多个第一计数值以及每一个码字所属的第一码字群组的序号,以决定每一个第二码字群组的上边界以及下边界;以及 determining an upper boundary and a lower boundary of each second codeword group according to a plurality of first count values of the codewords in the codebook and the serial number of the first codeword group to which each codeword belongs; and
依据该编码数据以自该第二辅助对照表中选择出该特定上边界以及该特定下边界的步骤包含有: The step of selecting the specific upper boundary and the specific lower boundary from the second auxiliary comparison table according to the encoded data includes:
计算该编码数据中位于一标记位元之后且与该标记位元具有相同值的连续位元个数以得到一第二计数值;以及 calculating the number of consecutive bits in the coded data which are located after a mark bit and have the same value as the mark bit to obtain a second count value; and
自该第二辅助对照表中选择出对应于该第二计数值的该特定上边界以及该特定下边界。 The specific upper boundary and the specific lower boundary corresponding to the second count value are selected from the second auxiliary look-up table.
本发明所述的方法,其中参考该第一辅助对照表,将该编码书中的码字分为多个第二码字群组,并界定每一个第二码字群组的上下边界的步骤包含有: In the method of the present invention, wherein referring to the first auxiliary comparison table, the codewords in the coding book are divided into a plurality of second codeword groups, and the step of defining the upper and lower boundaries of each second codeword group Contains:
针对该编码书中每一个码字,计算位于一标记位元之后且与该标记位元具有相同值的连续位元个数以得到一第一计数值,其中同一第二码字群组中的码字具有相同的第一计数值;以及 For each codeword in the codebook, calculate the number of consecutive bits that are located after a marker bit and have the same value as the marker bit to obtain a first count value, wherein the same second codeword group the codewords have the same first count value; and
依据该编码书中的码字的多个第一计数值以及每一个码字所属的第一码字群组的序号,以决定每一个第二码字群组的上边界以及下边界。 The upper boundary and the lower boundary of each second codeword group are determined according to a plurality of first count values of the codewords in the coding book and the serial number of the first codeword group to which each codeword belongs.
本发明所述的方法,其中该传输流符合动态影像专家群先进音讯编码(Moving Picture Experts Group Advanced Audio Coding,MPEG AAC)或是联合影像专家群(Joint Photographic Experts Group,JPEG)的规格。 In the method of the present invention, the transport stream complies with the specifications of Moving Picture Experts Group Advanced Audio Coding (MPEG AAC) or Joint Photographic Experts Group (JPEG).
实施本发明的霍夫曼解码方法,具有以下有益效果:通过使用辅助对照表来进行解码,可以加速搜寻速度且仅需要较少的存储器空间,因此,本发明的霍夫曼解码方法可以有效率地使用在多数的嵌入式系统中。 Implementing the Huffman decoding method of the present invention has the following beneficial effects: by using the auxiliary look-up table for decoding, the search speed can be accelerated and only less memory space is required, so the Huffman decoding method of the present invention can be efficient used in most embedded systems.
附图说明 Description of drawings
下面将结合附图及实施例对本发明作进一步说明,附图中: The present invention will be further described below in conjunction with accompanying drawing and embodiment, in the accompanying drawing:
图1为依据本发明一实施例的先进音讯编码解码器的示意图; FIG. 1 is a schematic diagram of an advanced audio codec according to an embodiment of the present invention;
图2为依据本发明另一实施例的联合影像专家群解码器的示意图; FIG. 2 is a schematic diagram of a joint video expert group decoder according to another embodiment of the present invention;
图3为依据本发明一第一实施例的霍夫曼解码方法,其中该霍夫曼解码方法用来对一串流中的编码数据进行解码; 3 is a Huffman decoding method according to a first embodiment of the present invention, wherein the Huffman decoding method is used to decode encoded data in a stream;
图4为依据图3所示的霍夫曼解码方法中一对照表的示意图; FIG. 4 is a schematic diagram of a comparison table according to the Huffman decoding method shown in FIG. 3;
图5A、图5B为图3所示的流程中产生辅助对照表的详细流程图; Fig. 5A, Fig. 5B are the detailed flow charts that generate auxiliary comparison table in the process shown in Fig. 3;
图6为使用上述图5A、图5B所产生的辅助对照表来搜寻霍夫曼值的详细流程图; Fig. 6 is a detailed flow chart of searching for Huffman values using the auxiliary comparison table generated in Fig. 5A and Fig. 5B;
图7为依据本发明一第二实施例的霍夫曼解码方法,其中该霍夫曼解码方法用来对一串流中的编码数据进行解码; 7 is a Huffman decoding method according to a second embodiment of the present invention, wherein the Huffman decoding method is used to decode encoded data in a stream;
图8为依据图7所示的霍夫曼解码方法中一对照表的示意图; FIG. 8 is a schematic diagram of a comparison table according to the Huffman decoding method shown in FIG. 7;
图9为建立第一辅助对照表的详细流程图,且该第一辅助对照表包含有一中间对照表MI与三个子对照表MC、BA、ML; Fig. 9 is a detailed flowchart of establishing the first auxiliary comparison table, and the first auxiliary comparison table includes an intermediate comparison table MI and three sub-comparison tables MC, BA, and ML;
图10A、图10B为产生第二辅助对照表的详细流程图。 10A and 10B are detailed flowcharts for generating the second auxiliary comparison table.
【主要组件符号说明】 [Description of main component symbols]
具体实施方式 Detailed ways
图1为依据本发明一实施例的先进音讯编码(Advanced Audio Code,AAC)解码器100的示意图,其中解码器100可以使用硬件或是软件来实现。解码器100包含有一串流反格式转换器(stream deformattor)101、一霍夫曼解码模块102、一变量值组计算以及反量化(tuple calculation anddequantization)模块104、一立体声处理模块106以及一反滤波模块(inversefiltering)108,其中霍夫曼解码模块102依据储存于一储存装置110中的霍夫曼对照表112以及一辅助对照表114以进行解码操作。在解码器100的操作上,串流反格式转换器101自一先进音讯编码串流中取得所需的位元之后,将所取得的位元传送至与该先进音讯编码串流直接相关的解码模块(例如霍夫曼解码模块102、立体声处理模块106以及反滤波模块108)。此外,霍夫曼对照表112包含有十一个预定的系列编码书(codebook)以及一个比例因素编码书,且辅助对照表114内容由霍夫曼对照表112中至少一个编码书所推导出。此外,在霍夫曼解码模块102中,许多传统解码方法,例如树状移动法(tree traverse),可以被使用来解码霍夫曼符号;在变量值组计算以及反量化模块104中,使用解码后的霍夫曼符号来产生两个或是四个变量值组,之后再对所产生的变量值组进行反量化操作;接着,立体声处理模块106使用变量值组计算以及反量化模块104所产生的单一通道反量化结果以建立一双通道输出;最后,反滤波模块108将该双信道输出转换为一时域音讯输出,而此时域音讯输出可以传送至一扬声器系统来播放。 FIG. 1 is a schematic diagram of an Advanced Audio Code (AAC) decoder 100 according to an embodiment of the present invention, wherein the decoder 100 can be implemented by hardware or software. The decoder 100 includes a stream deformattor 101, a Huffman decoding module 102, a variable value group calculation and inverse quantization (tuple calculation and dequantization) module 104, a stereo processing module 106 and an inverse filter Module (inverse filtering) 108 , wherein the Huffman decoding module 102 performs a decoding operation according to a Huffman lookup table 112 and an auxiliary lookup table 114 stored in a storage device 110 . In the operation of the decoder 100, after the serial inverse format converter 101 obtains the required bits from an ACOD stream, the obtained bits are sent to the decoder directly related to the ACOD stream. modules (such as the Huffman decoding module 102, the stereo processing module 106, and the inverse filtering module 108). In addition, the Huffman comparison table 112 includes eleven predetermined series of codebooks (codebook) and one scale factor codebook, and the content of the auxiliary comparison table 114 is derived from at least one codebook in the Huffman comparison table 112 . In addition, in the Huffman decoding module 102, many traditional decoding methods, such as tree traverse, can be used to decode Huffman symbols; in the variable value group calculation and inverse quantization module 104, using decoding The final Huffman symbols are used to generate two or four variable value groups, and then the generated variable value groups are dequantized; The single-channel dequantization result of the single-channel to create a two-channel output; finally, the inverse filtering module 108 converts the two-channel output into a time-domain audio output, and the time-domain audio output can be sent to a speaker system for playback.
图2为依据本发明另一实施例的联合影像专家群解码器200的示意图, 其中解码器200可以使用硬件或是软件来实现。解码器200包含有一串流反格式转换器(stream deformattor)201、一霍夫曼解码模块202、一接收与扩大模块204、一反量化(dequantization)模块206以及一反离散余弦转换(inverse discrete cosine transform)模块208,其中霍夫曼解码模块202依据储存于一储存装置210中的霍夫曼对照表212以及一辅助对照表214以进行解码操作。串流反格式转换器201以及霍夫曼解码模块202的功能与图1所示的串流反格式转换器101以及霍夫曼解码模块102的功能相同,此外,因为联合影像专家群的编码书并非预先设定好而是载在一传输流上,因此霍夫曼对照表212通过一设定模块(未绘示)来建立。在使用联合影像专家群标准中所描述的方法下,联合影像专家群的编码书与先进音讯编码的编码书具有相同的特征,因此,针对联合影像专家群以及先进音讯编码这两种规格,霍夫曼解码模块202可以使用相同的解码方法。之后,接收与扩大模块204使用霍夫曼解码模块202所解码出的霍夫曼符号以自JPEG串流中获得多个量化值,此外,类似于霍夫曼对照表以及霍夫曼编码书,JPEG量化对照表亦载于JPEG串流上,且需要使用设定模块来分析建立出来。之后,反量化模块206对接收与扩大模块204的输出进行处理并产生频域影像区块(frequency-domain image block),最后,反离散余弦转换模块208将频域影像区块转换为时域影像区块(time-domain image block)。 FIG. 2 is a schematic diagram of a joint video expert group decoder 200 according to another embodiment of the present invention, wherein the decoder 200 can be implemented by hardware or software. The decoder 200 includes a stream deformattor 201, a Huffman decoding module 202, a receiving and expanding module 204, an inverse quantization (dequantization) module 206 and an inverse discrete cosine transform (inverse discrete cosine) transform) module 208, wherein the Huffman decoding module 202 performs a decoding operation according to a Huffman look-up table 212 and an auxiliary look-up table 214 stored in a storage device 210 . The functions of the serial inverse format converter 201 and the Huffman decoding module 202 are the same as those of the serial inverse format converter 101 and the Huffman decoding module 102 shown in FIG. It is not pre-set but carried on a transport stream, so the Huffman lookup table 212 is established through a setting module (not shown). The JEVS codebook has the same characteristics as the AIC codebook, using the methods described in the JEVS standard, so for both the JVG and AIC specifications, Huo The Fman decoding module 202 can use the same decoding method. Afterwards, the receiving and expanding module 204 uses the Huffman symbols decoded by the Huffman decoding module 202 to obtain multiple quantization values from the JPEG stream. In addition, similar to the Huffman comparison table and the Huffman coding book, The JPEG quantization table is also contained in the JPEG stream, and needs to be analyzed and established using the configuration module. Afterwards, the inverse quantization module 206 processes the output of the receiving and expanding module 204 to generate a frequency-domain image block, and finally, the inverse discrete cosine transform module 208 converts the frequency-domain image block into a time-domain image block (time-domain image block).
请参考图3,图3为依据本发明一第一实施例的霍夫曼解码方法,其中该霍夫曼解码方法用来对串流反格式转换器101、201所提供的一串流中的一编码数据进行解码。首先,包含有至少一编码书的霍夫曼对照表112或是212自该串流中被撷取出,且被储存于储存装置110或是210中,需注意的是,在本实施例中,霍夫曼对照表112或是212的编码书中的所有码字均为16位元,且如图4前三栏所示地依据该些码字的最高位元(Most-Significant Bit,MSB)来排序,且排序后的码字被储存于储存装置110或是210中的一对照表CW中。图4所示的编码书包含有霍夫曼值HV(Huffman value)、码字长度CL(code length)、码字CW、标记位元(sign bit)、以及第一计数值等信息,需注意的是,图4所示的编码书仅为一范例说明,而并非作为本发明的 限制。本发明的解码流程如下所述: Please refer to FIG. 3. FIG. 3 is a Huffman decoding method according to a first embodiment of the present invention. An encoded data is decoded. First, the Huffman comparison table 112 or 212 including at least one codebook is extracted from the stream and stored in the storage device 110 or 210. It should be noted that in this embodiment, All codewords in the coding book of Huffman comparison table 112 or 212 are 16 bits, and as shown in the first three columns of Figure 4, according to the highest bit (Most-Significant Bit, MSB) of these codewords to sort, and the sorted codewords are stored in a comparison table CW in the storage device 110 or 210 . The code book shown in Figure 4 contains information such as Huffman value HV (Huffman value), code word length CL (code length), code word CW, sign bit (sign bit), and the first count value. It should be noted that Yes, the codebook shown in Figure 4 is only an example and is not intended to be a limitation of the present invention. The decoding process of the present invention is as follows:
在步骤300中,解码作业开始。接着,于步骤302中,将该编码书中的码字分为多个码字群组,并界定每一个码字群组的上下边界,其中该多个码字群组分别对应至多个不同的位元形态(bit pattern),且同一码字群组中的码字均具有如图4所示的一部分相同的位元形态。举例来说,图4所示的码字群组2中的码字具有一部分相同的位元形态“001”、码字群组4中的码字具有一部分相同的位元形态“10”、以及码字群组6中的码字具有一部分相同的位元形态“1110”...等等,因此,每一个码字群组所包含的码字为包含其上下边界以及位于该上下边界之间的所有码字。此外,在本实施例中,该编码书中的每一个码字的最高位元(MSB)被视为一标记位元,且位于该标记位元之后且与该标记位元具有相同值的连续位元个数被计算出以作为一第一计数值,且该第一计数值用来识别不同的位元形态,换句话说,同一码字群组中的每一个码字均具有相同的第一计数值。举例来说,码字群组2中的码字“00110”的第一计数值为“1”,且码字群组6中的码字“11101111”的第一计数值为“2”。 In step 300, the decoding job starts. Next, in step 302, the codewords in the coding book are divided into multiple codeword groups, and the upper and lower boundaries of each codeword group are defined, wherein the multiple codeword groups correspond to multiple different bit pattern, and the codewords in the same codeword group all have a part of the same bit pattern as shown in FIG. 4 . For example, the codewords in the codeword group 2 shown in FIG. 4 have a part of the same bit pattern "001", the codewords in the codeword group 4 have a part of the same bit pattern "10", and The codewords in the codeword group 6 have a part of the same bit pattern "1110"... etc. Therefore, the codewords contained in each codeword group are those that contain its upper and lower boundaries and are located between the upper and lower boundaries all codewords of . In addition, in this embodiment, the most significant bit (MSB) of each codeword in the codebook is regarded as a mark bit, and the continuous The number of bits is calculated as a first count value, and the first count value is used to identify different bit patterns, in other words, each codeword in the same codeword group has the same first count value A count value. For example, the first count value of the code word "00110" in code word group 2 is "1", and the first count value of the code word "11101111" in code word group 6 is "2".
接着,在步骤304中,建立辅助对照表114或是214,且辅助对照表 记录每一个码字群组的一上边界以及一下边界,此外,在本实施例中,每一个码字群组的上下边界依据该编码书中码字的标记位元以及第一计数值来决定。举例来说,针对码字群组2,辅助对照表储存一上边界(对应至CW=0010)以及一下边界(对应至CW=00111)的信息;以及针对码字群组4,辅助对照表储存一上边界(对应至CW=100000)以及一下边界(对应至CW=101111)的信息。 Then, in step 304, set up the auxiliary comparison table 114 or 214, and the auxiliary comparison table records an upper boundary and a lower boundary of each codeword group, in addition, in the present embodiment, each codeword group's The upper and lower boundaries are determined according to the flag bit of the codeword in the codebook and the first count value. For example, for codeword group 2, the auxiliary look-up table stores information of an upper boundary (corresponding to CW=0010) and a lower boundary (corresponding to CW=00111); and for codeword group 4, the auxiliary lookup table stores Information of an upper boundary (corresponding to CW=100000) and a lower boundary (corresponding to CW=101111).
在步骤306,依据一编码数据,一特定上边界以及一特定下边界自辅助对照表中被选择出。详细来说,霍夫曼解码模块102或202自串流反格式转换器101或201接收该编码数据,并决定该编码数据属于哪一个码字群组,此外,在本实施例中,霍夫曼解码模块102或202将该编码数据的最高位元(MSB)被视为一标记位元,并计算出位于该标记位元之后且与该标记位元具有相同值的连续位元个数以作为一第二计数值;接着,霍夫曼解码模块102 或202依据该编码数据的该第二计数值以及该编码数据的该标记位元以决定该编码数据属于哪一个码字群组。举例来说,若是该编码数据的第二计数值为“1”,且标记位元大于“0”,则该编码数据属于码字群组2,且码字群组2的上下边界分别作为该特定上边界以及该特定下边界;若是该编码数据的第二计数值为“2”,且标记位元小于“0”,则该编码数据属于码字群组6,且码字群组6的上下边界分别作为该特定上边界以及该特定下边界。 In step 306, according to an encoded data, a specific upper boundary and a specific lower boundary are selected from the auxiliary look-up table. In detail, the Huffman decoding module 102 or 202 receives the encoded data from the serial inverse format converter 101 or 201, and determines which codeword group the encoded data belongs to. In addition, in this embodiment, the Huffman The Mann decoding module 102 or 202 regards the highest bit (MSB) of the encoded data as a mark bit, and calculates the number of consecutive bits that are positioned after the mark bit and have the same value as the mark bit to obtain As a second count value; then, the Huffman decoding module 102 or 202 determines which codeword group the coded data belongs to according to the second count value of the coded data and the flag bit of the coded data. For example, if the second count value of the coded data is "1" and the flag bit is greater than "0", then the coded data belongs to codeword group 2, and the upper and lower boundaries of codeword group 2 serve as the A specific upper boundary and the specific lower boundary; if the second count value of the coded data is "2" and the flag bit is less than "0", then the coded data belongs to codeword group 6, and the codeword group 6 The upper and lower boundaries serve as the specific upper boundary and the specific lower boundary, respectively.
之后,在步骤308中,通过参考该特定上边界以及该特定下边界,搜寻该编码书中一或多个码字出以决定出对应于该编码数据的一目标码字。特别地,于本实施例中,若是该特定上边界以及该特定下边界之间仅具有一个特定码字(例如图4所示的码字群组1),则该特定码字即作为该目标码字;若是该特定上边界以及该特定下边界之间具有多个特定码字(例如图4所示的码字群组2~7),则可以利用二分搜寻法(binary search)以自该多个特定码字中找出一特定码字以作为该目标码字,亦即,经由比较该编码数据以及该编码书中一个码字群组中一或多个特定码字以决定出该目标码字。 Then, in step 308, by referring to the specific upper boundary and the specific lower boundary, one or more codewords in the codebook are searched to determine a target codeword corresponding to the coded data. Particularly, in this embodiment, if there is only one specific codeword between the specific upper boundary and the specific lower boundary (such as the codeword group 1 shown in FIG. 4 ), then the specific codeword is taken as the target codeword; if there are a plurality of specific codewords (for example codeword group 2~7 shown in Figure 4) between this specific upper boundary and this specific lower boundary, then can utilize binary search method (binary search) to from this Finding a specific code word from a plurality of specific code words as the target code word, that is, determining the target code word by comparing the coded data with one or more specific code words in a code word group in the code book Codeword.
最后,在步骤310中,输出记录于该编码书中且对应于该目标码字的一霍夫曼值以作为一解码数据。举例来说,当该目标码字为“100000”,则输出霍夫曼值“12”;该目标码字为“11110000”,则输出霍夫曼值“53”以作为解码数据。 Finally, in step 310, output a Huffman value recorded in the coding book and corresponding to the target codeword as a decoded data. For example, when the target codeword is "100000", the Huffman value "12" is output; the target codeword is "11110000", then the Huffman value "53" is output as the decoded data.
图3、图4所示的霍夫曼解码方法具有以下的优点:当对应于该编码数据的一霍夫曼值需要被搜寻而求出时,只需要对图4所示的单一码字群组进行搜寻即可,且通过该编码数据的第二计数值,可以很有效率地被决定出该编码数据位于哪一个码字群组。与习知使用图4所示的所有码字群组以作为搜寻范围地霍夫曼解码方法相比,本发明的霍夫曼解码方法可以节省存储器空间,且加快搜寻出霍夫曼值的速度。 The Huffman decoding method shown in Fig. 3 and Fig. 4 has the following advantages: when a Huffman value corresponding to the coded data needs to be searched and obtained, only the single codeword group shown in Fig. 4 is needed Groups can be searched, and which codeword group the coded data is located in can be efficiently determined through the second count value of the coded data. Compared with the conventional Huffman decoding method that uses all the codeword groups shown in FIG. 4 as the search range, the Huffman decoding method of the present invention can save memory space and speed up the search for Huffman values .
请参考图5A、图5B,图5A、图5B为图3的步骤304中产生辅助对照表HT的详细流程图。如图5A、图5B所示,在步骤500,作业开始。之后,在步骤501的初始化过程中,码字索引k以及一变量pl被重新设定为“0”,一函数‘sc’用来计算一编码书中每一个码字中位于一标记位元之后且与该标 记位元具有相同值的连续位元个数,并据以产生一第一计数值,以及依据一第一码字CW[0]的第一计数值以决定一变量ps,亦即ps=sc(CW[0]),需注意的是,在许多嵌入式处理器中,函数‘sc’可以利用一单一指令来实作。此外,一编码书长度,亦即该编码书中码字的数量,被储存为一n值,且一变量pff被设定为“1”。 Please refer to FIG. 5A and FIG. 5B . FIG. 5A and FIG. 5B are detailed flowcharts of generating the auxiliary comparison table HT in step 304 of FIG. 3 . As shown in Fig. 5A and Fig. 5B, at step 500, the job starts. Afterwards, in the initialization process of step 501, the codeword index k and a variable pl are reset to "0", and a function 'sc' is used to calculate the codeword located after a marker bit in a codebook And have the number of consecutive bits with the same value as the mark bit, and generate a first count value accordingly, and determine a variable ps according to the first count value of a first code word CW[0], also That is, ps=sc(CW[0]), it should be noted that in many embedded processors, the function 'sc' can be implemented with a single instruction. In addition, a codebook length, that is, the number of codewords in the codebook, is stored as a value n, and a variable pff is set to "1".
上述流程将会对该编码书中每一个码字进行处理以产生辅助对照表HT,针对每一个码字而言,于步骤502中,函数‘sc’会先对该码字进行运算以产生一第一计数值s,之后,于步骤503中,检查码字的标记位元(亦即码字CW[k]的最高位元),若是码字CW[k]>=0,则流程进入步骤504以判断ps与s之间的关系,若是ps等于s,该码字索引的数值增加1(亦即步骤510,k=k+1)并判断目前所处理的码字是否为该编码书中最后一个码字(步骤518);若目前所处理的码字不为该编码书中最后一个码字,流程回到步骤502以取得下一个码字的第一计数值;若是ps不等于s,辅助对照表HT的一索引值i被初始化为i=s+1(步骤505)。之后,于步骤506~508,辅助对照表中的值HT[2*i]以及HT[2*i+1]分别被设定为pl以及k直到索引值i==ps;当索引值i>ps时,流程进入步骤509且变量pl与ps分别更新为pl=k以及ps=s。接着,增加码字索引k的数值并判断目前所处理的码字是否为该编码书中最后一个码字(步骤510以及518)。 The above process will process each codeword in the codebook to generate an auxiliary comparison table HT. For each codeword, in step 502, the function 'sc' will first operate on the codeword to generate a After the first count value s, in step 503, check the mark bit of code word (that is the most significant bit of code word CW[k]), if code word CW[k]>=0, then flow process enters step 504 to judge the relationship between ps and s, if ps is equal to s, the numerical value of this codeword index increases by 1 (that is step 510, k=k+1) and judges whether the currently processed codeword is the codebook Last code word (step 518); If the code word processed at present is not the last code word in this coding book, flow process returns to step 502 to obtain the first count value of next code word; If ps is not equal to s, An index value i of the auxiliary lookup table HT is initialized as i=s+1 (step 505 ). Afterwards, in steps 506-508, the values HT[2*i] and HT[2*i+1] in the auxiliary comparison table are respectively set to pl and k until the index value i==ps; when the index value i> When ps, the process enters step 509 and the variables pl and ps are updated to pl=k and ps=s respectively. Next, increase the value of the codeword index k and determine whether the currently processed codeword is the last codeword in the codebook (steps 510 and 518).
若是码字CW[k]<0,判断变量ppf是否等于1(步骤511),若变量ppf等于1,则变数ppf的值被清除,且索引值i被初始化为s(步骤514)。类似上述步骤506~508,辅助对照表HT中的值HT[2*i]以及HT[2*i+1]分别被设定为pl以及k,且索引值i在循环中逐渐增加直到i==ps(步骤515~517)。在索引值i的循环结束之后(亦即i>ps),变量pl以及ps的值被更新,且码字索引k的值增加1且判断k是否小于n(步骤510以及518);回到步骤511,若是变量ppf不等于1,判断变量ps是否等于s(步骤512),若是变量ps不等于s,则辅助对照表中的值HT=[2*ps+32]以及HT[2*ps+33]分别被设定为pl以及k(步骤513),接着,变量pl以及ps的值分别被设定为k以及s(步骤509),且码字索引k的值增加1且判断k是否小于n(步骤510以及518)。 若是变量ps等于s,则流程进入步骤510将码字索引k的值增加1,并判断k是否小于n(步骤518)。 If codeword CW[k]<0, judge whether variable ppf is equal to 1 (step 511), if variable ppf is equal to 1, then the value of variable ppf is cleared, and index value i is initialized as s (step 514). Similar to the above steps 506-508, the values HT[2*i] and HT[2*i+1] in the auxiliary comparison table HT are set to pl and k respectively, and the index value i is gradually increased in the loop until i= = ps (steps 515-517). After the loop of the index value i ends (i.e. i>ps), the values of the variables pl and ps are updated, and the value of the codeword index k increases by 1 and it is judged whether k is less than n (steps 510 and 518); back to the steps 511, if the variable ppf is not equal to 1, judge whether the variable ps is equal to s (step 512), if the variable ps is not equal to s, then the value HT=[2*ps+32] and HT[2*ps+ 33] is set to pl and k (step 513) respectively, then, the value of variable pl and ps is set to k and s (step 509) respectively, and the value of codeword index k increases by 1 and judges whether k is less than n (steps 510 and 518). If the variable ps is equal to s, the process enters step 510 to increase the value of the codeword index k by 1, and judge whether k is less than n (step 518).
当该编码书中所有的码字均已进行过上述流程之后(亦即码字索引k==n),索引值i会被重新设定为ps(步骤519)。若是索引值i>=16,则进入步骤523结束产生辅助对照表HT的流程;若是索引值i<16,则持续进行步骤520~522的循环直到索引值i==16,此外,在此循环中,辅助对照表中的值HT=[2*i+32]以及HT[2*i+33]分别被设定为pl以及(pi+1)(步骤521)。 After all the codewords in the codebook have gone through the above process (ie codeword index k==n), the index value i will be reset to ps (step 519 ). If the index value i>=16, then enter step 523 to end the flow process of generating the auxiliary comparison table HT; if the index value i<16, then continue the loop of steps 520-522 until the index value i==16, in addition, loop here , the values HT=[2*i+32] and HT[2*i+33] in the auxiliary lookup table are set as pl and (pi+1) respectively (step 521).
请参考图6,图6为图3的步骤306~310中搜寻霍夫曼值的详细流程图,其中搜寻霍夫曼值的步骤中使用上述图5A、图5B所产生的辅助对照表HT。如图6所示,在步骤600中,作业开始。于步骤601中,一16位元的编码数据在不移动读取指针的情形下自AAC或JPEG串流中撷取出来,且该16位元的编码数据被设定为一整数值x;接着,于步骤602中,将该16位元的编码数据视为一有符号整数(signed integer number),并使用函数‘sc’来计算该16位元编码数据中位于一标记位元之后且与该标记位元具有相同值的连续位元个数以产生一第二计数值,且该第二计数值被储存于一变量s中。之后,在步骤603中,判断该16位元编码数据x是否小于0:若是该16位元编码数据x小于0,则变数(亦即第二计数值)s需要被更新为(s+16)(步骤604),且更新后的变量s在之后的步骤作为辅助对照表HT的一索引值;若是16位元编码数据x不小于0,则变数(亦即第二计数值)s直接作为辅助对照表HT的索引值。之后,于步骤605中,辅助对照表HT中的值HT=[2*s]以及HT[2*s+1]被撷取出且分别被储存为变量bl以及bh。 Please refer to FIG. 6 . FIG. 6 is a detailed flow chart of searching for Huffman values in steps 306 - 310 of FIG. 3 , wherein the step of searching for Huffman values uses the auxiliary comparison table HT generated in FIGS. 5A and 5B . As shown in FIG. 6, in step 600, a job starts. In step 601, a 16-bit encoded data is extracted from the AAC or JPEG stream without moving the read pointer, and the 16-bit encoded data is set to an integer value x; then , in step 602, treat the 16-bit coded data as a signed integer (signed integer number), and use the function 'sc' to calculate the The number of consecutive bits with the same value is marked to generate a second count value, and the second count value is stored in a variable s. Afterwards, in step 603, it is judged whether the 16-bit encoded data x is less than 0: if the 16-bit encoded data x is less than 0, then the variable (that is, the second count value) s needs to be updated to (s+16) (step 604), and the updated variable s is used as an index value of the auxiliary comparison table HT in the following steps; if the 16-bit encoded data x is not less than 0, then the variable (that is, the second count value) s is directly used as an auxiliary The index value of the comparison table HT. Afterwards, in step 605 , the values HT=[2*s] and HT[2*s+1] in the auxiliary lookup table HT are retrieved and stored as variables bl and bh respectively.
之后,在步骤606中,依据公式i=(bh+bl)>>1计算出一索引值i,其中“>>”为一位元位元移运算子(bit shift operator),且上述公式将bh以及bl的整数和向右平移1个位元。此索引值i用来作为三个必要的霍夫曼解码对照表的索引值,此三个霍夫曼解码对照表分别为:码字对照表CW、用来储存一编码书中所有码字的位元数的码字长度对照表CL、以及图4前三栏所示的霍夫曼值对照表HV。之后,于步骤607中,将变量bh与bl的差值(亦即(bh-bl))与“1”作比较:若是变数bh与bl的差值大于1,则将16位元编码 数据x与码字CW[i]作比较(步骤608),关于步骤608,16位元编码数据x与码字CW[i]此时应要被视为无符号整数(unsigned integer number),且若是x>CW[i],将变数bl更新为bl=i(步骤609);若是x<CW[i],将变数bh更新为bh=i(步骤611),在更新变量bl或是bh之后,解码流程回至步骤606;若是x==CW[i],亦即,已经找到可以用来撷取出霍夫曼解码结果的码字索引,因此,流程进入步骤612以取得一码字长度CL[i],之后于步骤613中,移动指标并回传一霍夫曼值HV[i]以作为最终的解码结果。此外,回到有关步骤607的叙述,若是变量bh与bl的差值不大于1,则目前的索引值i亦为所寻找的最终索引值,因此,流程会进入最终步骤,亦即步骤612~613以取得码字长度CL[i],并移动指标并回传霍夫曼值HV[i]。 Afterwards, in step 606, an index value i is calculated according to the formula i=(bh+bl)>>1, wherein ">>" is a bit shift operator (bit shift operator), and the above formula will Integer sum of bh and bl shifted 1 bit to the right. This index value i is used as the index value of three necessary Huffman decoding comparison tables, and these three Huffman decoding comparison tables are: codeword comparison table CW, used to store all codewords in a coding book The codeword length comparison table CL of the number of bits, and the Huffman value comparison table HV shown in the first three columns of FIG. 4 . Afterwards, in step 607, the difference between the variables bh and bl (that is, (bh-bl)) is compared with "1": if the difference between the variables bh and bl is greater than 1, the 16-bit encoded data x Compare with codeword CW[i] (step 608), about step 608, 16-bit encoded data x and codeword CW[i] should be regarded as unsigned integer (unsigned integer number) at this moment, and if x >CW[i], update variable bl to bl=i (step 609); if x<CW[i], update variable bh to bh=i (step 611), after updating variable bl or bh, decode The flow returns to step 606; if x==CW[i], that is, the codeword index that can be used to retrieve the Huffman decoding result has been found, so the flow enters step 612 to obtain a codeword length CL[i ], then in step 613, move the index and return a Huffman value HV[i] as the final decoding result. In addition, returning to the description of step 607, if the difference between the variables bh and bl is not greater than 1, then the current index value i is also the final index value to be searched, so the process will enter the final step, that is, step 612~ 613 to obtain the code word length CL[i], move the index and return the Huffman value HV[i].
请参考图7,图7为依据本发明一第二实施例的霍夫曼解码方法,其中该霍夫曼解码方法用来对串流反格式转换器101、201所提供的一串流中的编码数据进行解码。首先,包含有至少一编码书的霍夫曼对照表112或是212自该串流中被撷取出,且被储存于储存装置110或是210中,需注意的是,在本实施例中,霍夫曼对照表112或是212的编码书中的所有码字均为16位元,且如图8前三栏所示地依据该些码字的最高位元(Most-Significant Bit,MSB)来排序,排序后的码字被储存于储存装置110或是210中的一对照表CW中。图8所示的编码书包含有霍夫曼值HV(Huffman value)、码字长度CL(code length)、码字CW、标记位元(sign bit)、以及第一计数值等信息,需注意的是,图8所示的编码书仅为一范例说明,而并非作为本发明的限制。本发明的解码流程如下所述: Please refer to FIG. 7. FIG. 7 is a Huffman decoding method according to a second embodiment of the present invention, wherein the Huffman decoding method is used for a stream provided by the stream inverse format converter 101, 201 Encoded data is decoded. First, the Huffman comparison table 112 or 212 including at least one codebook is extracted from the stream and stored in the storage device 110 or 210. It should be noted that in this embodiment, All codewords in the coding book of Huffman comparison table 112 or 212 are 16 bits, and as shown in the first three columns of Fig. 8, according to the most significant bit (Most-Significant Bit, MSB) of these codewords The sorted codewords are stored in a comparison table CW in the storage device 110 or 210 . The code book shown in Figure 8 contains information such as Huffman value HV (Huffman value), code word length CL (code length), code word CW, sign bit (sign bit), and the first count value. It should be noted that Yes, the code book shown in FIG. 8 is just an example and not a limitation of the present invention. The decoding process of the present invention is as follows:
在步骤700中,解码作业开始。之后,于步骤702,将该编码书中的码字分为多个第一码字群组,其中每一个第一码字群组对应至不同的码字长度,且同一第一码字群组中的码字均具有如图8所示的相同的码字长度。举例来说,如图8所示,第一码字群组3包含有码字长度为5的多个码字,且第一码字群组4包含有码字长度为6的多个码字。 In step 700, a decoding job starts. Afterwards, in step 702, the codewords in the codebook are divided into a plurality of first codeword groups, wherein each first codeword group corresponds to a different codeword length, and the same first codeword group The codewords in all have the same codeword length as shown in Figure 8. For example, as shown in Figure 8, the first codeword group 3 includes a plurality of codewords with a codeword length of 5, and the first codeword group 4 includes a plurality of codewords with a codeword length of 6 .
接着,于步骤704中,建立一第一辅助对照表,其中该第一辅助对照表 记录每一个码字所属的第一码字群组的序号,其中,同一第一码字群组中的 码字均具有相同的序号,此外,该第一辅助对照表另 记录每一个第一码字群组的一起始码字、该起始码字于该编码书中的索引值、以及该第一码字群组的码字长度。举例来说,第一码字群组3中的起始码字为“00110”,且序号为2。 Then, in step 704, set up a first auxiliary comparison table, wherein the first auxiliary comparison table records the serial number of the first code word group to which each code word belongs, wherein, the code in the same first code word group The words all have the same serial number. In addition, the first auxiliary comparison table additionally records a start code word of each first code word group, the index value of the start code word in the coding book, and the first code word The codeword length of the word group. For example, the initial codeword in the first codeword group 3 is "00110" and its sequence number is 2.
接着,于步骤706,参考该第一辅助对照表,将该编码书中的码字分为多个第二码字群组,并界定每一个第二码字群组的上下边界,其中每一个第二码字群组的上下边界分别为一或多个第一码字群组的序号的上下边界,其中,该多个第二码字群组分别对应至多个不同的位元形态(bit pattern),且同一码字群组中的码字均具有如图8所示的一部分相同的位元形态。举例来说,图8所示的码字群组2中的码字具有一部分相同的位元形态“001”、码字群组3中的码字具有一部分相同的位元形态“01”、以及码字群组5中的码字具有一部分相同的位元形态“110”...等等。此外,在本实施例中,编码书中的每一个码字的最高位元(MSB)被视为一标记位元,且位于该标记位元之后且与该标记位元具有相同值的连续位元个数被计算出以作为一第一计数值,且该第一计数值用来识别不同的位元形态,换句话说,同一第二码字群组中的每一个码字均具有相同的第一计数值。 Next, in step 706, referring to the first auxiliary comparison table, the codewords in the coding book are divided into a plurality of second codeword groups, and the upper and lower boundaries of each second codeword group are defined, wherein each The upper and lower boundaries of the second codeword group are respectively the upper and lower boundaries of the sequence numbers of one or more first codeword groups, wherein the plurality of second codeword groups correspond to a plurality of different bit patterns (bit pattern) respectively. ), and the codewords in the same codeword group all have a part of the same bit pattern as shown in FIG. 8 . For example, the codewords in the codeword group 2 shown in FIG. 8 have a part of the same bit pattern "001", the codewords in the codeword group 3 have a part of the same bit pattern "01", and Codewords in codeword group 5 have a portion of the same bit pattern "110" . . . and so on. In addition, in this embodiment, the most significant bit (MSB) of each codeword in the coding book is regarded as a mark bit, and the consecutive bits that are located after the mark bit and have the same value as the mark bit The number of bits is calculated as a first count value, and the first count value is used to identify different bit patterns, in other words, each codeword in the same second codeword group has the same first count value.
接着,于步骤708,建立一第二辅助对照表,且该第二辅助对照表 记录每一个第二码字群组的一上边界以及一下边界,此外,在本实施例中,每一个第二码字群组的上下边界依据该编码书中码字的第一计数值来决定。此外,该第二辅助对照表 记录每一个第二码字群组中的码字位于哪一个第一码字群组,举例来说,码字“01000”~“01100”位于第二码字群组3,且亦位于第一码字群组3;码字“011010”~“011111”位于第二码字群组3,且亦位于第一码字群组4。因此,该第二辅助对照表 记录第二码字群组3关联于第一码字群组3与4,且该第二辅助对照表亦 记录相关联的第一码字群组的起始码字(亦即,第一码字群组3的起始码字“00110”以及第一码字群组4的起始码字“011010”)。在实作上,该第二辅助对照表 记录第二码字群组3关联于第一码字群组序号2与3(分别对应于第一码字群组3与4),换句话说,于本实施例中,因为每一个第二码字群组的上下边界分别为一或多个第一码字群组的 序号的上下边界,因此,第二码字群组3的上边界为第一码字群组3的序号2(具有起始码字“00110”),且下边界为第一码字群组4的序号3(具有起始码字“011010”)。 Then, in step 708, a second auxiliary comparison table is established, and the second auxiliary comparison table records an upper boundary and a lower boundary of each second codeword group. In addition, in this embodiment, each second The upper and lower boundaries of the codeword group are determined according to the first count value of the codeword in the codebook. In addition, the second auxiliary comparison table records which first codeword group the codewords in each second codeword group are located in. For example, the codewords "01000" to "01100" are located in the second codeword group group 3, and is also located in the first code word group 3; Therefore, the second auxiliary lookup table records that the second codeword group 3 is associated with the first codeword group 3 and 4, and the second auxiliary lookup table also records the start code of the associated first codeword group words (ie, the initial codeword "00110" of the first codeword group 3 and the initial codeword "011010" of the first codeword group 4). In practice, the second auxiliary comparison table records that the second codeword group 3 is associated with the first codeword group numbers 2 and 3 (corresponding to the first codeword group 3 and 4 respectively), in other words, In this embodiment, because the upper and lower boundaries of each second codeword group are respectively the upper and lower boundaries of the serial numbers of one or more first codeword groups, therefore, the upper boundary of the second codeword group 3 is the first The sequence number 2 of a codeword group 3 (with the start codeword "00110"), and the lower boundary is the sequence number 3 of the first codeword group 4 (with the start codeword "011010").
在步骤710,依据一编码数据,自该第二辅助对照表中选择出一特定上边界以及一特定下边界。详细来说,霍夫曼解码模块102或202自串流反格式转换器101或201接收该编码数据,并决定该编码数据属于哪一个第二码字群组,此外,在本实施例中,霍夫曼解码模块102或202将该编码数据的最高位元(MSB)被视为一标记位元,并计算出位于该标记位元之后且与该标记位元具有相同值的连续位元个数以作为一第二计数值,接着,霍夫曼解码模块102或202依据该编码数据的该第二计数值以及该编码数据的该标记位元以决定该编码数据属于哪一个第二码字群组,并据以自该第二辅助对照表中选择出一特定上边界以及一特定下边界。步骤710的详细操作类似于步骤306,因此,说明在此省略。 In step 710, a specific upper boundary and a specific lower boundary are selected from the second auxiliary look-up table according to a coded data. Specifically, the Huffman decoding module 102 or 202 receives the encoded data from the serial inverse format converter 101 or 201, and determines which second codeword group the encoded data belongs to. In addition, in this embodiment, The Huffman decoding module 102 or 202 regards the highest bit (MSB) of the coded data as a mark bit, and calculates the number of consecutive bits that are located after the mark bit and have the same value as the mark bit Count as a second count value, and then, the Huffman decoding module 102 or 202 determines which second codeword the coded data belongs to according to the second count value of the coded data and the flag bit of the coded data group, and accordingly select a specific upper boundary and a specific lower boundary from the second auxiliary comparison table. The detailed operation of step 710 is similar to step 306, therefore, the description is omitted here.
接着,在步骤712中,通过参考该特定上边界以及该特定下边界,搜寻该第一辅助对照表中一或多个起始码字以决定出一目标起始码字。特别地,于本实施例中,若是该特定上边界以及该特定下边界之间仅具有一个特定起始码字(例如图8所示的第二码字群组1),则该特定起始码字即作为该目标起始码字;若是该特定上边界以及该特定下边界之间具有多个特定起始码字(例如图8所示的第二码字群组3~5),则可以利用二分搜寻法(binary search)以自该多个特定起始码字中找出一特定起始码字以作为该目标起始码字,于本实施例中,因为该编码数据所需比对的特定起始码字数量很少,因此可以大幅减短二分搜寻法所花的时间。举例来说,如图8所示,假设第二码字群组3的上下边界分别作为该特定上边界以及该特定下边界,则因为该特定上边界以及该特定下边界分别为第一辅助对照表中的两个起始码字(亦即,第一码字群组3的起始码字CW=00110以及第一码字群组4的起始码字CW=011010),则之后对该两个起始码字进行搜寻以决定哪一个起始码字为目标起始码字。举例来说,假设该编码数据为“011111”,则所选择出的目标起始码字必须为该第一辅助对照表的多个起始码字中最接近该编码数据且小于该编 码数据的起始码字(亦即,第一码字群组4的起始码字CW=011010);举另一例来说,假设该编码数据为“01100”,则所选择出的目标起始码字为第一码字群组3的起始码字CW=00110。 Next, in step 712, by referring to the specific upper boundary and the specific lower boundary, one or more initial codewords in the first auxiliary look-up table are searched to determine a target initial codeword. Especially, in this embodiment, if there is only one specific start codeword (such as the second codeword group 1 shown in FIG. 8 ) between the specific upper boundary and the specific lower boundary, then the specific start codeword The codeword is used as the target initial codeword; if there are multiple specific initial codewords (such as the second codeword group 3-5 shown in Figure 8) between the specific upper boundary and the specific lower boundary, then A binary search method (binary search) can be used to find a specific start code word from the plurality of specific start code words as the target start code word. In this embodiment, because the encoded data requires a ratio of The number of specific starting codewords for the pair is very small, so the time spent by the binary search method can be greatly reduced. For example, as shown in FIG. 8 , assuming that the upper and lower boundaries of the second codeword group 3 are respectively used as the specific upper boundary and the specific lower boundary, since the specific upper boundary and the specific lower boundary are respectively the first auxiliary comparison Two initial codewords in the table (that is, the initial codeword CW=00110 of the first codeword group 3 and the initial codeword CW=011010 of the first codeword group 4), then the Two start codewords are searched to determine which start codeword is the target start codeword. For example, assuming that the coded data is "011111", the selected target start codeword must be the closest to the coded data and smaller than the coded data among the multiple start codewords in the first auxiliary comparison table. (that is, the initial codeword CW=011010 of the first codeword group 4); for another example, assuming that the coded data is "01100", the selected target initial code The word is the start codeword CW=00110 of the first codeword group 3 .
之后,于步骤714中,依据该编码数据以及该目标起始码字的间的差距以得到一偏移值(offset value),其中得到该偏移值的步骤会于之后进行详述。最后,在步骤716中,依据该目标起始码字的一索引值以及该偏移值以对编码书进行搜寻,以得到一霍夫曼值。 Afterwards, in step 714, an offset value (offset value) is obtained according to the difference between the coded data and the target initial codeword, and the step of obtaining the offset value will be described in detail later. Finally, in step 716, the codebook is searched according to an index value of the target initial codeword and the offset value to obtain a Huffman value.
请参考图9,图9为建立第一辅助对照表的详细流程图。该第一辅助对照表包含有一中间对照表MI与三个子对照表MC、BA、ML,MI[i]为一编码书中码字其所对应至一第一码字群组的序号,MC[i]为第一码字群组的一起始码字,BA[i]为起始码字于编码书中的索引值,且ML[i]为第一码字群组的码字长度。如图9所示,在步骤900中,作业开始。之后,于步骤901,变量k、i、pl首先被初始化为“0”,且一编码书长度(亦即该编码书中码字的数量)被储存为一n值。接着,于步骤902,判断变量k(此时作为码字索引)是否小于编码书长度n,若是变量k不小于编码书长度n,则流程进入步骤910并结束建立该第一辅助对照表的步骤;若是变量k小于编码书长度n,则进入步骤903以决定码字长度CL[k],并将CL[k]储存为一m值。接着,在步骤904,比较码字长度m与变量pl,若是变量pl等于码字长度m,则流程进入步骤908以将MI[k]设为(i-1);若是变量pl不等于码字长度m,则流程进入步骤905以分别更新三个子对照表(MC[i]=CW[k]、BA[i]=k、ML[i]=CL[k])。之后,于步骤906以及907中,变量pl被设为码字长度m,且索引值i被更新为(i+1)。在更新过变量以及子对照表的内容后(步骤905~907),流程进入步骤908以将MI[k]设为(i-1)。最后,于步骤909,将变量k的值增加“1”(亦即k=k+1),之后流程回到步骤902。 Please refer to FIG. 9 , which is a detailed flowchart of establishing the first auxiliary comparison table. The first auxiliary comparison table includes an intermediate comparison table MI and three sub-comparison tables MC, BA, and ML. MI[i] is the serial number of a codeword in a coding book corresponding to a first codeword group, and MC[ i] is an initial codeword of the first codeword group, BA[i] is the index value of the initial codeword in the coding book, and ML[i] is the codeword length of the first codeword group. As shown in FIG. 9, in step 900, a job starts. Afterwards, in step 901, the variables k, i, and pl are first initialized to "0", and a codebook length (that is, the number of codewords in the codebook) is stored as a value of n. Next, in step 902, it is judged whether the variable k (as a code word index at this time) is less than the codebook length n, if the variable k is not less than the codebook length n, then the process enters step 910 and ends the step of establishing the first auxiliary comparison table ; If the variable k is less than the codebook length n, enter step 903 to determine the codeword length CL[k], and store CL[k] as a value of m. Then, in step 904, compare code word length m and variable pl, if variable pl is equal to code word length m, then flow process enters step 908 so that MI[k] is set as (i-1); If variable pl is not equal to code word length m, the process enters step 905 to update three sub-comparison tables (MC[i]=CW[k], BA[i]=k, ML[i]=CL[k]) respectively. Afterwards, in steps 906 and 907, the variable pl is set to the codeword length m, and the index i is updated to (i+1). After the variables and the content of the sub-lookup table are updated (steps 905-907), the process goes to step 908 to set MI[k] to (i-1). Finally, in step 909 , the variable k is incremented by “1” (ie k=k+1), and then the process returns to step 902 .
请参考图10A、图10B,图10A、图10B为产生第二辅助对照表HT的详细流程图。图10A、图10B中的流程与图5A、图5B中的流程类似,而图5以及图10的主要差别在于:图9所示的流程中所产生的中间对照表MI被用来设定图10所示的流程所产生的第二辅助对照表HT。在步骤1000中, 作业开始。接着,于步骤1001,变量pl以及码字索引k被初始化为“0”,且变量ppf被设定为“1”,此外,变量ps被初始化为码字CW[0]的一第一计数值,且一编码书长度(亦即该编码书中码字的数量)被储存为一n值,其中码字CW[0]的第一计数值为码字CW[0]中位于一标记位元之后且与该标记位元具有相同值的连续位元个数。 Please refer to FIG. 10A and FIG. 10B . FIG. 10A and FIG. 10B are detailed flowcharts of generating the second auxiliary comparison table HT. The processes in Fig. 10A and Fig. 10B are similar to those in Fig. 5A and Fig. 5B, and the main difference between Fig. 5 and Fig. 10 is that the intermediate comparison table MI generated in the process shown in Fig. 9 is used to set the The second auxiliary comparison table HT generated by the process shown in 10 . In step 1000, the job starts. Next, in step 1001, the variable pl and the codeword index k are initialized to "0", and the variable ppf is set to "1", in addition, the variable ps is initialized to a first count value of the codeword CW[0] , and a codebook length (that is, the number of codewords in the codebook) is stored as an n value, where the first count value of the codeword CW[0] is located in a marker bit in the codeword CW[0] The number of consecutive bits that follow and have the same value as the flag bit.
于步骤1002中,利用函数‘sc’计算出每一个码字的第一计数值,并将所计算出的第一计数值储存于一变量s中。接着,于步骤1003中,判断码字CW[k](此时,码字CW[k]被视为一16位元有符号整数(signed integernumber))是否小于0,若是CW[k]>=0且ps==s(步骤1004),则码字索引k的数值增加“1”(亦即步骤1010,k=k+1)并判断是否均被处理过(步骤1018);若是CW[k]>=0且ps!=s,流程进入步骤2005以将一变量i被初始化为(s+1)。之后,于步骤1006中,第二辅助对照表中的值HT[2*i]以及HT[2*i+1]分别被设定为MI[pl]以及MI[k]+1。接着,于步骤1007以及1008,变量i的数值增加1且判断变量i是否小于等于变量ps,若是I<=ps,流程回到步骤1006;若是i>ps,则流程进入步骤1009以将变量pl以及ps分别设定为k以及s。 In step 1002, use the function 'sc' to calculate the first count value of each codeword, and store the calculated first count value in a variable s. Then, in step 1003, it is judged whether the codeword CW[k] (at this moment, the codeword CW[k] is regarded as a 16-bit signed integer (signed integer)) is less than 0, if CW[k]>= 0 and ps==s (step 1004), then the numerical value of codeword index k increases " 1 " (that is step 1010, k=k+1) and judges whether all have been processed (step 1018); If CW[k ]>=0 and ps! =s, the process goes to step 2005 to initialize a variable i to (s+1). After that, in step 1006, the values HT[2*i] and HT[2*i+1] in the second auxiliary look-up table are set as MI[pl] and MI[k]+1 respectively. Then, in steps 1007 and 1008, the value of variable i is increased by 1 and it is judged whether variable i is less than or equal to variable ps. If I<=ps, the process returns to step 1006; if i>ps, the process enters step 1009 to change variable p1 and ps are respectively set to k and s.
接着,若是CW[k]<0且ppf==1(步骤1011),则流程进入步骤1014以将变量ppf设定为0且将变量i设定为s。接着,于步骤1015,第二辅助对照表中的值HT[2*i]以及HT[2*i+1]分别被设定为MI[pl]以及MI[k]+1。接着,于步骤1016以及1017,变量i的数值增加1,以及将变量i与变量ps作比较,若是i<=ps,则流程回到步骤1015;若是i>ps,则流程进入步骤1009以将变量pl以及ps分别设定为k以及s。此外,若是CW[k]<0且ppf!=1,则流程进入步骤1012以判断变量ps是否不等于变量s,若是ps不等于s,则流程进入步骤1013以及1009以将第二辅助对照表中的值HT[2*ps+32]以及HT[2*ps+33]分别被设定为MI[pl]以及MI[k]+1,且将变量pl以及ps分别设定为k以及s。若是在步骤1012中判断ps等于s,则流程进入步骤1010以将码字索引k的数值增加1。 Then, if CW[k]<0 and ppf==1 (step 1011 ), then the flow goes to step 1014 to set the variable ppf to 0 and the variable i to s. Next, in step 1015, the values HT[2*i] and HT[2*i+1] in the second auxiliary lookup table are set as MI[pl] and MI[k]+1 respectively. Then, in steps 1016 and 1017, the value of the variable i is increased by 1, and the variable i is compared with the variable ps. If i<=ps, the process returns to step 1015; if i>ps, the process enters step 1009 to The variables pl and ps are set to k and s, respectively. In addition, if CW[k]<0 and ppf! =1, then the process enters step 1012 to determine whether the variable ps is not equal to variable s, if ps is not equal to s, then the process enters steps 1013 and 1009 to use the values HT[2*ps+32] and HT[2*ps+33] is set to MI[pl] and MI[k]+1, respectively, and the variables pl and ps are set to k and s, respectively. If it is determined in step 1012 that ps is equal to s, then the process proceeds to step 1010 to increase the value of the codeword index k by 1.
之后,流程进入步骤1018以判断是否所有的码字均被处理过,若不是, 流程回到步骤1002;反之,若是所有的码字均被处理过,则流程进入步骤1019以将变量i设定为变量ps的值。接着,在步骤1020中,判断变量i是否小于16,若是变量i不小于16,则进入步骤1023以结束此建立第二辅助对照表的流程;若是变量i小于16,则流程进入步骤1021以将第二辅助对照表中的值HT[2*i+32]以及HT[2*i+33]分别被设定为MI[pl]以及MI[pl]+1。之后,于步骤1022,将变量i的数值增加1,且流程回到步骤1020。图10所示的流程所输出的为第二辅助对照表HT,且第二辅助对照表HT与该第一辅助对照表中三个子对照表MC、BA、ML一起用来解码出霍夫曼值。 Afterwards, flow process enters step 1018 to judge whether all codewords have been processed, if not, flow process returns to step 1002; Otherwise, if all codewords have been processed, then flow process enters step 1019 to set variable i is the value of the variable ps. Then, in step 1020, it is judged whether the variable i is less than 16, if the variable i is not less than 16, then enter step 1023 to end the process of establishing the second auxiliary comparison table; if the variable i is less than 16, then the process enters step 1021 to set The values HT[2*i+32] and HT[2*i+33] in the second auxiliary lookup table are respectively set to MI[pl] and MI[pl]+1. Afterwards, in step 1022 , the variable i is incremented by 1, and the process returns to step 1020 . The output of the process shown in Figure 10 is the second auxiliary comparison table HT, and the second auxiliary comparison table HT is used together with the three sub-comparison tables MC, BA, and ML in the first auxiliary comparison table to decode the Huffman value .
以下对图7的步骤710~716中搜寻霍夫曼值的详细流程进行阐述,其中搜寻霍夫曼值的步骤中使用上述图9所产生的第一辅助对照表中的三个子对照表MC、BA、ML,以及图10A、图10B所产生的第二辅助对照表。具体流程如下: The detailed process of searching for the Huffman value in steps 710-716 of FIG. 7 is described below, wherein the step of searching for the Huffman value uses the three sub-comparison tables MC, MC, BA, ML, and the second auxiliary comparison table generated in Fig. 10A and Fig. 10B. The specific process is as follows:
首先解码作业开始。 First the decoding job starts.
接着,一16位元的编码数据在不移动读取指针的情形下自AAC或JPEG串流中撷取出来,且该16位元的编码数据被设定为一整数值x。 Then, a 16-bit encoded data is extracted from the AAC or JPEG stream without moving the read pointer, and the 16-bit encoded data is set to an integer value x.
接着,将该16位元的编码数据视为一有符号整数(signed integernumber),并使用函数‘sc’来计算该16位元编码数据中位于一标记位元之后且与该标记位元具有相同值的连续位元个数以产生一第二计数值,且该第二计数值被储存于一变量s中。 Next, treat the 16-bit encoded data as a signed integer (signed integer number), and use the function 'sc' to calculate the 16-bit encoded data that is located after a mark bit and has the same The number of consecutive bits of the value is used to generate a second count value, and the second count value is stored in a variable s.
接着,判断x是否小于0:若是x小于0,则变数s被更新为(s+16),且辅第二辅助对照表中的值HT[2*s]以及HT[2*s+1]被撷取出且分别被储存为变量bl以及bh。 Next, judge whether x is less than 0: if x is less than 0, the variable s is updated to (s+16), and the values HT[2*s] and HT[2*s+1] in the second auxiliary comparison table are supplemented are extracted and stored as variables bl and bh, respectively.
接着,依据公式i=(bh+bl)>>1计算出一索引值i,其中“>>”为一位元位元移运算子(bit shift operator)。 Next, an index value i is calculated according to the formula i=(bh+bl)>>1, wherein ">>" is a bit shift operator.
接着,将变量bh与bl的差值(亦即(bh-bl))与1作比较,存在两种情况: Next, compare the difference between the variables bh and bl (ie (bh-bl)) with 1, there are two situations:
第一种,若是变量bh与bl的差值大于1,比较变量x与码字MC[i],其中MC[i]为图9的流程中所产生的一无符号整数(unsigned integer number), 若是x>MC[i],则将变量bl设为i;若是x不大于MC[i],则判断x是否等于MC[i],若是x不等于MC[i],则将变量bh设为i。在更新完变量bl或是bh之后,流程返回至上述的“依据公式i=(bh+bl)>>1计算出一索引值i”。此外,若是x==MX[i],则将(x-MC[i])向右位元移(16-ML[i])位元以产生一变量off,其中MC[i]为一码字,且ML[i]为该码字MC[i]的码字长度,换句话说,亦即计算该编码数据与该目标起始码字的一二元差值(binary difference),并将该二元差值(亦即(x-MC[i]))向右位元移(16-ML[i])位元以产生变量off。接着,依据公式ii=BA[i]+off以计算出一索引值ii,其中BA[i]为图9的流程中所产生的起始码字于编码书中的索引值。最后,将指标位元移ML[i]并得到一霍夫曼值HV[ii]以作为解码结果,之后结束解码流程。 First, if the difference between the variable bh and bl is greater than 1, compare the variable x with the codeword MC[i], where MC[i] is an unsigned integer (unsigned integer number) generated in the flow process of Figure 9, If x>MC[i], set the variable bl to i; if x is not greater than MC[i], then judge whether x is equal to MC[i]; if x is not equal to MC[i], set the variable bh to i. After the variable bl or bh is updated, the process returns to the above-mentioned "calculate an index value i according to the formula i=(bh+bl)>>1". In addition, if x==MX[i], then (x-MC[i]) is shifted to the right by (16-ML[i]) bits to generate a variable off, where MC[i] is a code word, and ML[i] is the codeword length of the codeword MC[i], in other words, that is to calculate a binary difference (binary difference) between the coded data and the target initial codeword, and The binary difference (ie (x-MC[i])) is shifted right by (16-ML[i]) bits to generate the variable off. Next, an index value ii is calculated according to the formula ii=BA[i]+off, wherein BA[i] is the index value of the initial codeword generated in the process of FIG. 9 in the coding book. Finally, the index bit is shifted to ML[i] to obtain a Huffman value HV[ii] as a decoding result, and then the decoding process ends.
第二种,若是变量bh与bl的差值不大于1,与x==MX[i]时执行的流程相同,即,将(x-MC[i])向右位元移(16-ML[i])位元以产生一变量off,其中MC[i]为一码字,且ML[i]为该码字MC[i]的码字长度,换句话说,亦即计算该编码数据与该目标起始码字的一二元差值(binary difference),并将该二元差值(亦即(x-MC[i]))向右位元移(16-ML[i])位元以产生变量off。接着,依据公式ii=BA[i]+off以计算出一索引值ii,其中BA[i]为图9的流程中所产生的起始码字于编码书中的索引值。最后,将指标位元移ML[i]并得到一霍夫曼值HV[ii]以作为解码结果,之后结束解码流程。 In the second type, if the difference between the variable bh and bl is not greater than 1, the process performed when x==MX[i] is the same, that is, (x-MC[i]) is shifted to the right by (16-ML [i]) bits to generate a variable off, where MC[i] is a codeword, and ML[i] is the codeword length of the codeword MC[i], in other words, the coded data is calculated A binary difference (binary difference) with the target start codeword, and shift the binary difference (ie (x-MC[i])) to the right by (16-ML[i]) bit to generate the variable off. Next, an index value ii is calculated according to the formula ii=BA[i]+off, wherein BA[i] is the index value of the initial codeword generated in the process of FIG. 9 in the coding book. Finally, the index bit is shifted to ML[i] to obtain a Huffman value HV[ii] as a decoding result, and then the decoding process ends.
此外,在图1所示的AAC解码器100以及图2所示的JPEG解码器200中,霍夫曼对照表112、212以及辅助对照表114、214储存在相同的储存装置110、210中,然而,在本发明的其它实施例中,霍夫曼对照表以及辅助对照表可以分别建立于不同的储存装置中,这设计上的变化应隶属于本发明的范畴。 In addition, in the AAC decoder 100 shown in FIG. 1 and the JPEG decoder 200 shown in FIG. 2, the Huffman lookup tables 112, 212 and the auxiliary lookup tables 114, 214 are stored in the same storage device 110, 210, However, in other embodiments of the present invention, the Huffman lookup table and the auxiliary lookup table may be respectively established in different storage devices, and such design changes shall fall within the scope of the present invention.
需注意的是,图3以及图7所示的霍夫曼解码方法应用于图1所示的AAC解码器100以及图2所示的JPEG解码器200中,然而,在本发明的其它实施例中,本发明的霍夫曼解码方法亦可应用于其它需要使用霍夫曼解码的解码装置中。 It should be noted that the Huffman decoding method shown in FIG. 3 and FIG. 7 is applied to the AAC decoder 100 shown in FIG. 1 and the JPEG decoder 200 shown in FIG. 2 , however, in other embodiments of the present invention Among them, the Huffman decoding method of the present invention can also be applied to other decoding devices that need to use Huffman decoding.
简要归纳本发明,本发明的用来对一传输流上的一编码数据进行霍夫曼 解码的方法包含有:对一编码书中的码字进行处理以产生至少一辅助对照表,并将所产生的每一个辅助对照表储存至一储存装置中,其中该编码书自该传输流中所取出;以及依据该编码书以及储存于该储存装置中的至少该辅助对照表,以搜寻出该编码数据中一目标码字的相对应解码值。通过使用辅助对照表来进行解码,可以加速搜寻速度且仅需要较少的存储器空间,因此,本发明的霍夫曼解码方法可以有效率地使用在多数的嵌入式系统中。 Summarizing the present invention briefly, the method for performing Huffman decoding on a coded data on a transport stream of the present invention includes: processing codewords in a codebook to generate at least one auxiliary look-up table, and converting the Each auxiliary look-up table generated is stored in a storage device, wherein the code book is retrieved from the transport stream; and the code is searched based on the code book and at least the auxiliary look-up table stored in the storage device The corresponding decoded value of a target codeword in the data. By using the auxiliary look-up table for decoding, the search speed can be accelerated and less memory space is required. Therefore, the Huffman decoding method of the present invention can be efficiently used in most embedded systems.
以上所述仅为本发明的较佳实施例,凡依本发明申请专利范围所做的均等变化与修饰,皆应属本发明的涵盖范围。 The above descriptions are only preferred embodiments of the present invention, and all equivalent changes and modifications made according to the scope of the patent application of the present invention shall fall within the scope of the present invention.
Claims (13)
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201010151333.6A CN102237878B (en) | 2010-04-20 | 2010-04-20 | A Huffman decoding method |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201010151333.6A CN102237878B (en) | 2010-04-20 | 2010-04-20 | A Huffman decoding method |
Publications (2)
Publication Number | Publication Date |
---|---|
CN102237878A CN102237878A (en) | 2011-11-09 |
CN102237878B true CN102237878B (en) | 2015-09-02 |
Family
ID=44888174
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201010151333.6A Active CN102237878B (en) | 2010-04-20 | 2010-04-20 | A Huffman decoding method |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN102237878B (en) |
Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
AU7024694A (en) * | 1994-08-12 | 1996-02-22 | Canon Kabushiki Kaisha | Data encoding and decoding apparatus and method |
CN1547805A (en) * | 2000-10-31 | 2004-11-17 | ض� | Method of performing huffman decoding |
CN1613188A (en) * | 2001-10-19 | 2005-05-04 | 诺基亚公司 | Huffman coding |
CN101325418A (en) * | 2008-08-05 | 2008-12-17 | 北京海尔集成电路设计有限公司 | Haffman quick decoding method based on probability table look-up |
Family Cites Families (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US6891976B2 (en) * | 2002-03-12 | 2005-05-10 | Intel Corporation | Method to decode variable length codes with regular bit pattern prefixes |
-
2010
- 2010-04-20 CN CN201010151333.6A patent/CN102237878B/en active Active
Patent Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
AU7024694A (en) * | 1994-08-12 | 1996-02-22 | Canon Kabushiki Kaisha | Data encoding and decoding apparatus and method |
CN1547805A (en) * | 2000-10-31 | 2004-11-17 | ض� | Method of performing huffman decoding |
CN1613188A (en) * | 2001-10-19 | 2005-05-04 | 诺基亚公司 | Huffman coding |
CN101325418A (en) * | 2008-08-05 | 2008-12-17 | 北京海尔集成电路设计有限公司 | Haffman quick decoding method based on probability table look-up |
Also Published As
Publication number | Publication date |
---|---|
CN102237878A (en) | 2011-11-09 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US10033405B2 (en) | Data compression systems and method | |
TW392391B (en) | Variable length code detection in a signal processing system | |
TWI587640B (en) | Method and apparatus for pyramid vector quantization indexing and de-indexing of audio/video sample vectors | |
CN102098508B (en) | The coding of multimedia signature and decoding | |
US20070168197A1 (en) | Audio coding | |
CN110085238B (en) | Audio encoder and decoder | |
US20130019029A1 (en) | Lossless compression of a predictive data stream having mixed data types | |
RU2367087C2 (en) | Coding information without loss with guaranteed maximum bit speed | |
JP2002534721A (en) | Efficient encoding of side information in lossless encoder | |
JP2003218703A (en) | Data coder and data decoder | |
TWI429205B (en) | Huffman decoding method | |
JP4601690B2 (en) | Vector encoding / decoding method, apparatus, and stream media player | |
US10699723B2 (en) | Encoding and decoding of digital audio signals using variable alphabet size | |
CN100370828C (en) | Adaptive method and system for mapping parameter values to codeword indices | |
US20100017196A1 (en) | Method, system, and apparatus for compression or decompression of digital signals | |
CN111061722A (en) | Data compression method, data decompression method, device and equipment | |
MX2011003914A (en) | Method and apparatus for compressing and decompressing data records. | |
JP2010520696A (en) | Entropy encoding and decoding apparatus and method based on tree structure | |
US20130082850A1 (en) | Data encoding apparatus, data decoding apparatus and methods thereof | |
WO2011097963A1 (en) | Encoding method, decoding method, encoder and decoder | |
CN102237878B (en) | A Huffman decoding method | |
JP2006129467A (en) | Lossless adaptive encoding/decoding of integer data | |
US6411226B1 (en) | Huffman decoder with reduced memory size | |
US8487789B2 (en) | Method and apparatus for lossless encoding and decoding based on context | |
US7739119B2 (en) | Technique for implementing Huffman decoding |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
C06 | Publication | ||
PB01 | Publication | ||
C10 | Entry into substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
C14 | Grant of patent or utility model | ||
GR01 | Patent grant |