Patent Description:
Encoding methods for e.g. audio and/or video, typically comprise some type of quantization of signal segments. It is known that unconstrained vector quantization (VQ) is a useful quantization method for grouped samples, i.e. vectors, of a certain length. However, the memory and search complexity constraints have led to the development of structured vector quantizers. Different structures give different trade-offs in terms of search complexity and memory requirements. One such conventional method for structured vector quantization is the gain-shape vector quantization, where the target vector x is represented using a shape vector r and a gain G: <MAT>.

The concept of gain-shape vector quantization is to quantize a pair of gain and shape components {r, G} instead of directly quantizing the target vector. The gain and shape components are then encoded using a shape quantizer which is tuned for the normalized shape input, and a gain quantizer which handles the dynamics of the signal. This structure is commonly used in audio coding since the division into dynamics and shape, also denoted fine structure, fits well with the perceptual auditory model.

Further, many audio codecs such as IETF Opus and ITU-T G. <NUM> uses a gain-shape vector quantization to encode the spectral coefficients of the target audio signal. Both these codecs use a fixed band structure to partition the spectrum into multiple segments, and there is no adaptation of the band structure to any changes in the target vector.

One issue with gain shape quantization is to find a suitable vector length. Longer vectors give larger variations within the vector such that the shape quantizer needs to handle the dynamics of the signal. Shorter vectors reduce the dynamics within the vector, but may suffer from the fact the lower dimensionality of the shape VQ has less capability to exploit the sample correlation. In addition, the overhead for gain coding increases as the number of partitions increases, which leaves fewer bits for the for the shape coding. Document XP002737929 is directed to coding for low bit rate communication systems.

It is desired to achieve an efficient gain shape vector encoding and decoding.

The invention is provided as defined in the independent claims. Some preferred embodiments are described in the dependent claims.

The foregoing and other objects, features, and advantages of the technology disclosed herein will be apparent from the following more particular description of embodiments as illustrated in the accompanying drawings. The drawings are not necessarily to scale, emphasis instead being placed upon illustrating the principles of the technology disclosed herein.

A concept of embodiments described herein is to analyze the shape and determine a suitable resolution into sub-vectors, given a target vector of a certain size. This may reduce the quantization error, and increase perceived quality, in case of audio codec. Further, it is an aim of some embodiments described herein to find an optimal number of sections, i.e. number of splits of the target vector.

Embodiments herein relate to a method for supporting split gain shape vector encoding. The method is intended to be performed by a media encoder in situations where the encoding of each vector segment is subjected to a constraint related to a maximum number of bits, BMAX. That is, in situations where the maximum number of bits allowed for encoding of a vector segment is BMAX. This constraint may be due to e.g. processing capacity and/or memory capacity of the media encoder. A method according to an exemplifying embodiment will be described below with reference to <FIG>. The method illustrated in <FIG> comprises, for a target vector x, determining <NUM> an initial number, Np_init, of segments for the target vector x. The number Np_init could be determined based on e.g. BMAX and a bit budget, i.e. the number of bits allocated for encoding the entire vector x. The method further comprises determining <NUM> an average number of bits per segment, BAVG, based on the vector bit budget and Np_init. Note that the vector x need not actually be split on this stage, even though an initial number of segments and an average number of bits available for an initial vector segment have been determined. The method further comprises determining <NUM> a final number, Np, of segments to be used in the gain shape vector encoding, based on energies of the Np_init segments and a difference between BMAX and BAVG. By determining a final number of segments based on these paramters, an efficient allocation of the bits of the bit budget over the target vector is enabled, which will be described more in detail further below. The determining of a number of segments could alternatively be expressed as determining a number of splits, since the number of segments and the number of splits are closely related. Alternatively, the term split could be used to denote a segment.

