formatting fixups (bug #4769)

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@6184 65c4cc65-6c06-0410-ace0-fbb531ad65f3
1.2-netsec
Russell Bryant 20 years ago
parent 6eb0ec533e
commit 4f007c8192

39
plc.c

@ -69,15 +69,13 @@ static inline int16_t fsaturate(double damp)
static void save_history(plc_state_t *s, int16_t *buf, int len)
{
if (len >= PLC_HISTORY_LEN)
{
if (len >= PLC_HISTORY_LEN) {
/* Just keep the last part of the new data, starting at the beginning of the buffer */
memcpy(s->history, buf + len - PLC_HISTORY_LEN, sizeof(int16_t)*PLC_HISTORY_LEN);
s->buf_ptr = 0;
return;
}
if (s->buf_ptr + len > PLC_HISTORY_LEN)
{
if (s->buf_ptr + len > PLC_HISTORY_LEN) {
/* Wraps around - must break into two sections */
memcpy(s->history + s->buf_ptr, buf, sizeof(int16_t)*(PLC_HISTORY_LEN - s->buf_ptr));
len -= (PLC_HISTORY_LEN - s->buf_ptr);
@ -89,6 +87,7 @@ static void save_history(plc_state_t *s, int16_t *buf, int len)
memcpy(s->history + s->buf_ptr, buf, sizeof(int16_t)*len);
s->buf_ptr += len;
}
/*- End of function --------------------------------------------------------*/
static void normalise_history(plc_state_t *s)
@ -102,6 +101,7 @@ static void normalise_history(plc_state_t *s)
memcpy(s->history + PLC_HISTORY_LEN - s->buf_ptr, tmp, sizeof(int16_t)*s->buf_ptr);
s->buf_ptr = 0;
}
/*- End of function --------------------------------------------------------*/
static int __inline__ amdf_pitch(int min_pitch, int max_pitch, int16_t amp[], int len)
@ -114,19 +114,18 @@ static int __inline__ amdf_pitch(int min_pitch, int max_pitch, int16_t amp[], in
pitch = min_pitch;
min_acc = INT_MAX;
for (i = max_pitch; i <= min_pitch; i++)
{
for (i = max_pitch; i <= min_pitch; i++) {
acc = 0;
for (j = 0; j < len; j++)
acc += abs(amp[i + j] - amp[j]);
if (acc < min_acc)
{
if (acc < min_acc) {
min_acc = acc;
pitch = i;
}
}
return pitch;
}
/*- End of function --------------------------------------------------------*/
int plc_rx(plc_state_t *s, int16_t amp[], int len)
@ -139,8 +138,7 @@ int plc_rx(plc_state_t *s, int16_t amp[], int len)
float new_weight;
float gain;
if (s->missing_samples)
{
if (s->missing_samples) {
/* Although we have a real signal, we need to smooth it to fit well
with the synthetic signal we used for the previous block */
@ -156,8 +154,7 @@ int plc_rx(plc_state_t *s, int16_t amp[], int len)
old_step = new_step*gain;
new_weight = new_step;
old_weight = (1.0 - new_step)*gain;
for (i = 0; i < pitch_overlap; i++)
{
for (i = 0; i < pitch_overlap; i++) {
amp[i] = fsaturate(old_weight*s->pitchbuf[s->pitch_offset] + new_weight*amp[i]);
if (++s->pitch_offset >= s->pitch)
s->pitch_offset = 0;
@ -171,6 +168,7 @@ int plc_rx(plc_state_t *s, int16_t amp[], int len)
save_history(s, amp, len);
return len;
}
/*- End of function --------------------------------------------------------*/
int plc_fillin(plc_state_t *s, int16_t amp[], int len)
@ -187,8 +185,7 @@ int plc_fillin(plc_state_t *s, int16_t amp[], int len)
orig_amp = amp;
orig_len = len;
if (s->missing_samples == 0)
{
if (s->missing_samples == 0) {
/* As the gap in real speech starts we need to assess the last known pitch,
and prepare the synthetic data we will use for fill-in */
normalise_history(s);
@ -203,8 +200,7 @@ int plc_fillin(plc_state_t *s, int16_t amp[], int len)
/* The last 1/4 of the cycle is overlapped with the end of the previous cycle */
new_step = 1.0/pitch_overlap;
new_weight = new_step;
for ( ; i < s->pitch; i++)
{
for ( ; i < s->pitch; i++) {
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;
new_weight += new_step;
}
@ -219,8 +215,7 @@ int plc_fillin(plc_state_t *s, int16_t amp[], int len)
old_step = new_step;
new_weight = new_step;
old_weight = 1.0 - new_step;
for (i = 0; i < pitch_overlap; i++)
{
for (i = 0; i < pitch_overlap; i++) {
amp[i] = fsaturate(old_weight*s->history[PLC_HISTORY_LEN - 1 - i] + new_weight*s->pitchbuf[i]);
new_weight += new_step;
old_weight -= old_step;
@ -228,14 +223,11 @@ int plc_fillin(plc_state_t *s, int16_t amp[], int len)
old_weight = 0.0;
}
s->pitch_offset = i;
}
else
{
} else {
gain = 1.0 - s->missing_samples*ATTENUATION_INCREMENT;
i = 0;
}
for ( ; gain > 0.0 && i < len; i++)
{
for ( ; gain > 0.0 && i < len; i++) {
amp[i] = s->pitchbuf[s->pitch_offset]*gain;
gain -= ATTENUATION_INCREMENT;
if (++s->pitch_offset >= s->pitch)
@ -247,6 +239,7 @@ int plc_fillin(plc_state_t *s, int16_t amp[], int len)
save_history(s, amp, len);
return len;
}
/*- End of function --------------------------------------------------------*/
plc_state_t *plc_init(plc_state_t *s)

Loading…
Cancel
Save