In MP3 (MPEG-1 Layer 3) encoding and decoding, the spectrum is considered to be divided into 576 frequency bins. These frequency bins are in turn grouped into sub-bands and this grouping of bins into sub-bands is defined in the MP3 specification. The sub-bands themselves are grouped into three regions which are referred to as ‘Big Values’, ‘Count1’ and ‘Rzero’ and the size of these regions may vary according to the particular audio signal. Big Values represents the lowest frequency lines and these are coded with the highest accuracy of all the regions. Count1 represents the higher frequency lines, which are encoded using only a small number of values and Rzero represents the highest frequencies which are removed by the encoder, and hence on decoding these frequency bins are filled with zeros.
The Big Values region is itself divided into three regions (region0, region1, region2) with each of these three regions being encoded using a particular Huffman table. This division of Big Values into three regions typically occurs for each granule when performing MP3 encoding. Some existing encoders, such as LAME (an open source MP3 encoder), use look-up tables to obtain the boundaries between these three regions according to the number of sub-bands to be encoded (e.g. the number of sub-bands within the Big Values region or the number of sub-bands which have any data in them). This requires virtually no computation but does not take into consideration the statistics of a particular audio signal which is to be encoded and therefore can result in encoding redundancies in the signal.
This Summary is provided to introduce a selection of concepts in a simplified form that are further described below in the Detailed Description. This Summary is not intended to identify key features or essential features of the claimed subject matter, nor is it intended to be used as an aid in determining the scope of the claimed subject matter.
Methods of spectral partitioning which may be implemented in an encoder are described. The methods comprise determining an estimate of bit requirements for each of a plurality of spectral sub-bands. These estimates are then used to group the sub-bands into two or more regions by minimising a cost function. This cost function is based on the estimates of bit requirements for each sub-band and the estimates of bit requirements may include estimates of code bit requirements and/or additional code bit requirements for each sub-band. These estimates may be determined in many different ways and a number of different methods are described.
A first aspect provides a method of spectral partitioning for use in encoding a signal comprising: determining an estimate of bit requirements for each of a plurality of spectral sub-bands; and grouping the spectral sub-bands into a plurality of regions by minimising a cost function based on the estimates of bit requirements for each of the spectral sub-bands.
The estimate of bit requirements may comprise at least one of: an estimate of code bit requirements and an estimate of additional code bit requirements. The estimate of code bit requirements may comprise an estimate of bit requirements when encoded using a Huffman tree and the estimate of additional code bit requirements may comprise an estimate of bit requirements for encoding values not presented in a Huffman table.
Each spectral sub-band comprises at least one frequency bin.
The estimate of additional code bit requirements for a spectral sub-band may comprise one or more of: the number of additional code bits required to encode the maximum value in any frequency bin in the spectral sub-band and the number of frequency bins within the spectral sub-band that require additional code bits.
The estimate of code bit requirements for a spectral sub-band may comprise one or more of: the number of code bits required to encode a maximum value in any frequency bin in the spectral sub-band excluding any additional code bits and the number of frequency bins in the spectral sub-band.
The step of grouping the spectral sub-bands into regions may comprise: determining a cost function for each region for all possible combinations of spectral sub-bands; combining the cost functions for each region into a set of overall cost functions for all possible combinations of spectral sub-bands; and selecting the combination of spectral sub-bands having the lowest overall cost function.
The cost function for each region may comprise one of or a combination of: the maximum number of additional code bits required by any spectral sub-band in the region multiplied by the number of frequency bins in the region requiring additional code bits; and the maximum number of code bits required by any spectral sub-band in the region multiplied by the total number of frequency bins in the region. Where the cost function comprises a combination, this combination may comprise a sum.
The method may further comprise: selecting a code table for each of the regions; and encoding each region using the selected code table for that region.
Each code table may comprise a Huffman table.
The signal may comprise an audio signal, such as one to be encoded using an MP3 encoder.
A second aspect provides a method of spectral partitioning substantially as described with reference to
A third aspect provides an encoder comprising: means for determining an estimate of bit requirements for each of a plurality of spectral sub-bands; and means for grouping the spectral sub-bands into a plurality of regions by minimising a cost function based on the estimates of bit requirements for each of the spectral sub-bands.
The estimate of bit requirements may comprise at least one of: an estimate of code bit requirements and an estimate of additional code bit requirements. The estimate of code bit requirements may comprise an estimate of bit requirements when encoded using a Huffman tree and the estimate of additional code bit requirements may comprise an estimate of bit requirements for encoding values not presented in the Huffman table.
Each spectral sub-band may comprise at least one frequency bin.
The estimate of additional code bit requirements for a spectral sub-band may comprise one or more of: the number of frequency bins within the spectral sub-band that require additional code bits and the number of additional code bits required to encode the maximum value in any frequency bin in the spectral sub-band.
The estimate of code bit requirements for a spectral sub-band may comprise one or more of: the number of code bits required to encode a maximum value in any frequency bin in the spectral sub-band excluding any additional code bits and the number of frequency bins in the spectral sub-band.
The means for grouping the spectral sub-bands into regions may comprise: means for determining a cost function for each region for all possible combinations of spectral sub-bands; means for combining the cost functions for each region into a set of overall cost functions for all possible combinations of spectral sub-bands; and means for selecting the combination of spectral sub-bands having the lowest overall cost function.
The cost function for each region may be based on at least one of: the maximum number of additional code bits required by any spectral sub-band in the region multiplied by the number of frequency bins in the region requiring additional code bits; and the maximum number of code bits required by any spectral sub-band in the region multiplied by the total number of frequency bins in the region. The cost function may comprise one of the above two factors or a combination of the two factors. Where the cost function comprises a combination, this combination may comprise a sum.
The methods described herein may be performed by firmware or software in machine readable form on a tangible storage medium. The software can be suitable for execution on a parallel processor or a serial processor such that the method steps may be carried out in any suitable order, or simultaneously.
A fourth aspect provides a computer program arranged to perform any of the methods described herein. The computer program may be stored on a tangible machine readable medium.
This acknowledges that firmware and software can be valuable, separately tradable commodities. It is intended to encompass software, which runs on or controls “dumb” or standard hardware, to carry out the desired functions. It is also intended to encompass software which “describes” or defines the configuration of hardware, such as HDL (hardware description language) software, as is used for designing silicon chips, or for configuring universal programmable chips, to carry out desired functions.
The preferred features may be combined as appropriate, as would be apparent to a skilled person, and may be combined with any of the aspects of the invention.
Embodiments of the invention will be described, by way of example, with reference to the following drawings, in which:
Common reference numerals are used throughout the figures to indicate similar features.
Embodiments of the present invention are described below by way of example only. These examples represent the best ways of putting the invention into practice that are currently known to the Applicant although they are not the only ways in which this could be achieved. The description sets forth the functions of the example and the sequence of steps for constructing and operating the example. However, the same or equivalent functions and sequences may be accomplished by different examples.
It will be appreciated that
As the statistics of an audio/video signal varies across frequency, it is often beneficial to divide the spectrum into several regions and encode each region separately (e.g. within the bitstream formatting element 104). Dividing the Big Values region into a number of regions (e.g. up to three regions in MP3) in a fixed manner based on the size of Big Values provides a quick method of spectral partitioning which does not require much processing power. However, because each of the regions is encoded using a single code table (e.g. a single Huffman table for MP3) this may result in inefficient encoding.
Ideally the Big Values region should be divided into regions where the spectral values in each region have similar statistics, such that each region contains sub-bands of similar characteristics (e.g. similar ranges of values in the frequency bins). This enables a region to be encoded with a lower bitrate and/or at higher quality. The optimum solution therefore involves considering every possible combination of number of sub-bands in each region and obtaining the actual number of bits for each combination. In order to obtain the actual number of bits for a partitioned spectrum, the spectral values of each region are encoded using all possible code tables and then the best table is selected. This is repeated for each of the regions and the spectral partitioning is typically performed for each granule. This is a lengthy, processor intensive process and is therefore impractical for many applications, particularly for low-power and/or real-time applications.
A code table, which may be used to encode a signal, may include codes for the most common sample values and the coding scheme may in addition provide an escape code in order to facilitate coding of less frequent values which are not included within the table. In such a coding scheme, values within the table may be encoded as the code given in the table and the encoded value may also include a sign bit indicating if the value is positive or negative, as follows:
Code+Sign bit
The bits within the ‘code’ above are referred to herein as ‘code bits’. Where the value is not in the table the value may be encoded using the escape code plus an additional code which identifies the actual value as follows:
Escape code+Additional code+Sign bit
The additional code may have a fixed number of bits (e.g. five bits) and because of the fixed number of bits, the additional code may be referred to as a Pulse Code Modulation (PCM) code. These bits within the additional code are referred to herein as ‘additional code bits’. When the bit-stream is decoded and an escape code is observed, this fixed number of bits read after the escape pattern will contain the difference between the escape value, which is the first value which cannot be encoded using a code in the table, and the value of the sample to be encoded. In an example, if a coding table includes codes for values up to 14, the escape value is 15. If a value of 35 is to be encoded, the additional code will give the value 20 (i.e. 35−15).
Such a coding scheme may be explained with reference to the following example which uses an additional code length of 5 bits:
Using this coding scheme values between −34 and 34 may be encoded. If the value is 0 only 0 is transmitted and if the value is 1 or 2 the corresponding code is transmitted followed by a sign bit (e.g. zero) to determine that they are positive values. If the value is 3 or more the escape code (111) is transmitted followed by 5 bits giving the difference between the value and 3 (i.e. the escape value). Negative values are transmitted in the same manner but with a one as their sign bit. The following table provides some examples of coded values:
As shown by the examples in the table above, whilst use of escape codes and additional codes enables values outside the range of the code table to be encoded, their use results in an encoding overhead of the escape code, plus the fixed number of bits of the additional code. In order to improve the efficiency of encoding, the requirement to use escape codes and additional codes should be minimised.
For MP3 applications, Huffman coding is used and in Huffman encoding, the code bits are referred to as ‘Huffman bits’ and the additional code bits are referred to as ‘linbits’. There are 30 different Huffman tables which may be used and each code in a Huffman table determines two values. The code also indicates whether either or both of the two values are also using linbits or not. Escape codes, and therefore linbits, are only provided by some of the 30 Huffman tables and the number of these bits (if they exist) is determined by the table index which is also transmitted.
The methods described herein may be applied to quantised MDCT (modified discrete cosine transform) values. In other examples, other frequency analysis methods (other than MDCT) may be used, such as FFT (fast Fourier transform).
MP3 coding, and its terminology (e.g. linbits) is used by way of example only in the following description of various methods of spectral partitioning and the techniques described are applicable to other coding schemes, such as variable run-length (VRL) code, which may be used in image/video coding.
Having performed the spectral partitioning, the optimum code table (e.g. Huffman table) can be selected for each region. The table may be selected base on factors including the maximum amplitude in a region. Of the 30 Huffman tables, there are typically two or three that could be used for a region based on a particular maximum amplitude in that region.
This method takes into consideration the characteristics of a particular signal (e.g. the abstract statistics of spectral sub-bands), which may be an audio signal, which is being encoded into an MP3 stream. The estimate of linbit requirements is a parameter which can be easily extracted from each of the sub-bands and in some circumstances some or all of the data may already be available within an encoder from an earlier stage in the encoding process.
In a first example implementation, the estimate of linbit requirements for a sub-band i may comprise two parameters: N(i), the number of frequency bins (or samples) in the sub-band i that need linbits and L(i), the maximum number of linbits required to encode the maximum value in the sub-band.
Whether linbits are required is determined by the maximum value which can be encoded without using linbits, Y−1, where Y is the escape value. For MP3 the escape value is defined as 15 (i.e. Y=15, therefore Y−1=14) but for other applications, the escape value may have a different value. Any value equal to or exceeding Y (i.e. ≧15 for MP3) requires linbits. The threshold (or escape value) Y is indicated by a dotted line in
If none of the values in any of the frequency bins in a sub-band equals or exceeds the threshold Y, (‘Yes’ in block 31), as in sub-band 2 of
If the maximum value in any of the frequency bins within a sub-band exceeds or equals the threshold, X(i)≧Y, (‘No’ in block 31), then there will be some samples which require linbits (N(i)>0). The number of samples requiring linbits, N(i), is the number of frequency bins with a value which exceeds or equals the threshold. In the example of
If X(i)=Y, (‘No’ in both blocks 31 and 32) the linbit size is zero, i.e. L(i)=0. However, where X(i)>Y, (‘No’ in block 31 and ‘Yes’ in block 32), the maximum number of linbits required, L(i), may be computed as follows:
L(i)=ceil(log2(X(i)−Y))
where: cell is a function which rounds up to the nearest integer (also known as ‘CEILING’ function).
The flow chart of
These parameters N(i) and L(i) may then be used in a cost function in order to group the sub-bands into regions (in block 21, as shown in more detail in
where: LMAX(j,k)=max{L(i)} for i=j . . . k
Using this cost function per region B(j,k) for all possible regions (determined in block 21a), i.e. where j,k can be varied to cover all possible sub-band combinations, the overall cost function for each possible region combination can be calculated as the sum of the cost functions for each individual region, i.e. for one possible region combination:
B
overall
=B(1,r1)+B(r1+1,r2)+ . . . +B(rn−1,K)
where there are K sub-bands being grouped into n regions and the values rx determine which sub-bands are included within each region. By iterating through the possible values of rx:
the overall cost functions for each possible region combination can be computed (block 21b) and the region combination with the minimum overall cost function selected (block 21c). As a result the spectrum is partitioned into the regions according to the combination with the minimum overall cost function. Having performed the spectral partitioning in this way, the optimum code table (e.g. Huffman code) can be selected for each region.
Typically for MP3, there are 22 sub-bands (K=22) being divided into three regions (n=3) and as described above there is a limit on the maximum size of each of the first and second regions. In such an example:
B
overall
=B(1,r1)+B(r1+1,r2)+B(r2+1,22)
where the values of r1,r2,r3 are iterated through all combinations of the following values:
r1=1 . . . 16
r
2
=r
1+1 . . . min(r1+8,21)
r
3
=r
2+1 . . . 22
There are many other estimates of bit requirements of each sub-band which may be used instead of, or in combination with, the estimate and/or parameters described above and some of the options are described in more detail below.
In a second example implementation, the cost function may be based on an estimate of Huffman bit requirements and, where linbits are required, also on an estimate of linbit requirements (which may for example be determined as described above).
Initially four parameters are determined for each of the sub-bands (block 61):
In some cases, the values of one or more of the parameters may be fixed. For example, for MP3 encoding, the number of frequency bins in a sub-band is fixed on a granule to granule basis and only varies with sample rate. As a result, the value of w(i) will generally be the same for the entirety of an audio file. In the example shown in
b
M(i)=ceil(log2X(i))
However, if X(i)≧Y (‘No’ in block 71 and ‘Yes’ or ‘No’ in block 72), then the number of bits used for encoding the maximum value excluding its linbits is a constant value given by:
b
M(i)=ceil(log2Y)
In MP3 applications, for example, Y=15, and therefore if X(i)≧Y then:
b
M(i)=4
In the example shown in
N(1)=2
L(1)=ceil(log2(30−15))=4
w(1)=4
b
M(1)=ceil(log215)=4
N(2)=0
L(2)=0
w(2)=4
b
M(2)=ceil(log210)=4
The four parameters (determined in block 60) may then be used to form a per-region cost function which is a combination (e.g. the sum) of an estimated number of Huffman bits required and an estimated number of linbits required (if any). The linbits term may be as described above, i.e.:
or alternatively any other measure of the number of linbits required may be used.
The Huffman bits estimate may be determined from the number of bits required to encode the largest value for any of the frequency bins in the region excluding its linbits (bMAX) multiplied by the sum of the number of frequency bins (or samples) in each sub-band in the region. This term may be written as:
where: bMAX(j,k)=max{bM(i)} for i=j . . . k
The cost function, B(j,k) for a single region starting from sub-band j and finishing at sub-band k can therefore be written as the sum of these two terms:
where: LMAX(j, k)=max{L(i)}for i=j . . . k and bMAX(j,k)=max{bM(i)} for i=j . . . k
Using the example of
Using the cost function per region B(j,k) detailed above for all possible regions, i.e. where j,k are varied to cover all possible sub-band combinations, the overall cost function for each possible region combination can be calculated (as above) as the sum of the cost functions for each individual region, i.e. for one possible region combination:
B
overall
=B(1,r1)+B(r1+1,r2)+ . . . +B(rn−1,K)
where there are K sub-bands being grouped into n regions and the values rx determine which sub-bands are included within each region. By iterating through the possible values of rx:
the overall cost functions for each possible region combination can be computed and the region combination with the minimum overall cost function selected (block 61):
where rx is the index of the last sub-band in region x and {right arrow over (r)} is the vector containing the resultant boundaries of each region. The first region (x=1) starts at sub-band 1 and the last region (x=K) ends at sub-band K. Results achieved using this method and this particular cost function are described below.
Whilst this second example implementation uses a combination of an estimate of the Huffman bit requirements and, where linbits are required, an estimate of the linbit requirements, in a further implementation, only an estimate of the Huffman bit requirements (i.e. the code bit requirements) may be used.
Using the methods described above, the minimum size of any region is one sub-band, although there may be constraints dependent upon the particular application which restrict region size further, e.g. for MP3 there are only a small number bits available to communicate the sizes of the first and second regions and this therefore puts a limit on the maximum size of these regions. As the third region comprises all the remaining sub-bands, the MP3 specification comprises no such maximum size limit on the third region.
In a further example implementation, the maximum number of linbits required by any of the sub-bands within the region (LMAX) may be used as the cost function, such that:
B(j,k)=LMAX(j,k)
where: LMAX(j,k)=max{L(i)} for i=j . . . k
In another implementation, the cost function may also include the number of bits required to encode the largest value for any of the frequency bins in the region (bMAX), such that the cost function comprises:
B(j,k)=bMAX(j,k)+LMAX(j,k)
where: LMAX(j,k)=max{L(i)}for i=j . . . k and bMAX(j,k)=max{bM(i)}for i=j . . . k
In another example implementation, the estimate of linbit requirements may use an average number of linbits required or fixed value instead of the maximum number of linbits required, L(i). In such an example the cost per region may be:
where L is a predefined parameter (e.g. a constant). This value L may be considered to be a per frequency bin penalty for use of linbits. In a further example this estimation of linbit requirements may be combined with a term for the Huffman bits (e.g. as described above with reference to
In a further variation, the value bMAX(j,k) may be replaced by a constant value bconst giving:
In an example, bconst may be set equal to ceil(log2 Y) although in such a situation the benefit of using the Huffman bit estimate term within the cost function may be limited given that w(i) is generally fixed. This may however be beneficial where a number of sub-bands are eliminated, for example because the audio in those sub-bands is completely masked.
In a further example implementation, the estimate of linbit requirements may be a determination of whether the sub-band uses linbits or not. In the example shown in
Linbits(i)=parameter of linbit requirements of sub-band i
Linbits(1)=1
Linbits(2)=0
In this example, the cost function B(j,k) for a region starting from sub-band j and finishing at sub-band k may comprise:
where a is a predefined parameter (e.g. a constant). This value, a, may be considered to be a per sub-band penalty for use of linbits.
In a further example implementation, the estimate of bit requirements may comprise an estimated average code length per frequency bin, e.g. an estimate of the required Huffman bits and any required linbits.
The spectral partitioning may be performed for an entire file or data group or alternatively may be performed for each portion of the file or data group. In the example of MP3 encoding, the spectral partitioning may be performed on a per-granule basis.
Whilst in MP3 applications, the search (in block 21 or 61) can be performed over the entire search space, in other applications the search space may be too large (e.g. because n and/or K are large). In some applications it may be beneficial to initially perform a coarser search (in block 21 or 61), e.g. using a coarser combination of sub-bands, to determine a trend and thereby seek a solution. In an example, the values rx may initially be iterated in steps of two or five, with the search being narrowed down such that values of rx need only be iterated in steps of one over a smaller search region. In another example, the partitioning obtained for the previous frame may be used as an initial partitioning with only a limited amount of deviation from those values being allowed in order to reduce the computational complexity.
Many of the calculations in the methods described above involve the calculation of a logarithm to the base 2. Such computations may be implemented within a DSP (digital signal processor) using an instruction which is designed to detect the number of sign bits of a number (e.g. for use in normalisation of a number or in fixed-point to floating-point conversion). The number of sign bits of a number may be defined as the number of positions by which the number is shifted in normalisation (this can alternatively be considered to be the number of positions by which the decimal position is moved) or the exponent of a normalised floating-point number. Examples of such an instruction include ‘SIGNDET’ (as used by CSR plc), ‘EXP’ (as used by Analog Devices) and ‘NORM’ (as used by Texas Instruments). Such an instruction returns (using the SIGNDET instruction name by way of example only):
y=SIGNDET(x)=z−└log2(|x+0.5|)┘−2
where z is the precision of the processor and └ ┘ rounds towards minus infinity.
Using such an instruction, the estimation of parameters L(i) and bM(i) can be approximately implemented on a DSP as:
L(i)=a−SIGNDET(X(i)−Y)
b
M(i)=b−SIGNDET(X(i)) where X(i)<Y
b
M(i)=b−SIGNDET(Y) where X(i)≧Y
where a and b are predefined parameters (e.g. constants). Whilst the instruction ‘SIGNDET’ (and its equivalents used by other DSP manufacturers) itself is known, it was intended for use in normalisation of numbers and this is a new application and use for the instruction.
The methods described above achieve near-perfect partitioning of the spectrum with many fewer MIPS than the optimum solution. Use of these methods results in saving about 5% in the resulting bitrate when compared to alternative algorithms. The table below shows some results achieved from use of the following cost function:
where: LMAX(j,k)=max{L(i)} for i=j . . . k and bMAX(j,k)=max{bM(i)} for i=j . . . k
The method was tested on 13,511 MP3 frames (approximately 5 minutes and 53 seconds) where each frame consisted of four granules and each granule was sub-divided into three regions (n=3, K=22). The nominal bitrate was 160 kbps.
These results show that the increase in bitrate using the proposed methods is small in comparison to the optimum solution. This small increase in bitrate is achieved at the same time as improving the speed by more than 43 times. In fact, as an encoder may use as little as 30 MIPS (or lower), the large overhead of the optimum solution makes it unfeasible in most applications. In comparison to the table look-up approach, the increase in bitrate is much smaller, because the table look-up approach encodes redundancies in the signal.
Whilst the MP3 specification limits the number of regions to three and provides restrictions on the number of sub-bands which may be in each of the first two regions, the method may also be applied where such limitations and restrictions do not apply. The methods may be applied to encoding of audio signals (e.g. using MP3 or AAC (Advanced Audio Coding)), video signals or other signal types (e.g. multimedia signals).
Whilst the above examples relate to MP3 audio encoding in which the sub-band boundaries are defined in the specification, this is by way of example only. The methods described herein may be applied to any type of signal and any encoding technology (e.g. AAC) and the sub-bands may match any perceptually meaningful division of frequency.
Furthermore, whilst the methods described herein may be used for spectral partitioning of the Big Values region for MP3 applications where the resultant regions are to be coded using one Huffman table per region, the methods are more broadly applicable. The techniques described may be used to partition a spectrum into regions with similar statistics and this partitioning may then be used in any manner and for any application. For example, the spectrum may be partitioned for other types of processing/analysis, such as speech recognition. The methods described above are not limited to MP3 encoding or to spectral partitioning for the purposes of encoding.
Any range or device value given herein may be extended or altered without losing the effect sought, as will be apparent to the skilled person.
It will be understood that the benefits and advantages described above may relate to one embodiment or may relate to several embodiments. It will further be understood that reference to an item refers to one or more of those items.
The steps of the methods described herein may be carried out in any suitable order, or simultaneously where appropriate. Additionally, individual blocks may be deleted from any of the methods without departing from the spirit and scope of the subject matter described herein. Aspects of any of the examples described above may be combined with aspects of any of the other examples described to form further examples without losing the effect sought.
It will be understood that the above description of a preferred embodiment is given by way of example only and that various modifications may be made by those skilled in the art.
Number | Date | Country | Kind |
---|---|---|---|
0721257.4 | Oct 2007 | GB | national |
Filing Document | Filing Date | Country | Kind | 371c Date |
---|---|---|---|---|
PCT/GB08/50803 | 9/9/2008 | WO | 00 | 3/24/2010 |