The determined final number, Np, of segments may then be indicated to a media decoder, in order to enable the media decoder to adequately decode the encoded gain shape vector. It should be noted that it is not necessarily the actual number of segments that is indicated, but rather a change as compared to the determined initial number of segments. Regarding the determining of Np_init, this initial number of segments may be given for the encoder and decoder. In such cases the term "determining" would refer e.g. to establishing Np_init for use, or similar.

In one embodiment, illustrated in <FIG>, the determining of a final number of segments comprises increasing <NUM> the number of segments (and splits) when a relation between the energies of the Np_init segments and the difference between BMAX and BAVG fulfills a criterion. By "increasing" the number of segments is here meant increasing, as compared to the initial number Np_init, of segments. For example, the increase could be by one split (and segment), resulting in a final number of segments of Np= Np_init + <NUM>. The increase of the number of segments could then be indicated <NUM> to a media decoder in a suitable manner. It is advantageous to use as few bits as possible for indicating the final number of segments to a decoder. When the increase is a predetermined number of segments (or splits), e.g. one, the final increased number of segments (or splits), could be indicated to the media decoder using a single bit, which is often referred to as a flag. For example, the bit could be set to "<NUM>", or "true", when an increased number of segments is applied, and be set to "<NUM>", or "false", when the initial number of segments is to be used. That is, the determining of a final number of segments may further comprise to determine <NUM> that the initial number, Np_init, of segments, should be used, i.e. Np=Np_init when the relation between the energies of the Np_init segments and the difference between BMAX and BAVG does not fulfill the criterion, or, when a corresponding criterion is not met. This is illustrated as the action <NUM> in <FIG>.

The determining of a final number, Np, of segments may comprise increasing <NUM> the number of segments, as compared to the initial number, for the target vector x, when a maximum deviation, of a target vector segment energy, from an average per-segment energy value, EAVG, for the target vector x is larger than a threshold based on the difference between BMAX and BAVG. That is, an energy variation over the target vector segments may be compared to a threshold based on the difference between BMAX and BAVG. The logic behind using a maximum deviation from an average per-segment energy value, EAVG is, described in a simplified manner, that when there are large deviations from an average per-segment energy, there are large differences in the perceptual importance of the different segments. It should be noted that the "threshold" comparison could be expressed the other way around, such that the difference between BMAX and BAVG is compared to a threshold, which depends on, or is based on the energies of the Np_init segments. That is, the above could be expressed as that when the difference between BMAX and BAVG is smaller than a threshold depending on a maximum deviation, of a target vector segment energy, from an average per-segment energy value, EAVG, for the target vector x, the number of segments should be increased, etc. For example, this could be expressed as that the number of splits should be increased when M > α(BMAX - BAVG), or, when <MAT>; where either α(BMAX - BAVG) or <MAT> may be denoted threshold. Regarding the energies of the segments, the log-energy per-segment may be calculated as: <MAT> where i is a segment index and k is a sample index.

The average per-segment energy may then be defined as: <MAT>.

A measure of energy variations may then be defined as the absolute maximum log energy deviation from the mean as: <MAT>.

The determining, or decision, of when to add an additional split may be based on testing whether the energy variation measure M is above a certain threshold based on BMAX and BAVG as:.

<FIG> illustrates a mean energy per segment (black dots) and total average energy EAVG (average of the segment averages). To minimize the coding distortion, it is desired to use more bits for encoding segments comprising more energy than for encoding segments comprising less energy. Thus, when there is large variation in energy between segments, it would be desired to reallocate bits from segments comprising less energy to segments comprising more energy, assuming that all segments initially are allocated at least approximately BAVG bits, i.e. assuming an initial even distribution of the bits over the segments. <FIG> is a simple graph illustrating a number of segments, a BMAX value and a BAVG value. When the difference between BMAX and BAVG, which could also be denoted the headroom herein, is "small", e.g. smaller than a threshold, it will not be possible to reallocate that many bits to the high energy content segments, before reaching BMAX. However, by increasing the number of segments, BAVG will be reduced, which is illustrated by a dashed arrow in <FIG>, and thus increase the possibility to allocate more bits to high energy content segments. By increasing the number of segments, a higher positive deviation, in number of bits, is allowed from BAVG, which enables reallocation of bits. The maximum allowed positive deviation is BMAX - BAVG. The term reallocation here does not imply that an average number BAVG of bits is actually allocated to each segment before reallocating, but is only used to facilitate understanding of the solution provided herein.

