1. A method for encoding performed by a media encoder, the method comprising: for a target vector x: determining an initial number (Np_init) of segments for the target vector x, wherein a number of bits B band have been allocated to the target vector x; determining an average number of bits per segment (Bavg), wherein determining Bavg comprises computing: Bavg=(B band /Np_init); and determining a final number (Np) of segments for the target vector to be used during the encoding based on energies of the Np_init segments and a difference between a maximum number of bits (Bmax) and B avg.