Method and apparatus for compensating for voice packet loss
Embodiments of the present invention disclose a method and an apparatus for compensating for a voice packet loss, which are used to compensate for a lost voice packet. The method in the embodiments of the present invention includes: extracting a pitch period from received voice data when a lost frame is detected; calculating a backward phase of a last received frame of normal voice data; calculating a forward phase of the lost frame according to the backward phase; capturing, from the received data, data whose last frame is with a same phase as the forward phase, as compensation data.
1. A method for acquiring compensation data, the method comprising:
extracting a pitch period from received voice data when a lost frame in the received voice data is detected;
calculating a backward phase of a last received frame of normal voice data in the received voice data, wherein the backward phase is a time interval between an end of the last received frame and a wave crest of a last pitch period of the last received frame, and the last received frame is a last normal frame received before the lost frame;
calculating a forward phase of the lost frame, wherein the forward phase is a time interval between a beginning of the lost frame and a wave crest of a first pitch period of the lost frame, and is calculated as a difference between the pitch period and the backward phase;
correcting the forward phase of the lost frame according to a forward phase change value of the received voice data; and
capturing, from the received voice data, data whose last frame is with a same phase as the forward phase, as compensation data.
2. The method according to claim 1 , wherein correcting the forward phase according to a phase change value of the received voice data comprises:
adding the forward phase and a difference between forward phases of two frames previous to the last received frame, so as to obtain a correction value of the forward phase.
3. The method according to claim 1 , wherein after correcting the forward phase according to a phase change value of the received voice data, the method comprises:
correcting a frequency and an amplitude of the compensation data.
4. The method according to claim 3 , wherein correcting a frequency and an amplitude of the compensation data comprises:
adding a frequency of the compensation data at a current moment in time and a difference between frequencies of the two frames previous to the last frame, so as to obtain a correction value of the frequency of the compensation data; and
adding an amplitude of the compensation data at the current moment in time and a difference between amplitudes of the two frames previous to the last frame, so as to obtain a correction value of the amplitude of the compensation data.
5. The method according to claim 3 , wherein after correcting the frequency and the amplitude of the compensation data, the method comprises:
smoothing an amplitude of the corrected compensation data according to an amplitude of the compensation data at a current moment in time and a difference value at a frame boundary between the compensation data and a frame previous to the compensation data.
6. An apparatus, comprising: a processor and a memory, wherein the memory stores instructions, the processor communicates with the memory when the apparatus runs, and the processor executes the instructions to cause the apparatus to perform the following:
extracting a pitch period from received voice data when a lost frame in the received voice data is detected;
calculating a backward phase of a last received frame of normal voice data in the received voice data, wherein the backward phase is a time interval between an end of the last received frame and a wave crest of a last pitch period of the last received frame, and the last received frame is a last normal frame received before the lost frame;
calculating a forward phase of the lost frame, wherein the forward phase is a time interval between a beginning of the lost frame and a wave crest of a first pitch period of the lost frame, and is calculated as a difference between the pitch period and the backward phase;
correcting the forward phase of the lost frame according to a phase change value of the received voice data; and
capturing, from the received voice data, data whose last frame is with a same phase as the forward phase, as compensation data.
7. The apparatus according to claim 6 , wherein the apparatus is further caused to perform:
adding the forward phase and a difference between forward phases of two frames previous to the last received frame, so as to obtain a correction value of the forward phase;
adding a frequency of the compensation data at a current moment in time and a difference between frequencies of the two frames previous to the last frame, so as to obtain a correction value of the frequency of the compensation data; and
adding an amplitude of the compensation data at a current moment in time and a difference between amplitudes of the two frames previous to the last frame, so as to obtain a correction value of the amplitude of the compensation data.
8. The apparatus according to claim 6 , wherein the apparatus is further caused to perform:
correcting a frequency and an amplitude of the compensation data.
9. The apparatus according to claim 8 , wherein the apparatus is further caused to perform:
smoothing an amplitude of the corrected compensation data according to an amplitude of the compensation data at a current moment in time and a difference value at a frame boundary between the compensation data and a frame previous to the compensation data after correcting the frequency and the amplitude of the compensation data.