An exemplifying embodiment could be described as: when an energy variation between the vector segments is "large" in relation to a headroom, BMAX - BAVG, the number of splits and segments is increased by "<NUM>", which is then indicated to a decoder by the setting of a one-bit flag. The determining of "large" may be performed by use of a threshold value, which may be selected based on e.g. simulations. This embodiment is illustrated in <FIG>. In <FIG>, the energy variation is denoted M, and in this example, the threshold MTHR is based on BMAX - BAVG. Different examples of expressions for an energy variation will be described further below.

Since the difference between BMAX and BAVG, i.e. the headroom, is a number of bits, which should be compared to an energy variation, e.g. a maximum deviation from an average, which is an energy measure, a tuning parameter α may be used to make the decision threshold proportional to the headroom. A value of α may be derived e.g. based on simulations.

Further, there are situations where it is not considered meaningful to perform the analysis of the number of segments described above. By analysis is here meant the determining <NUM> of BAVG and the determining <NUM> of a final number of segments In such situations, it is not desired to perform the analysis or to waste bits on indicating a number of segments to the decoder. Therefore, the performing of the analysis, and the indicating of a result, may be conditioned, i.e. only be performed when at least one additional condition is met. One such additional condition may be that the vector bit budget is above a threshold. The reason for such a condition would be that when the bit budget is low, there are not that many bits to reallocate to other segments. Another additional condition could be that the initial number of splits or sections should be below a threshold. The reason for such a condition would be e.g. complexity constraints.

It should be noted that the embodiments described above are intended to be non-recursive, which implies a low complexity. This may be advantageous, as compared to more resource-demanding recursive methods. It should further be note that the segments are intended to be at least approximately evenly distributed over the vector, i.e. be of, at least approximately, equal size. This may also be an advantage, as compared to methods generating segments of very different sizes.

Embodiments herein further relate to a method for supporting split gain shape vector decoding. The method corresponds to the encoding method described above. The method is intended to be performed by a media decoder in situations where a representation of each vector segment of a gain shape vector x is subjected to a constraint related to a maximum number of bits, BMAX, allowed for encoding a vector segment. The term "media" is here intended to refer to e.g. audio and/or video. A method according to an exemplifying embodiment will be described below with reference to <FIG>. The method illustrated in <FIG> comprises determining <NUM> an initial number, Np_init, of segments, for a vector to be reconstructed xq; The method further comprises receiving <NUM> an indication, from a media encoder, of whether an increased number of segments is applied for the vector xq, or not, and determining <NUM> a final number of segments for the decoding of the vector xq based on the initial number of segments and the received indication. The vector xq may then be decoded <NUM> based on the final number of segments. The indication may, in analogy with the example on the encoder side, be received in form of a bit-flag, which is set to e.g. "<NUM>" when an additional split is to be applied, Np=Np_init + <NUM>, and to "<NUM>" when the initial number of segments is to be used, Np=Np_init. The use of a flag as indicator is also illustrated in <FIG>.

In correspondence with the encoder side, the receiving of an indication may be conditioned, and thus only performed when one or more additional conditions are met. The same conditions should be used on the encoder and decoder side. Such additional conditions may, as previously stated, be e.g. that the vector bit budget is above a threshold T1, and that the initial number of splits or segments is below a threshold T2, and/or that the bitrate per sample BSAMPLE is above a given limit. (T1 and T2 are just used to indicate that it is not the same threshold for the two cases). Below some more details and variants of the solution provided herein will be described. Embodiments of a media encoder and media decoder corresponding to the methods embodiments described above will be described at the end of the detailed description.

