void Deemph_32_( Word16 x_hi[], /* (i) : input signal (bit31..16) */ Word16 x_lo[], /* (i) : input signal (bit15..4) */ Word16 y[], /* (o) : output signal (x16) */ Word16 mu, /* (i) Q15 : deemphasis factor */ Word16 L, /* (i) : vector size */ Word16 * mem /* (i/o) : memory (y[-1]) */ ) { Word16 i; Word32 L_tmp; /* L_tmp = hi<<16 + lo<<4 */ L_tmp = (Word32)x_hi[0] << 16; L_tmp = L_tmp + ((Word32)x_lo[0] << 4); L_tmp = L_shl(L_tmp, 4); L_tmp = L_mac(L_tmp, *mem, mu); /* saturation can occur here */ y[0] = round16(L_tmp); for (i = 1; i < L; i++) { L_tmp = (Word32)x_hi[i] << 16; L_tmp = L_tmp + ((Word32)x_lo[i] << 4); L_tmp = L_shl(L_tmp, 4); L_tmp = L_mac(L_tmp, y[i - 1], mu); /* saturation can occur here */ y[i] = round16(L_tmp); } *mem = y[L - 1]; return; }
void Deemph2_( Word16 x[], /* (i/o) : input signal overwritten by the output */ Word16 mu, /* (i) Q15 : deemphasis factor */ Word16 L, /* (i) : vector size */ Word16 * mem /* (i/o) : memory (y[-1]) */ ) { Word16 i; Word32 L_tmp; /* saturation can occur in L_mac() */ L_tmp = L_mult(x[0], 16384); L_tmp = L_mac(L_tmp, *mem, mu); x[0] = round16(L_tmp); for (i = 1; i < L; i++) { L_tmp = L_mult(x[i], 16384); L_tmp = L_mac(L_tmp, x[i - 1], mu); x[i] = round16(L_tmp); } *mem = x[L - 1]; return; }
void Deemph_( Word16 x[], /* (i/o) : input signal overwritten by the output */ Word16 mu, /* (i) Q15 : deemphasis factor */ Word16 L, /* (i) : vector size */ Word16 * mem /* (i/o) : memory (y[-1]) */ ) { Word16 i; Word32 L_tmp; L_tmp = (Word32)x[0] << 16; L_tmp = L_mac(L_tmp, *mem, mu); x[0] = round16(L_tmp); for (i = 1; i < L; i++) { L_tmp = (Word32)x[i] << 16; L_tmp = L_mac(L_tmp, x[i - 1], mu); x[i] = round16(L_tmp); } *mem = x[L - 1]; return; }
void Pred_lt4( Word16 exc[], /* in/out: excitation buffer */ Word16 T0, /* input : integer pitch lag */ Word16 frac, /* input : fraction of lag */ Word16 L_subfr /* input : subframe size */ ) { Word16 i, j, k, *x; Word32 L_sum; x = &exc[-T0]; // frac = -frac; /* frac=0,1,2,3 */ if (frac >= 0) { frac = frac - UP_SAMP; x--; } x = x - L_INTERPOL2 + 1; for (j = 0; j < L_subfr; j++) { L_sum = 0L; for (i = 0, k = UP_SAMP-1+frac; i < 2*L_INTERPOL2; i++, k += UP_SAMP) { L_sum = L_mac(L_sum, x[i], inter4_2[k]); } L_sum = L_shl(L_sum, 1); exc[j] = round16(L_sum); x++; } return; }
void Preemph_( Word16 x[], /* (i/o) : input signal overwritten by the output */ Word16 mu, /* (i) Q15 : preemphasis coefficient */ Word16 lg /* (i) : lenght of filtering */ ) { Word16 i; Word32 L_tmp; for (i = lg - 1; i > 0; i--) { L_tmp = (Word32)x[i] << 16; L_tmp = L_msu(L_tmp, x[i - 1], mu); x[i] = round16(L_tmp); } return; }
Word16 Interpol( /* return result of interpolation */ Word16 * x, /* input vector */ Word16 * fir, /* filter coefficient */ Word16 frac, /* fraction (0..resol) */ Word16 resol, /* resolution */ Word16 nb_coef /* number of coefficients */ ) { Word16 i, k; Word32 L_sum; x = x - nb_coef + 1; L_sum = 0L; for (i = 0, k = resol- 1- frac; i < 2 * nb_coef; i++, k = k + resol) { L_sum = L_mac(L_sum, x[i], fir[k]); } L_sum = L_shl(L_sum, 1); /* saturation can occur here */ return (round16(L_sum)); }
void dct_type_iv_a (Int16 *input, Int16 *output, Int16 dct_length) { Int16 *in_ptr, *in_ptr_low, *in_ptr_high, *next_in_base; Int16 *out_ptr_low, *out_ptr_high, *next_out_base; Int16 *out_buffer, *in_buffer, *buffer_swap; Int16 *outptr[2] = {buffer_a, buffer_b}; Int16 in_val_low, in_val_high; Int16 in_low_even, in_low_odd; Int16 in_high_even, in_high_odd; Int16 out_low_even, out_low_odd; Int16 out_high_even, out_high_odd; Int16 *pair_ptr; Int16 cosine, sine; Int32 sum, acca; Int16 set_span, set_count, set_count_log, pairs_left, sets_left; Int16 k, temp; cos_msin_t **table_ptr_ptr, *cos_msin_ptr; /*++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ /* Do the sum/difference butterflies, the first part of */ /* converting one N-point transform into N/2 two-point */ /* transforms, where N = 1 << DCT_LENGTH_LOG. = 64/128 */ /*++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ if (dct_length == 320) /* Add bias offsets */ DSP_add(input, anal_bias, dct_length); in_buffer = input; set_span = dct_length; set_count = 1; for (set_count_log = 0; set_count_log < DCT_LENGTH_LOG - 1; set_count_log++) { out_buffer = outptr[0]; outptr[0] = outptr[1]; outptr[1] = out_buffer; /*===========================================================*/ /* Initialization for the loop over sets at the current size */ /*===========================================================*/ in_ptr = in_buffer; next_out_base = out_buffer; /*=====================================*/ /* Loop over all the sets of this size */ /*=====================================*/ for (sets_left = set_count; sets_left > 0; sets_left--) { /*||||||||||||||||||||||||||||||||||||||||||||*/ /* Set up output pointers for the current set */ /*||||||||||||||||||||||||||||||||||||||||||||*/ out_ptr_low = next_out_base; next_out_base += set_span; out_ptr_high = next_out_base; /*||||||||||||||||||||||||||||||||||||||||||||||||||*/ /* Loop over all the butterflies in the current set */ /*||||||||||||||||||||||||||||||||||||||||||||||||||*/ do { in_val_low = *in_ptr++; in_val_high = *in_ptr++; acca = (Int32)in_val_low + (Int32)in_val_high; *out_ptr_low++ = (Int16)(acca >> 1); acca = (Int32)in_val_low - (Int32)in_val_high; *--out_ptr_high = (Int16)(acca >> 1); } while (out_ptr_low < out_ptr_high); } /* End of loop over sets of the current size */ /*============================================================*/ /* Decide which buffers to use as input and output next time. */ /* Except for the first time (when the input buffer is the */ /* subroutine input) we just alternate the local buffers. */ /*============================================================*/ in_buffer = out_buffer; set_span >>= 1; set_count <<= 1; } /* End of loop over set sizes */ /*++++++++++++++++++++++++++++++++*/ /* Do N/2 two-point transforms, */ /* where N = 1 << DCT_LENGTH_LOG */ /*++++++++++++++++++++++++++++++++*/ pair_ptr = in_buffer; buffer_swap = buffer_c; for (pairs_left = 1<<(DCT_LENGTH_LOG-1); pairs_left > 0; pairs_left--) { for (k = 0; k < CORE_SIZE; k++) *buffer_swap++ = DSP_mac(pair_ptr, dct_core_a[k], CORE_SIZE); /* for (k = 0; k < CORE_SIZE; k++) { sum=0L; for (i = 0; i < CORE_SIZE; i++) sum = L_mac(sum, pair_ptr[i], dct_core_a[k][i]); *buffer_swap++ = round16(sum); } */ /* address arithmetic */ pair_ptr += CORE_SIZE; } DSP_memcpy(in_buffer, buffer_c, dct_length>>1); // for (i = 0; i < dct_length; i++) // in_buffer[i] = buffer_c[i]; table_ptr_ptr = a_cos_msin_table; /*++++++++++++++++++++++++++++++*/ /* Perform rotation butterflies */ /*++++++++++++++++++++++++++++++*/ out_buffer = outptr[0]; set_span = 10; for (set_count_log = DCT_LENGTH_LOG -2; set_count_log >= 0; set_count_log--) { /*===========================================================*/ /* Initialization for the loop over sets at the current size */ /*===========================================================*/ /* set_span = 1 << (DCT_LENGTH_LOG - set_count_log); */ set_span <<= 1; set_count = 1 << set_count_log; next_in_base = in_buffer; next_out_base = (set_count_log) ? out_buffer : output; /*=====================================*/ /* Loop over all the sets of this size */ /*=====================================*/ for (sets_left = set_count; sets_left > 0; sets_left--) { /*|||||||||||||||||||||||||||||||||||||||||*/ /* Set up the pointers for the current set */ /*|||||||||||||||||||||||||||||||||||||||||*/ in_ptr_low = next_in_base; temp = set_span >> 1; /* address arithmetic */ in_ptr_high = in_ptr_low + temp; next_in_base += set_span; out_ptr_low = next_out_base; next_out_base += set_span; out_ptr_high = next_out_base; cos_msin_ptr = *table_ptr_ptr; /*||||||||||||||||||||||||||||||||||||||||||||||||||||||*/ /* Loop over all the butterfly pairs in the current set */ /*||||||||||||||||||||||||||||||||||||||||||||||||||||||*/ do { /* address arithmetic */ in_low_even = *in_ptr_low++; in_low_odd = *in_ptr_low++; in_high_even = *in_ptr_high++; in_high_odd = *in_ptr_high++; cosine = (*cos_msin_ptr).cosine; sine = (*cos_msin_ptr++).minus_sine; sum = L_mult(cosine, in_low_even); sum = L_msu(sum, sine, in_high_even); out_low_even = round16(sum); sum = L_mult(sine, in_low_even); sum = L_mac(sum, cosine, in_high_even); out_high_even = round16(sum); cosine = (*cos_msin_ptr).cosine; sine = (*cos_msin_ptr++).minus_sine; sum = L_mult(cosine, in_low_odd); sum = L_mac(sum, sine, in_high_odd); out_low_odd = round16(sum); sum = L_mult(sine, in_low_odd); sum = L_msu(sum, cosine, in_high_odd); out_high_odd = round16(sum); *out_ptr_low++ = out_low_even; *--out_ptr_high = out_high_even; *out_ptr_low++ = out_low_odd; *--out_ptr_high = out_high_odd; } while (out_ptr_low < out_ptr_high); } /* End of loop over sets of the current size */ /*=============================================*/ /* Swap input and output buffers for next time */ /*=============================================*/ buffer_swap = in_buffer; in_buffer = out_buffer; out_buffer = buffer_swap; table_ptr_ptr++; } }
void rmlt_coefs_to_samples(Int16 *coefs, Int16 *out_samples, Int16 dct_length, Int16 mag_shift, Uint16 chn) { Int16 i; Int16 *new_ptr, *old_ptr; Int16 *win_new, *win_old; Int16 *out_ptr; Int16 half_dct_size; Int32 sum; half_dct_size = dct_length >> 1; /* Perform a Type IV (inverse) DCT on the coefficients */ dct_type_iv_s(coefs, windowed_data, dct_length); if(mag_shift != 0) for(i = dct_length; i--; ) windowed_data[i] = shr(windowed_data[i], mag_shift); /* Get the first half of the windowed samples */ out_ptr = out_samples; if (dct_length != MAX_DCT_LENGTH) win_new = rmlt_to_samples_window; else win_new = max_rmlt_to_samples_window; win_old = win_new + dct_length; old_ptr = &old_samples[chn * dct_length]; new_ptr = windowed_data + half_dct_size; for (i = half_dct_size; i--; ) { sum = L_mult(*win_new++, *--new_ptr); sum = L_mac(sum, *--win_old, *old_ptr++); *out_ptr++ = round16(L_shl(sum, 2)); } /* Get the second half of the windowed samples */ for (i = half_dct_size; i--; ) { sum = L_mult(*win_new++, *new_ptr++); sum = L_msu(sum, *--win_old, *--old_ptr); *out_ptr++ = round16(L_shl(sum, 2)); } /* Save the second half of the new samples for */ /* next time, when they will be the old samples. */ /* pointer arithmetic */ DSP_memcpy(&old_samples[chn*dct_length], &windowed_data[half_dct_size], half_dct_size); // // new_ptr = windowed_data + (DCT_LENGTH>>1); // old_ptr = old_samples; // for (i = 0; i < (DCT_LENGTH>>1); i++) // *old_ptr++ = *new_ptr++; }
Word16 samples_to_rmlt_coefs(Word16 *new_samples,Word16 *old_samples,Word16 *coefs,Word16 dct_length) { Word16 index, vals_left,mag_shift,n; Word16 windowed_data[MAX_DCT_LENGTH]; Word16 *new_ptr, *old_ptr, *sam_low, *sam_high; Word16 *win_low, *win_high; Word16 *dst_ptr; Word16 neg_win_low; Word16 samp_high; Word16 half_dct_size; Word32 acca; Word32 accb; Word16 temp; Word16 temp1; Word16 temp2; Word16 temp5; half_dct_size = shr(dct_length,1); /*++++++++++++++++++++++++++++++++++++++++++++*/ /* Get the first half of the windowed samples */ /*++++++++++++++++++++++++++++++++++++++++++++*/ dst_ptr = windowed_data; move16(); /* address arithmetic */ test(); if (dct_length==DCT_LENGTH) { win_high = samples_to_rmlt_window + half_dct_size; } else { win_high = max_samples_to_rmlt_window + half_dct_size; } win_low = win_high; move16(); /* address arithmetic */ sam_high = old_samples + half_dct_size; sam_low = sam_high; move16(); for (vals_left = half_dct_size;vals_left > 0;vals_left--) { acca = 0L; move32(); acca = L_mac(acca,*--win_low, *--sam_low); acca = L_mac(acca,*win_high++, *sam_high++); temp = round16(acca); *dst_ptr++ = temp; move16(); } /*+++++++++++++++++++++++++++++++++++++++++++++*/ /* Get the second half of the windowed samples */ /*+++++++++++++++++++++++++++++++++++++++++++++*/ sam_low = new_samples; move16(); /* address arithmetic */ sam_high = new_samples + dct_length; for (vals_left = half_dct_size; vals_left > 0; vals_left--) { acca = 0L; move32(); acca = L_mac(acca,*--win_high, *sam_low++); neg_win_low = negate(*win_low++); samp_high = *--sam_high; acca = L_mac(acca, neg_win_low, samp_high); temp = round16(acca); *dst_ptr++=temp; move16(); } /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ /* Save the new samples for next time, when they will be the old samples */ /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ new_ptr = new_samples; move16(); old_ptr = old_samples; move16(); for (vals_left = dct_length;vals_left > 0;vals_left--) { *old_ptr++ = *new_ptr++; move16(); } /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ /* Calculate how many bits to shift up the input to the DCT. */ /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ temp1=0; move16(); for(index=0;index<dct_length;index++) { temp2 = abs_s(windowed_data[index]); temp = sub(temp2,temp1); test(); if(temp > 0) { move16(); temp1 = temp2; } } mag_shift=0; move16(); temp = sub(temp1,14000); test(); if (temp >= 0) { mag_shift = 0; move16(); } else { temp = sub(temp1,438); test(); if(temp < 0) temp = add(temp1,1); else { temp = temp1; move16(); } accb = L_mult(temp,9587); acca = L_shr(accb,20); temp5 = extract_l(acca); temp = norm_s(temp5); test(); if (temp == 0) { mag_shift = 9; move16(); } else mag_shift = sub(temp,6); } acca = 0L; move32(); for(index=0; index<dct_length; index++) { temp = abs_s( windowed_data[index]); acca = L_add(acca,temp); } acca = L_shr(acca,7); test(); if (temp1 < acca) { mag_shift = sub(mag_shift,1); } test(); if (mag_shift > 0) { for(index=0;index<dct_length;index++) { windowed_data[index] = shl(windowed_data[index],mag_shift); } } else { test(); if (mag_shift < 0) { n = negate(mag_shift); for(index=0;index<dct_length;index++) { windowed_data[index] = shr(windowed_data[index],n); move16(); } } } /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ /* Perform a Type IV DCT on the windowed data to get the coefficients */ /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ dct_type_iv_a(windowed_data, coefs, dct_length); return(mag_shift); }