Go to the source code of this file.
Data Structures | |
struct | plc_state_t |
Defines | |
#define | _SPANDSP_PLC_H_ |
#define | CORRELATION_SPAN 160 |
#define | PLC_HISTORY_LEN (CORRELATION_SPAN + PLC_PITCH_MIN) |
#define | PLC_PITCH_MAX 40 |
#define | PLC_PITCH_MIN 120 |
#define | PLC_PITCH_OVERLAP_MAX (PLC_PITCH_MIN >> 2) |
Functions | |
int | plc_fillin (plc_state_t *s, int16_t amp[], int len) |
Fill-in a block of missing audio samples. | |
plc_state_t * | plc_init (plc_state_t *s) |
Process a block of received V.29 modem audio samples. | |
int | plc_rx (plc_state_t *s, int16_t amp[], int len) |
Process a block of received audio samples. |
All rights reserved.
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
This version may be optionally licenced under the GNU LGPL licence.
A license has been granted to Digium (via disclaimer) for the use of this code.
Definition in file plc.h.
#define CORRELATION_SPAN 160 |
The length over which the AMDF function looks for similarity (20 ms)
Definition at line 99 of file plc.h.
Referenced by plc_fillin().
#define PLC_HISTORY_LEN (CORRELATION_SPAN + PLC_PITCH_MIN) |
History buffer length. The buffer much also be at leat 1.25 times PLC_PITCH_MIN, but that is much smaller than the buffer needs to be for the pitch assessment.
Definition at line 103 of file plc.h.
Referenced by normalise_history(), plc_fillin(), and save_history().
#define PLC_PITCH_MAX 40 |
#define PLC_PITCH_MIN 120 |
#define PLC_PITCH_OVERLAP_MAX (PLC_PITCH_MIN >> 2) |
int plc_fillin | ( | plc_state_t * | s, | |
int16_t | amp[], | |||
int | len | |||
) |
Fill-in a block of missing audio samples.
Fill-in a block of missing audio samples.
s | The packet loss concealer context. | |
amp | The audio sample buffer. | |
len | The number of samples to be synthesised. |
Definition at line 171 of file plc.c.
References amdf_pitch(), ATTENUATION_INCREMENT, CORRELATION_SPAN, fsaturate(), normalise_history(), PLC_HISTORY_LEN, PLC_PITCH_MAX, PLC_PITCH_MIN, s, and save_history().
Referenced by framein().
00172 { 00173 int i; 00174 int pitch_overlap; 00175 float old_step; 00176 float new_step; 00177 float old_weight; 00178 float new_weight; 00179 float gain; 00180 int16_t *orig_amp; 00181 int orig_len; 00182 00183 orig_amp = amp; 00184 orig_len = len; 00185 if (s->missing_samples == 0) { 00186 /* As the gap in real speech starts we need to assess the last known pitch, 00187 and prepare the synthetic data we will use for fill-in */ 00188 normalise_history(s); 00189 s->pitch = amdf_pitch(PLC_PITCH_MIN, PLC_PITCH_MAX, s->history + PLC_HISTORY_LEN - CORRELATION_SPAN - PLC_PITCH_MIN, CORRELATION_SPAN); 00190 /* We overlap a 1/4 wavelength */ 00191 pitch_overlap = s->pitch >> 2; 00192 /* Cook up a single cycle of pitch, using a single of the real signal with 1/4 00193 cycle OLA'ed to make the ends join up nicely */ 00194 /* The first 3/4 of the cycle is a simple copy */ 00195 for (i = 0; i < s->pitch - pitch_overlap; i++) 00196 s->pitchbuf[i] = s->history[PLC_HISTORY_LEN - s->pitch + i]; 00197 /* The last 1/4 of the cycle is overlapped with the end of the previous cycle */ 00198 new_step = 1.0/pitch_overlap; 00199 new_weight = new_step; 00200 for ( ; i < s->pitch; i++) { 00201 s->pitchbuf[i] = s->history[PLC_HISTORY_LEN - s->pitch + i] * (1.0 - new_weight) + s->history[PLC_HISTORY_LEN - 2 * s->pitch + i]*new_weight; 00202 new_weight += new_step; 00203 } 00204 /* We should now be ready to fill in the gap with repeated, decaying cycles 00205 of what is in pitchbuf */ 00206 00207 /* We need to OLA the first 1/4 wavelength of the synthetic data, to smooth 00208 it into the previous real data. To avoid the need to introduce a delay 00209 in the stream, reverse the last 1/4 wavelength, and OLA with that. */ 00210 gain = 1.0; 00211 new_step = 1.0 / pitch_overlap; 00212 old_step = new_step; 00213 new_weight = new_step; 00214 old_weight = 1.0 - new_step; 00215 for (i = 0; i < pitch_overlap; i++) { 00216 amp[i] = fsaturate(old_weight * s->history[PLC_HISTORY_LEN - 1 - i] + new_weight * s->pitchbuf[i]); 00217 new_weight += new_step; 00218 old_weight -= old_step; 00219 if (old_weight < 0.0) 00220 old_weight = 0.0; 00221 } 00222 s->pitch_offset = i; 00223 } else { 00224 gain = 1.0 - s->missing_samples*ATTENUATION_INCREMENT; 00225 i = 0; 00226 } 00227 for ( ; gain > 0.0 && i < len; i++) { 00228 amp[i] = s->pitchbuf[s->pitch_offset] * gain; 00229 gain -= ATTENUATION_INCREMENT; 00230 if (++s->pitch_offset >= s->pitch) 00231 s->pitch_offset = 0; 00232 } 00233 for ( ; i < len; i++) 00234 amp[i] = 0; 00235 s->missing_samples += orig_len; 00236 save_history(s, amp, len); 00237 return len; 00238 }
plc_state_t* plc_init | ( | plc_state_t * | s | ) |
Process a block of received V.29 modem audio samples.
Process a block of received V.29 modem audio samples.
s | The packet loss concealer context. |
Definition at line 242 of file plc.c.
References s.
00243 { 00244 memset(s, 0, sizeof(*s)); 00245 return s; 00246 }
int plc_rx | ( | plc_state_t * | s, | |
int16_t | amp[], | |||
int | len | |||
) |
Process a block of received audio samples.
Process a block of received audio samples.
s | The packet loss concealer context. | |
amp | The audio sample buffer. | |
len | The number of samples in the buffer. |
Definition at line 128 of file plc.c.
References ATTENUATION_INCREMENT, fsaturate(), s, and save_history().
Referenced by framein().
00129 { 00130 int i; 00131 int pitch_overlap; 00132 float old_step; 00133 float new_step; 00134 float old_weight; 00135 float new_weight; 00136 float gain; 00137 00138 if (s->missing_samples) { 00139 /* Although we have a real signal, we need to smooth it to fit well 00140 with the synthetic signal we used for the previous block */ 00141 00142 /* The start of the real data is overlapped with the next 1/4 cycle 00143 of the synthetic data. */ 00144 pitch_overlap = s->pitch >> 2; 00145 if (pitch_overlap > len) 00146 pitch_overlap = len; 00147 gain = 1.0 - s->missing_samples*ATTENUATION_INCREMENT; 00148 if (gain < 0.0) 00149 gain = 0.0; 00150 new_step = 1.0/pitch_overlap; 00151 old_step = new_step*gain; 00152 new_weight = new_step; 00153 old_weight = (1.0 - new_step)*gain; 00154 for (i = 0; i < pitch_overlap; i++) { 00155 amp[i] = fsaturate(old_weight * s->pitchbuf[s->pitch_offset] + new_weight * amp[i]); 00156 if (++s->pitch_offset >= s->pitch) 00157 s->pitch_offset = 0; 00158 new_weight += new_step; 00159 old_weight -= old_step; 00160 if (old_weight < 0.0) 00161 old_weight = 0.0; 00162 } 00163 s->missing_samples = 0; 00164 } 00165 save_history(s, amp, len); 00166 return len; 00167 }