Energy variations across a target vector can be captured by splitting the target vector into smaller sections. The benefit of the split will depend on the energy distribution of the target vector. This can be illustrated by calculating the variance σ<NUM> of the target signal after normalizing the energies in each section. Assuming that the sections have equal size, this can be expressed as <MAT> where the <MAT> is the variance of section i, and Np is the number of segments.

Typically the variance value decreases fast for the first few number of splits but then saturates, as illustrated in <FIG>. Looking at the shape of the graph in <FIG>, the saturation point can be interpreted as the point where further resolution in more sections is not needed. Further, it may be noted that this curve will always converge to zero since the final split will result in sections containing one sample each with variance zero. An example target vector with corresponding section energies for <NUM> and <NUM>-way split is shown in <FIG>.

In another embodiment, the variance of the energies among the sections/segments is compared for different split configurations, i.e. for different numbers of segments. A large increase in variance between different split configurations, e.g. <NUM> segments vs. <NUM> segments, indicates that it would be beneficial with additional splitting of the target vector. The variance V is computed as <MAT> with the energy per coefficient in a segment i: <MAT>.

<FIG> illustrates an example target vector (upper figure) and the corresponding segment energies for <NUM> (middle figure) and <NUM>-way (lower figure) split, respectively, of the example target vector. In <FIG>, the corresponding variance of the segment energies is shown for a varying number of segments. Considering the change from <NUM> segments to <NUM> segments, the variance V is increasing, which then indicates that a split into <NUM> segments would be beneficial over a split into <NUM> segments.

In an embodiment the decision for additional split is made on basis of:
<IMG>
where β is a lower threshold for the increase in variance of the segment energies between two consecutive number of splits. When the increase in variance is sufficient, i.e. in this example exceeds the threshold β, the number of segments is increased, e.g. by one. As previously mentioned, the use of an additional split could be signalled from the encoder to the decoder by, for example, using one bit for signalling one additional split or no additional split. However, more bits could be used for signalling more than one additional split if preferred.

A variation on the embodiment above is to directly use the average energy per coefficient Ecoeff in normalized segments as a measure of the energy variations. The motivation for doing this is that when the average energy per coefficient does not change much between two consecutive number of splits, the distribution within each segment is similar and does not benefit from further splitting, while a large change between two consecutive number of splits motivates an additional split. The decision can be made based on a threshold γ similar to the above expression:
<IMG>.

In another embodiment, assuming that and initial number of segments Np_init is given, e.g., due to quantizer constraints, the algorithm makes a decision to increase Np_init or not with the following procedure:
First, the log-energy per-segment is calculated as: <MAT>.

The average per-segment energy is then defined as: <MAT>.

A measure of energy variations is defined as the absolute maximum log energy deviation from the mean: <MAT>.

The absolute is used in case it is essential to trigger on any large deviation from mean value, be it positive or negative. In some cases, only the upper limit is of importance, in which case the absolute value may be omitted, as: <MAT>.

In yet another embodiment, the lower limit may be of larger importance, and the measure may then be defined to find the smallest negative deviation: <MAT>.

In all exemplary embodiments of the energy deviation measure, the intent is to increase the number of splits in case the estimated energy deviation is large. The reason is that an additional split should provide slightly more freedom to allocate the bits locally, as previously described. The decision when to add an additional split may be based on testing whether the energy variation measure M is above a certain threshold MTHR as (which is also illustrated in <FIG>):
<IMG>.

In one embodiment, the decision for additional split may also be affected by the constraints on the encoder for the different sections or segments. In such cases, an additional split may be needed if the necessary bit allocation cannot be fit below the maximum number of bits for each section or segment, BMAX. As previously mentioned, the difference between the maximum number of bits per section BMAX and the average number of bits per section BAVG may be denoted the headroom for the bit allocation (BMAX - BAVG). The average bits per band may be calculated as <MAT> where BBAND denotes the number of bits for the given band, i.e. the bit budget for a target vector representing the band. The term "band" could here be interpreted e.g. as the frequency band, which the target vector represents. Further, the decision threshold may be adjusted using a tuning parameter α to make the decision threshold proportional to the headroom:
<IMG>.

The decision to use an additional split may also be encoded as a parameter and sent from the encoder to the decoder. To ensure that the additional split signalling is only done when it is needed, e.g. since it requires an extra bit when used, the above algorithm may be restricted to be used only is situations where it may be beneficial. For instance, it may be limited to be used only when the initial number of splits or segments Np_init is below a maximum number of splits or segments, e.g. NP_init < NP,max and/or when the bitrate per sample BSAMPLE is above a given limit, e.g. BSAMPLE >BSAMPLE,THR. To be synchronized, the same condition should be used in the encoder and decoder for correct bitstream decoding.

It is an advantage of the embodiments that they may improve the performance of gain-shape quantization schemes. The criterion for split requires insignificant additional computational complexity, and since quantizing smaller segments is less complex than quantizing the entire target vector, the proposed algorithm of the embodiments may also achieve a reduction in computational complexity.

The methods and techniques described above may be implemented in encoders and decoders, which may be part of other devices.

An exemplifying embodiment of a media encoder is illustrated in a general manner in <FIG>. By media encoder is referred to an encoder for e.g. audio and/or video signals. The encoder <NUM> is configured to perform at least one of the method embodiments described above with reference to any of <FIG> and <FIG>. The encoder <NUM> is associated with the same technical features, objects and advantages as the previously described method embodiments. The encoder will be described in brief in order to avoid unnecessary repetition.

The encoder may be implemented and/or described as follows:
The encoder <NUM> is configured for split gain shape vector encoding. The encoder <NUM> comprises processing circuitry, or processing means <NUM> and a communication interface <NUM>. The processing circuitry <NUM> is configured to cause the encoder <NUM> to, for a target shape vector x: determine an initial number Np_init of segments, and further to determine an average number of bits per segment, BAVG, based on a vector bit budget and Np_init. The processing circuitry <NUM> is further configured to cause the encoder to determine a final number of segments to be used in the gain shape vector encoding based on energies of the Np_init segments and a difference between BMAX and BAVG. The communication interface <NUM>, which may also be denoted e.g. Input/Output (I/O) interface, includes an interface for sending data to and receiving data from other entities or modules.

The processing circuitry <NUM> could, as illustrated in <FIG>, comprise processing means, such as a processor <NUM>, e.g. a CPU, and a memory <NUM> for storing or holding instructions. The memory would then comprise instructions, e.g. in form of a computer program <NUM>, which when executed by the processing means <NUM> causes the encoder <NUM> to perform the actions described above.

An alternative implementation of the processing circuitry <NUM> is shown in <FIG>. The processing circuitry here comprises a first determining unit <NUM>, configured to cause the encoder <NUM> to: determine an initial number Np_init of segments for a target shape vector x. The processing circuitry further comprises a second determining unit <NUM> configured to cause the encoder to determine an average number of bits per segment, BAVG, based on a vector bit budget and Np_init. The processing circuitry further comprises a third determining unit <NUM>, configured to cause the encoder to determine a final number of segments, for the vector x, to be used in the gain shape vector encoding, based on energies of the Np_init segments and a difference between BMAX and BAVG. The processing circuitry <NUM> could comprise more units, such as an indicating unit <NUM> configured to cause the encoder to indicate the final number of segments, e.g. an increase by one segment as compared to the initial number, to a media decoder. This task could alternatively be performed by one of the other units.

The encoders described above could be configured for the different method embodiments described herein, such as increasing the number of segments, as compared to the initial number, for the target vector x for the gain shape vector encoding when a maximum deviation, of a target vector segment energy, from an average per-segment energy value, EAVG, for the target vector x is larger than a threshold based on the difference between BMAX and BAVG.

The encoder <NUM> may be assumed to comprise further functionality, for carrying out regular encoder functions.

Embodiments herein also relate to a media decoder <NUM> configured for carrying out embodiments of the decoding method described above. That is, the method for supporting split gain shape vector decoding, illustrated e.g. in <FIG>. An exemplifying embodiment of a decoder <NUM> is illustrated in a general manner in <FIG>. The decoder <NUM> is configured to perform at least one of the method embodiments described above with reference to <FIG>. The decoder <NUM> is associated with the same technical features, objects and advantages as the previously described method embodiments. The decoder will be described in brief in order to avoid unnecessary repetition.

The decoder <NUM> is configured for supporting split gain shape vector decoding, and is operable to perform split gain shape vector decoding. The decoder <NUM> comprises processing circuitry <NUM> and a communication interface <NUM>. The processing circuitry <NUM> is configured to cause the network node to determine an initial number Np_init, for a vector xq to be reconstructed; and further to receive an indication, from a media encoder, of whether an increased number of segments is applied for the vector xq, or not. The processing circuitry <NUM> is further configured to cause the network node to determine a final number of segments for the decoding of the vector xq based on the received indication. The communication interface <NUM>, which may also be denoted e.g. Input/Output (I/O) interface, includes an interface for sending data to and receiving data from other entities or modules.

The processing circuitry <NUM> could, as illustrated in <FIG>, comprise processing means, such as a processor <NUM>, and a memory <NUM> for storing or holding instructions. The memory would then comprise instructions, e.g. in form of computer program <NUM>, which when executed by the processing means <NUM> causes the network node <NUM> to perform the actions described above.

An alternative implementation of the processing circuitry <NUM> is shown in <FIG>. The processing circuitry here comprises a first determining unit <NUM>, configured to cause the network node to determine an initial number of segments, Np_init, for a vector xq to be reconstructed. The processing circuitry <NUM> further comprises a receiving unit <NUM>, configured to cause the network node to receive an indication, from a media encoder, of whether an increased number of segments is applied for the vector xq, or not. The processing circuitry <NUM> further comprises a second determining unit <NUM>, configured to cause the network node to determine a final number of segments for the decoding of the vector xq based on the received indication.

The network node <NUM> may be assumed to comprise further functionality, for carrying out regular decoder functions.

The encoder and decoder could alternatively be described and/or implemented as illustrated in <FIG> is a schematic block diagram of a split algorithm encoder and decoder according to embodiments of the herein suggested solution. The encoder comprises an initial split decider unit, an energy variation analyzer unit, and a split encoder unit. The decoder comprises an initial split decider, and a decision decoder. The encoder and the decoder with its included units could be implemented in hardware and/or software.

The encoder and decoder described herein could alternatively be implemented e.g. by one or more of a processor and adequate software with suitable storage or memory therefore, in order to perform the determining of an adequate number of splits and/or segments of an input vector, according to the embodiments described herein, see <FIG>. For the encoder illustrated in <FIG>, the incoming vector is received by an input (IN), to which the processor and the memory are connected, and the encoded representation of the vector, e.g. an audio signal (parameters), obtained from the software is outputted from the output (OUT).

The decoder described herein could be implemented e.g. by one or more of a processor and adequate software with suitable storage or memory therefore, in order to perform the decoding of the input parameters, according to the embodiments described herein, see <FIG>. The incoming parameters are received by an input (IN), to which the processor and the memory are connected, and the decoded signal obtained from the software is outputted from the output (OUT).

The technology described above may be comprised e.g. in a wireless device such as e.g. a user equipment, a mobile terminal, a tablet, a mobile wireless device for machine-to-machine communication, an integrated or embedded wireless card, an externally plugged in wireless card, a dongle, etc, or in a stationary or semi stationary device, such as a personal computer or a smart TV.

The steps, functions, procedures, modules, units and/or blocks described herein may be implemented in hardware using any conventional technology, such as discrete circuit or integrated circuit technology, including both general-purpose electronic circuitry and application-specific circuitry.

Particular examples include one or more suitably configured digital signal processors and other known electronic circuits, e.g. discrete logic gates interconnected to perform a specialized function, or Application Specific Integrated Circuits (ASICs).

Alternatively, at least some of the steps, functions, procedures, modules, units and/or blocks described above may be implemented in software such as a computer program for execution by suitable processing circuitry including one or more processing units. The software could be carried by a carrier, such as an electronic signal, an optical signal, a radio signal, or a computer readable storage medium before and/or during the use of the computer program in the network nodes.

The flow diagram or diagrams presented herein may be regarded as a computer flow diagram or diagrams, when performed by one or more processors. A corresponding apparatus may be defined as a group of function modules, where each step performed by the processor corresponds to a function module. In this case, the function modules are implemented as a computer program running on the processor.

Examples of processing circuitry includes, but is not limited to, one or more microprocessors, one or more Digital Signal Processors, DSPs, one or more Central Processing Units, CPUs, and/or any suitable programmable logic circuitry such as one or more Field Programmable Gate Arrays, FPGAs, or one or more Programmable Logic Controllers, PLCs. That is, the units or modules in the arrangements in the different nodes described above could be implemented by a combination of analog and digital circuits, and/or one or more processors configured with software and/or firmware, e.g. stored in a memory. One or more of these processors, as well as the other digital hardware, may be included in a single application-specific integrated circuitry, ASIC, or several processors and various digital hardware may be distributed among several separate components, whether individually packaged or assembled into a system-on-a-chip, SoC.

The embodiments described above are merely given as examples, and it should be understood that the proposed technology is not limited thereto. It will be understood by those skilled in the art that various modifications, combinations and changes may be made to the embodiments without departing from the present scope. In particular, different part solutions in the different embodiments can be combined in other configurations, where technically possible.

When using the word "comprise" or "comprising" it shall be interpreted as nonlimiting, i.e. meaning "consist at least of".

It is to be understood that the choice of interacting units, as well as the naming of the units within this disclosure are only for exemplifying purpose, and nodes suitable to execute any of the methods described above may be configured in a plurality of alternative ways in order to be able to execute the suggested procedure actions.

It should also be noted that the units described in this disclosure are to be regarded as logical entities and not with necessity as separate physical entities.

Reference to an element in the singular is not intended to mean "one and only one" unless explicitly so stated, but rather "one or more. " All structural and functional equivalents to the elements of the above-described embodiments that are known to those of ordinary skill in the art are expressly incorporated herein by reference and are intended to be encompassed hereby. Moreover, it is not necessary for a device or method to address each and every problem sought to be solved by the technology disclosed herein, for it to be encompassed hereby.

Claim 1:
A method for gain shape vector encoding performed by an audio encoder, where the encoding of each vector segment is subjected to a constraint related to a maximum number of bits, BMAX, allowed for encoding a vector segment, the method comprising:
- determining (<NUM>, <NUM>) an initial number, Np_init, of segments for a target vector x based at least on BMAX and number of bits allocated for encoding the entire vector x;
- determining a log-energy of each Np_init target vector segment by summing energies of samples within the vector segment;
- determining (<NUM>, <NUM>) an average number of bits per segment, BAVG, based on the number of bits allocated for encoding the entire vector x and Np_init;
- determining (<NUM>) a final number of segments to be used in the gain shape vector encoding by increasing (<NUM>) the number of segments, as compared to the initial number, for the target vector x, when the difference between BMAX and BAVG is smaller than a threshold (<NUM>), wherein the threshold depends on a maximum deviation of a target vector segment energy from an average per-segment energy value, EAVG, for the target vector x.