Skip to content
......@@ -47,47 +47,6 @@
* Estimation of pitch-synchronous (voiced sounds) or half-frame energy
*----------------------------------------------------------------------------------*/
#ifndef IVAS_FLOAT_FIXED
void fer_energy(
const int16_t L_frame, /* i : frame length */
const int16_t clas, /* i : frame classification */
const float *synth, /* i : synthesized speech at Fs = 12k8 Hz */
const float pitch, /* i : pitch period */
float *enr, /* o : pitch-synchronous or half_frame energy */
const int16_t offset /* i : speech pointer offset (0 or L_frame) */
)
{
int16_t len;
const float *pt_synth;
if ( clas == VOICED_CLAS || clas == ONSET || clas == SIN_ONSET ) /* Voiced or Onset current frame */
{
len = (int16_t) ( pitch + 0.5f ); /* pitch value */
pt_synth = synth;
if ( offset != 0 )
{
pt_synth = synth + L_frame - len;
}
emaximum( pt_synth, len, enr ); /* pitch synchronous E */
}
else
{
pt_synth = synth;
if ( offset != 0 )
{
pt_synth = synth + L_frame / 2;
}
*enr = dotp( pt_synth, pt_synth, L_frame / 2 );
*enr /= (float) ( L_frame / 2 );
}
return;
}
#endif
#ifdef IVAS_FLOAT_FIXED
void fer_energy_fx(
const Word16 L_frame, /* i : frame length */
const Word16 clas, /* i : frame classification */
......@@ -143,50 +102,6 @@ void fer_energy_fx(
}
return;
}
#endif // IVAS_FLOAT_FIXED
#ifndef IVAS_FLOAT_FIXED
/*------------------------------------------------------------------------*
* frame_energy()
*
* Compute pitch-synchronous energy at the frame end
*------------------------------------------------------------------------*/
float frame_energy(
const int16_t L_frame, /* i : length of the frame */
const float *pitch, /* i : pitch values for each subframe */
const float *speech, /* i : pointer to speech signal for E computation */
const float lp_speech, /* i : long-term active speech energy average */
float *frame_ener /* o : pitch-synchronous energy at frame end */
)
{
float enern;
const float *pt1;
int16_t len;
float dotProd;
len = (int16_t) ( 0.5f * ( pitch[2] + pitch[3] ) + 0.5f );
if ( len < L_SUBFR )
{
len *= 2;
}
pt1 = speech + L_frame - len;
dotProd = dotp( pt1, pt1, len );
if ( 0 == dotProd )
{
*frame_ener = MIN_LOG_VAL_60dB;
}
else
{
*frame_ener = 10.0f * (float) log10( dotProd / (float) len );
}
enern = *frame_ener - lp_speech;
return enern;
}
#endif
/*----------------------------------------------------------------------------------*
* frame_ener()
......
......@@ -46,34 +46,6 @@
*
*----------------------------------------------------------------------------------*/
#ifndef IVAS_FLOAT_FIXED
/*! r: codebook gain (adaptive or fixed) */
float get_gain_flt(
const float x[], /* i : target signal */
const float y[], /* i : filtered codebook excitation */
const int16_t n, /* i : segment length */
float *en_y /* o : energy of y (sum of y[]^2, optional) */
)
{
float corr = 0.0f, ener = 1e-6f;
int16_t i;
for ( i = 0; i < n; i++ )
{
corr += x[i] * y[i];
ener += y[i] * y[i];
}
if ( en_y )
{
*en_y = ener;
}
return ( corr / ener );
}
#endif
#ifdef IVAS_FLOAT_FIXED
Word32 get_gain( /* output: codebook gain (adaptive or fixed) Q16 */
const Word16 x[], /* input : target signal Qx */
const Word16 y[], /* input : filtered codebook excitation Qx */
......@@ -178,4 +150,3 @@ Word32 get_gain2( /* output: codebook gain (adaptive or fixed)
return Lgain;
}
#endif
/******************************************************************************************************
(C) 2022-2024 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
contributors to this repository. All Rights Reserved.
This software is protected by copyright law and by international treaties.
The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
contributors to this repository retain full ownership rights in their respective contributions in
the software. This notice grants no license of any kind, including but not limited to patent
license, nor is any license granted by implication, estoppel or otherwise.
Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
contributions.
This software is provided "AS IS", without any express or implied warranties. The software is in the
development stage. It is intended exclusively for experts who have experience with such software and
solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
and fitness for a particular purpose are hereby disclaimed and excluded.
Any dispute, controversy or claim arising under or in relation to providing this software shall be
submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
the United Nations Convention on Contracts on the International Sales of Goods.
*******************************************************************************************************/
/*====================================================================================
EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0
====================================================================================*/
#include <stdint.h>
#include "options.h"
#include <math.h>
#include "cnst.h"
#include "rom_com.h"
#include "prot.h"
#include "ivas_prot.h"
#include "wmc_auto.h"
#ifndef IVAS_FLOAT_FIXED
/*-------------------------------------------------------------------*
* Local function prototypes
*-------------------------------------------------------------------*/
static float Find_bit_frac( const int16_t nb_band, const int16_t remaining_bits );
static void reajust_bits( float *bits_per_bands, const int16_t st_band, const int16_t end_band, const int16_t sum_bit_in, const int16_t bit_bdgt_in );
#define Q15_0_33 10922 /* 0.33 */
#define Q18_0_1 26214 /* 0.1 */
#define Q18_0_50 131072 /* 0.50 */
#define Q18_0_75 196608 /* 0.75 */
#define Q18_0_76 199229 /* 76/100 */
#define Q18_1_0 262144 /* 1.0 */
#define Q18_1_2 314573 /* 1.2 */
#define Q18_112 29360128 /* 112 */
#define Q18_DSR_NB_PULSE 1179648 /* 4.5 */
#define Q18_1_5xDSR_NB_PULSE 1769472 /* 1.5x4.5 */
#define Q18_2_0xDSR_NB_PULSE ( Q18_DSR_NB_PULSE << 1 ) /* 2.0x4.5 */
#define Q31_0_00125 2684355 /* 0.125/100 */
#define Q31_0_0125 26843546 /* 0.0125 */
#define Q31_0_015 32212255 /* 0.0125 */
#define Q31_0_02 42949673 /* 0.02 */
#define Q31_0_17 365072220 /* 0.17 */
#define Q31_0_23 493921239 /* 0.23 */
static Word16 Find_norm_inv( const Word32 ToDivide, Word16 *e_div );
static Word16 Find_bit_alloc_IVAS_int( const Word32 core_brate, const Word16 GSC_IVAS_mode, const Word16 Diff_len, const Word16 nb_tot_bands, const Word16 L_frame, Word16 *bit, Word16 *max_ener_band, float *ener_vec, float *bits_per_bands );
static Word16 maximum_fx( const Word16 *vec_fx, const Word16 lvec_fx, Word16 *max_fx );
/*-------------------------------------------------------------------*
* bands_and_bit_alloc()
*
* AC mode (GSC) bands and bits allocation
*-------------------------------------------------------------------*/
void bands_and_bit_alloc(
const int16_t cor_strong_limit, /* i : HF correlation */
const int16_t noise_lev, /* i : dwn scaling factor */
const int32_t core_brate, /* i : core bitrate */
const int16_t Diff_len, /* i : Lenght of the difference signal (before pure spectral)*/
const int16_t bits_used, /* i : Number of bit used before frequency Q */
int16_t *bit, /* i/o: Number of bit allowed for frequency quantization */
float *Ener_per_bd_iQ, /* i/o: Quantized energy vector */
int16_t *max_ener_band, /* o : Sorted order */
int16_t *bits_per_bands_s, /* i/o: Number of bit allowed per allowed subband (Q3) */
int16_t *nb_subbands, /* o : Number of subband allowed */
const float *exc_diff, /* i : Difference signal to quantize (encoder side only) */
float *concat_in, /* o : Concatened PVQ's input vector (encoder side only) */
int16_t *pvq_len, /* o : Number of bin covered with the PVQ */
const int16_t coder_type, /* i : coding type */
const int16_t bwidth, /* i : input signal bandwidth */
const int16_t GSC_noisy_speech, /* i : GSC noisy speech flag */
const int16_t L_frame, /* i : frame length */
const int16_t element_mode, /* i : element mode */
const int16_t GSC_IVAS_mode /* i : GSC IVAS mode */
)
{
int16_t bandoffset, i, j, nb_bands_max, bit_new_bands, bit_tmp, st_band, nb_bands;
float bit_fracf, etmp;
float sum_bit;
float ener_vec[MBANDS_GN_BITALLOC16k];
int16_t nb_tot_bands;
int16_t bit_index, bit_index_mem, imax;
int16_t pos, band;
float SWB_bit_budget;
float bits_per_bands[MBANDS_GN_BITALLOC16k];
float fzero_val;
/* initializations */
nb_tot_bands = 16;
set_f( bits_per_bands, 0.0f, MBANDS_GN_BITALLOC16k );
if ( L_frame == L_FRAME16k )
{
nb_tot_bands = MBANDS_GN_BITALLOC16k;
}
/* To adapt current energy band to PVQ freq band for sorting*/
ener_vec[0] = Ener_per_bd_iQ[0] + Ener_per_bd_iQ[1];
mvr2r( Ener_per_bd_iQ + 1, ener_vec, 15 );
ener_vec[15] = ener_vec[14];
if ( L_frame == L_FRAME16k )
{
ener_vec[16] = Ener_per_bd_iQ[16];
ener_vec[17] = ( Ener_per_bd_iQ[16] + Ener_per_bd_iQ[17] ) * 0.5f;
ener_vec[18] = Ener_per_bd_iQ[17];
ener_vec[19] = Ener_per_bd_iQ[17] * 0.8f;
}
for ( i = 0; i < nb_tot_bands; i++ )
{
ener_vec[i] = (float) ( (int16_t) ( ener_vec[i] * 4096.f + 0.5f ) );
}
/*------------------------------------------------------------------------
* Determination of the number of bits available to the frequency domain
* Allocation of a maximum number of band to be encoded
*-----------------------------------------------------------------------*/
nb_bands_max = nb_tot_bands;
bit_new_bands = 5;
if ( core_brate > ACELP_16k40 && L_frame == L_FRAME16k )
{
bit_new_bands = 7;
}
i = 0;
while ( i < SIZE_BRATE_INTERMED_TBL )
{
if ( core_brate <= brate_intermed_tbl[i] )
{
break;
}
if ( brate_intermed_tbl[i] == ACELP_24k40 )
{
break;
}
i++;
}
if ( element_mode > EVS_MONO && coder_type == AUDIO &&
core_brate <= STEREO_GSC_BIT_RATE_ALLOC && brate_intermed_tbl[i] == ACELP_9k60 ) /* Bit allocation should be mapped to 8 kb/s instead of 9.6 kb/s in this case */
{
i--;
}
bit_index = BRATE2IDX( brate_intermed_tbl[i] ) * 17;
bit_index_mem = bit_index;
if ( ( coder_type == AUDIO || coder_type == INACTIVE ) && bwidth == NB )
{
if ( core_brate >= ACELP_9k60 )
{
*bit = (int16_t) ( core_brate * ( 1.0f / FRAMES_PER_SEC ) + 0.5f ) - bits_used - 25;
}
else
{
*bit = (int16_t) ( core_brate * ( 1.0f / FRAMES_PER_SEC ) + 0.5f ) - bits_used - 21;
}
nb_tot_bands = 10;
}
else
{
*bit = (int16_t) ( core_brate * ( 1.0f / FRAMES_PER_SEC ) + 0.5f ) - bits_used - GSC_freq_bits[bit_index];
}
if ( L_frame == L_FRAME16k )
{
*bit -= 8;
}
if ( coder_type == INACTIVE && core_brate <= GSC_LRES_GAINQ_LIMIT ) /* can happen only for 2nd channel inactive */
{
*bit += GSC_LRES_NB_NITS;
}
if ( *bit > 0 )
{
if ( GSC_IVAS_mode > 0 )
{
nb_tot_bands = Find_bit_alloc_IVAS_int( core_brate, GSC_IVAS_mode, Diff_len, nb_tot_bands, L_frame, bit, max_ener_band, ener_vec, bits_per_bands );
nb_bands = nb_tot_bands;
}
else if ( GSC_noisy_speech )
{
SWB_bit_budget = *bit;
nb_bands = 5;
fzero_val = 0.0f;
if ( element_mode > EVS_MONO )
{
fzero_val = MIN16B_FLT;
}
if ( coder_type == UNVOICED && element_mode > EVS_MONO )
{
nb_bands = 3;
if ( SWB_bit_budget > 20 )
{
nb_bands = 5;
}
}
else if ( bwidth < SWB )
{
nb_bands = 7;
}
st_band = nb_bands;
set_f( bits_per_bands, 0, MBANDS_GN );
bit_fracf = Find_bit_frac( nb_bands, (int16_t) SWB_bit_budget ); /* Supplementary bits distributed only on first bands */
nb_tot_bands = nb_bands_max - 6;
if ( nb_tot_bands > 16 )
{
nb_tot_bands = 16;
}
for ( j = 0; j < 2; j++ )
{
i = j;
max_ener_band[j] = i;
ener_vec[i] = fzero_val;
}
if ( bwidth < SWB )
{
if ( coder_type == UNVOICED && element_mode > EVS_MONO )
{
nb_tot_bands = 5;
}
for ( ; j < nb_bands; j++ )
{
i = maximum( ener_vec, nb_tot_bands, &etmp );
max_ener_band[j] = i;
ener_vec[i] = fzero_val;
}
}
else
{
for ( ; j < nb_bands; j++ )
{
i = maximum( ener_vec, nb_tot_bands, &etmp );
max_ener_band[j] = i;
ener_vec[i] = fzero_val;
}
}
set_f( bits_per_bands, bit_fracf, nb_bands );
}
else
{
bit_index++;
bit_tmp = *bit - GSC_freq_bits[bit_index];
bit_index++;
nb_bands_max += GSC_freq_bits[bit_index];
bit_index++;
*pvq_len = 112;
st_band = 7;
if ( L_frame == L_FRAME16k && core_brate > ACELP_16k40 )
{
*pvq_len = 160;
st_band = 10;
nb_bands = *pvq_len / 16;
bit_tmp -= 35;
bit_new_bands = 5;
}
if ( core_brate <= ACELP_9k60 )
{
*pvq_len = 80;
st_band = 5;
if ( Diff_len == 0 )
{
nb_bands_max += 2;
bit_tmp -= 13;
}
}
else if ( Diff_len == 0 )
{
nb_bands_max += 2;
bit_tmp -= 17;
}
nb_bands = *pvq_len / 16;
nb_bands_max = min( nb_bands_max, MBANDS_GN_BITALLOC16k );
/*------------------------------------------------------------------------
* Adjustement of the maximum number of bands in function of the
* dynamics of the spectrum (more or less speech like)
*-----------------------------------------------------------------------*/
if ( coder_type == INACTIVE || noise_lev >= NOISE_LEVEL_SP3 )
{
/* Probably classification error -> concentrate bits on LF */
if ( L_frame == L_FRAME16k && core_brate >= ACELP_24k40 )
{
nb_bands_max = nb_tot_bands - 2;
}
else if ( core_brate >= ACELP_16k40 )
{
nb_bands_max = nb_bands + 2;
}
else if ( core_brate >= ACELP_8k00 )
{
nb_bands_max = nb_bands + 1;
}
else
{
nb_bands_max = nb_bands;
}
}
else if ( noise_lev >= NOISE_LEVEL_SP2 || ( core_brate <= ACELP_13k20 && core_brate >= ACELP_9k60 && cor_strong_limit == 0 ) ) /* Very low dynamic, tend to speech, do not try to code HF at all */
{
nb_bands_max -= 2;
}
else if ( noise_lev >= NOISE_LEVEL_SP1 ) /* Very low dynamic, tend to speech, code less HF */
{
nb_bands_max -= 1;
}
if ( L_frame == L_FRAME16k )
{
if ( core_brate < ACELP_24k40 )
{
nb_bands_max -= 4;
}
else if ( core_brate < ACELP_32k )
{
if ( Diff_len > 0 || noise_lev >= NOISE_LEVEL_SP2 )
{
nb_bands_max -= 2;
bit_new_bands *= 2;
}
}
else if ( core_brate >= ACELP_32k )
{
bit_new_bands *= 2;
}
}
if ( bwidth == NB && nb_bands_max > 10 )
{
nb_bands_max = 10;
}
/*------------------------------------------------------------------------
* Find extra number of band to code according to bitrate availables
*-----------------------------------------------------------------------*/
while ( bit_tmp >= bit_new_bands && nb_bands <= nb_bands_max - 1 )
{
bit_tmp -= bit_new_bands;
nb_bands++;
}
/*------------------------------------------------------------------------
* Fractional bits to distribute on the first x bands
*-----------------------------------------------------------------------*/
if ( L_frame == L_FRAME16k && core_brate > ACELP_32k )
{
bit_fracf = 0;
}
else
{
bit_fracf = Find_bit_frac( st_band, bit_tmp ); /* Supplementary bits distributed only on first bands */
}
/*------------------------------------------------------------------------
* Complete the bit allocation per frequency band
*-----------------------------------------------------------------------*/
imax = 5;
if ( core_brate > ACELP_9k60 )
{
imax = 7;
}
for ( i = 0; i < imax; i++ )
{
bits_per_bands[i] = GSC_freq_bits[bit_index] + bit_fracf;
bit_index++;
}
if ( L_frame == L_FRAME16k && core_brate > ACELP_16k40 )
{
bit_index = 0;
i = imax - 1;
bits_per_bands[i] += Compl_GSC_freq_bits[bit_index];
i++;
bit_index++;
for ( ; i < 10; i++ )
{
bits_per_bands[i] += Compl_GSC_freq_bits[bit_index] + bit_fracf;
bit_index++;
}
}
if ( Diff_len == 0 )
{
bit_index = bit_index_mem + 10;
for ( i = 0; i < 7; i++ )
{
bits_per_bands[i] += GSC_freq_bits[bit_index];
bit_index++;
}
}
if ( bit_fracf < 0 )
{
for ( j = 0; j < nb_tot_bands; j++ )
{
bits_per_bands[j] = max( bits_per_bands[j], 0 );
}
}
/*--------------------------------------------------------------------------
* Complete the bit allocation per frequency band for 16kHz high brate mode
*--------------------------------------------------------------------------*/
if ( L_frame == L_FRAME16k && core_brate > ACELP_32k )
{
for ( j = st_band; j < nb_bands; j++ )
{
bits_per_bands[j] = bit_new_bands;
}
bit_fracf = ( 1.0f / nb_bands ) * ( bit_tmp );
etmp = 2.0f * bit_fracf / ( nb_bands + 1 );
bit_fracf = etmp;
for ( j = nb_bands - 1; j >= 0; j-- )
{
bits_per_bands[j] += etmp;
etmp += bit_fracf;
}
}
else
{
for ( j = st_band; j < nb_bands; j++ )
{
bits_per_bands[j] = bit_new_bands;
}
}
/*--------------------------------------------------------------------------
* Compute a maximum band (band offset) for the search on maximal energy
* This is function of the spectral dynamic and the bitrate
*--------------------------------------------------------------------------*/
bandoffset = nb_tot_bands - ( nb_bands + 2 );
if ( noise_lev <= NOISE_LEVEL_SP1a )
{
bandoffset--;
}
else if ( ( core_brate <= ACELP_13k20 && ( coder_type == INACTIVE || noise_lev >= NOISE_LEVEL_SP3 ) ) || ( core_brate <= ACELP_13k20 && core_brate >= ACELP_9k60 && cor_strong_limit == 0 ) )
{
bandoffset++;
}
if ( bandoffset < 0 )
{
bandoffset = 0;
}
/*--------------------------------------------------------------------------
* Initiazed sorted vector
* For the first x bands to be included in th final sorted vector
* Sort the remaining bands in decrease energy order
*--------------------------------------------------------------------------*/
for ( j = 0; j < nb_tot_bands; j++ )
{
max_ener_band[j] = -10;
}
for ( j = 0; j < st_band; j++ )
{
max_ener_band[j] = j;
ener_vec[j] = -10;
}
pos = st_band;
for ( ; j < nb_bands; j++ )
{
i = maximum( ener_vec, nb_tot_bands - bandoffset, &etmp );
if ( i > pos )
{
pos = i;
}
max_ener_band[j] = i;
ener_vec[i] = -10;
}
/* re-allocate bits to the frames such that the highest band with allocated bits is higher than the threshold */
if ( nb_tot_bands - bandoffset > nb_bands && ( pos > 7 && core_brate == ACELP_8k00 ) && bwidth == WB )
{
band = nb_tot_bands - bandoffset - nb_bands;
for ( j = 0; j < band; j++ )
{
i = maximum( ener_vec, nb_tot_bands - bandoffset, &etmp );
max_ener_band[nb_bands + j] = i;
ener_vec[i] = -10;
bits_per_bands[nb_bands + j] = 5;
}
nb_bands += band;
bit_tmp = 5 * band;
if ( band <= 2 )
{
for ( j = st_band - 1; j < nb_bands; j++ )
{
bits_per_bands[j] += 1;
}
bit_tmp += nb_bands - st_band + 1;
}
i = 0;
j = 0;
while ( bit_tmp > 0 )
{
bits_per_bands[j] -= 1;
if ( j == st_band - 1 - i )
{
j = 0;
}
else
{
++j;
}
if ( j == 0 && i < st_band - 1 )
{
i++;
}
bit_tmp -= 1;
}
}
/*--------------------------------------------------------------------------
* Bit sum verification for GSC inactive at very high rate
* The maximum number of bits per band of length 16 is 112
* Redistribute the overage bits if needed
*--------------------------------------------------------------------------*/
sum_bit = 0;
j = 0;
for ( i = 0; i < nb_bands; i++ )
{
if ( bits_per_bands[i] > 112 )
{
sum_bit += bits_per_bands[i] - 112;
bits_per_bands[i] = 112;
j = i + 1;
}
/* safety check for overage bit reallocation */
else if ( bits_per_bands[i] + sum_bit / 3 > 112 )
{
j = i + 1;
}
}
if ( sum_bit != 0 )
{
sum_bit /= ( nb_bands - j );
for ( i = j; i < nb_bands; i++ )
{
bits_per_bands[i] += sum_bit;
}
}
}
/*--------------------------------------------------------------------------
* second step of bit sum verification, normally sum_bit == *bit
*--------------------------------------------------------------------------*/
sum_bit = 0.00f;
for ( i = 0; i < nb_bands; i++ )
{
bits_per_bands[i] = (float) floor( bits_per_bands[i] );
sum_bit += bits_per_bands[i];
}
if ( GSC_IVAS_mode != 0 && sum_bit < *bit ) /* If we need to add bits, we are doing it on the LF */
{
reajust_bits( bits_per_bands, 0, nb_bands, (int16_t) sum_bit, *bit );
}
else
{
reajust_bits( bits_per_bands, nb_bands - 1, 0, (int16_t) sum_bit, *bit );
}
/*--------------------------------------------------------------------------
* Recompute the real number/length of frequency bands to encode
*--------------------------------------------------------------------------*/
*nb_subbands = nb_bands;
*pvq_len = *nb_subbands * 16;
/*--------------------------------------------------------------------------
* Concatenate bands (encoder only)
*--------------------------------------------------------------------------*/
if ( exc_diff != NULL )
{
for ( j = 0; j < nb_bands; j++ )
{
mvr2r( exc_diff + max_ener_band[j] * 16, concat_in + j * 16, 16 );
}
}
set_s( bits_per_bands_s, 0, nb_tot_bands );
for ( j = 0; j < nb_bands; j++ )
{
bits_per_bands_s[j] = ( (int16_t) bits_per_bands[j] ) << 3;
}
}
else /* *bit == 0 */
{
set_s( bits_per_bands_s, 0, nb_tot_bands );
*nb_subbands = 0;
*pvq_len = 0;
}
return;
}
/*-------------------------------------------------------------------*
* reajust_bits()
*
*
*-------------------------------------------------------------------*/
static void reajust_bits(
float *bits_per_bands,
const int16_t st_band,
const int16_t end_band,
const int16_t sum_bit_in,
const int16_t bit_bdgt_in )
{
int16_t i, amount_to_add, incr;
int16_t bit_bdgt, sum_bit;
incr = 1;
if ( end_band < st_band )
{
incr = -1;
}
if ( bit_bdgt_in < sum_bit_in )
{
amount_to_add = -1;
bit_bdgt = sum_bit_in;
sum_bit = bit_bdgt_in;
}
else
{
bit_bdgt = bit_bdgt_in;
sum_bit = sum_bit_in;
amount_to_add = 1;
}
i = st_band;
while ( bit_bdgt > sum_bit )
{
if ( amount_to_add > 0 || ( amount_to_add < 0 && bits_per_bands[i] > 1 ) )
{
bits_per_bands[i] += amount_to_add;
sum_bit += (int16_t) abs( amount_to_add );
}
i += incr;
if ( i == end_band )
{
i = st_band;
}
}
return;
}
/*-------------------------------------------------------------------*
* Find_bit_frac()
*
* Computes the fraction of the remaining bit budget to allocate to the bands
*-------------------------------------------------------------------*/
static float Find_bit_frac(
const int16_t nb_band,
const int16_t remaining_bits )
{
float var_out;
int16_t inv_bandQ15;
int32_t L_num;
inv_bandQ15 = 6553;
if ( nb_band == 7 )
{
inv_bandQ15 = 4681;
}
else if ( nb_band == 3 )
{
inv_bandQ15 = 10922;
}
else if ( nb_band == 4 )
{
inv_bandQ15 = 8192;
}
else if ( nb_band == 5 )
{
inv_bandQ15 = 6536;
}
else if ( nb_band == 10 )
{
inv_bandQ15 = 3277;
}
else
{
inv_bandQ15 = (int16_t) ( ( 1.0f / nb_band ) * 32678 + 0.5f );
}
L_num = inv_bandQ15 * remaining_bits;
L_num *= 8;
var_out = L_num / 262144.0f;
return ( var_out );
}
static Word16 Find_bit_alloc_IVAS_int( /* o : Number of band to encode */
const Word32 core_brate, /* i : core bit rate */
const Word16 GSC_IVAS_mode, /* i : GSC IVAS mode */
const Word16 Diff_len, /* i : Length of the difference signal (before pure spectral)*/
const Word16 nb_tot_bands_in, /* i : total number of band */
const Word16 L_frame, /* i : frame length */
Word16 *bit, /* i/o: Number of bit allowed for frequency quantization */
Word16 *max_ener_band, /* i/o: Energy based sorted order */
float *ener_vec_io, /* i/o: Energy per band order */
float *bits_per_bands_o /* o : Number of bit allowed per allowed sub-band Q3 */
)
{
Word32 mp, mb, nb_bands_adj, bit_adj;
Word16 nb_pulse_per_band[MBANDS_GN_BITALLOC16k];
Word32 SWB_bit_budget; // Q0 -> Q18
Word16 i, j, nb_bands_max, st_band, nb_tot_bands_loc, etmp;
Word32 sum_bit /*Q18*/, bit_fracf /*Q18*/;
Word16 d_tmp, e_div, tmp16, ener_vec[MBANDS_GN_BITALLOC16k];
Word32 Ltmp, etmp_32fx, bits_per_bands[MBANDS_GN_BITALLOC16k];
SWB_bit_budget = *bit; // Q0
st_band = 5;
nb_bands_max = nb_tot_bands_in;
for ( i = 0; i < MBANDS_GN; i++ )
{
ener_vec[i] = (short) ( ener_vec_io[i] ); /* Q12 -> Q12 */
}
if ( L_frame == L_FRAME16k )
{
for ( i = MBANDS_GN; i < MBANDS_GN_BITALLOC16k; i++ )
{
ener_vec[i] = (short) ( ener_vec_io[i] * 4096.0 + 0.5f ); /* Q0 -> Q12 */
}
}
set_l( bits_per_bands, 0, MBANDS_GN_BITALLOC16k );
/* Decide the pourcentage of bits allocated to LF (between 50-75%) depending of the temporal contribution in GSC */
/* bit_fracf = ( -0.125f * Diff_len + 76.0f ) / 100; */
bit_fracf = L_add( Mpy_32_32( -Q31_0_00125, L_shl( Diff_len, 18 ) ), Q18_0_76 ); /* Q18 */
/* bit_fracf = check_bounds(bit_fracf, 0.50f, 0.75f); */
bit_fracf = min( max( bit_fracf, Q18_0_50 ), Q18_0_75 );
/* Adjusment of the bitrate between LF and HF base on the content type */
/* 1 = new GSC bit alloc
2 = GSC bit alloc for tc frame
3 = more music like (should not happen often given music is coded with dft) */
if ( GSC_IVAS_mode <= 3 )
{
nb_bands_max -= 6;
}
if ( GSC_IVAS_mode == 2 )
{
/* bit_fracf += 0.1f; */
bit_fracf += Q18_0_1; /* Q18*/
nb_bands_max -= 1;
}
if ( GSC_IVAS_mode == 3 )
{
/* bit_fracf -= 0.1f; */
bit_fracf -= Q18_0_1; /* Q18*/
nb_bands_max += 3;
}
/* First find how much we want to share between LF and HF, at low bitrate, a miminum of bits is needed in LF by limitating the number of bands*/
/* Adjust the number of band based on the content type and bitrate */
/* nb_bands_adj = 1.0f; */
nb_bands_adj = Q18_1_0;
if ( GSC_IVAS_mode == 1 && core_brate < GSC_L_RATE_STG )
{
/* nb_bands_adj = 0.0125f * SWB_bit_budget - 0.75f;*/
nb_bands_adj = L_sub( Mpy_32_32( Q31_0_0125, L_shl( SWB_bit_budget, 18 ) ), Q18_0_75 ); // Q18
}
else if ( GSC_IVAS_mode != 2 && core_brate > GSC_H_RATE_STG )
{
/*nb_bands_adj = 0.02f * SWB_bit_budget - 1.2f;*/
nb_bands_adj = L_sub( Mpy_32_32( Q31_0_02, L_shl( SWB_bit_budget, 18 ) ), Q18_1_2 ); // Q18
}
/*nb_bands_max = (int16_t)(nb_bands_max * nb_bands_adj + 0.5f);*/
nb_bands_max = round_fx( Mpy_32_16_1( L_shl( nb_bands_adj, 5 ), shl( nb_bands_max, 10 - 2 ) ) ); /* Q0 */
nb_bands_max = check_bounds_s( nb_bands_max, 5, nb_tot_bands_in );
/* bit_fracf *= SWB_bit_budget;*/
/* At this point bit_fracf has a value below 1.0 */
bit_fracf = Mpy_32_16_1( L_shl( bit_fracf, 10 ), extract_l( L_shl( SWB_bit_budget, 5 ) ) ); /* (Q(18+10)*Q(0+5) + 1 - 16 = Q18 */
/* Estimation of the number of bit used in HF */
/* with only the first weighting The number of bits in max_ener_band[st_band-1] = 17% of bit_fracf */
/* mb = .17f * bit_fracf;*/
mb = Mpy_32_32( Q31_0_17, bit_fracf ); /* Q18 */
/* mp = 2 * DSR_NB_PULSE;*/
mp = Q18_2_0xDSR_NB_PULSE;
if ( core_brate < GSC_L_RATE_STG && GSC_IVAS_mode == 3 )
{
/* mp = 1.5f * DSR_NB_PULSE;*/
mp = Q18_1_5xDSR_NB_PULSE;
}
else if ( core_brate < GSC_L_RATE_STG )
{
/* mp = DSR_NB_PULSE;*/
mp = Q18_DSR_NB_PULSE;
}
/* We want max_ener_band[st_band] <= max_ener_band[st_band-1] and max_ener_band[nb_bands_max-1] <= max_ener_band[st_band]*/
/* We will estimate the number of bits to allocate of HF and put the remaining bits, if any, back on LF */
/* compute the total possible number of band to be coded */
/* nb_tot_bands = (int16_t)((SWB_bit_budget - bit_fracf) / (mp + (mb - mp) / 2.0f)); */
d_tmp = Find_norm_inv( L_add( mp, mb ), &e_div );
Ltmp = Mpy_32_16_1( L_sub( L_shl( SWB_bit_budget, 18 ), bit_fracf ), d_tmp ); /* Perform mult by 1/den */
nb_tot_bands_loc = extract_h( L_shl( Ltmp, sub( 1, e_div ) ) ); /* adjust exponent: 1 is to take into account the / 2.0f, and e_div for the num and den of the division*/
mp = min( mp, mb );
tmp16 = sub( add( nb_tot_bands_loc, st_band ), nb_bands_max );
if ( tmp16 > 0 )
{
/* bit_adj = ( ( mb + mp ) / 2 ) * ( nb_tot_bands_loc + st_band - nb_bands_max ); */
bit_adj = Mpy_32_16_1( L_shl( L_add( mb, mp ), 5 ), shl( tmp16, 10 - 1 ) ); /* Q18+5 * Q0+10 + 1 -1 - 16 = Q18 (-1 is to cover for the /2 in the equation) */
bit_adj = L_max( 0, bit_adj );
nb_tot_bands_loc = nb_bands_max - st_band;
bit_fracf += bit_adj; /* Q18 */
}
nb_tot_bands_loc += st_band;
/* Allocate bits to LF */
/* etmp = 0.23f; */
etmp_32fx = Q31_0_23;
for ( j = 0; j < st_band; j++ )
{
i = j;
max_ener_band[j] = i;
ener_vec[i] = MIN16B;
/* bits_per_bands[j] = etmp * bit_fracf; */
bits_per_bands[j] = Mpy_32_32( bit_fracf, etmp_32fx ); /* 18 + 31 + 1 - 32 = Q18 */
/* etmp -= 0.015f; */
etmp_32fx -= Q31_0_015; /* Q18 */
}
/* SWB_bit_budget -= bit_fracf; */
SWB_bit_budget = L_sub( L_shl( SWB_bit_budget, 18 ), bit_fracf ); /* Q0->Q18 */
/* Find low energy band in HF */
set_s( nb_pulse_per_band, 2, MBANDS_GN_BITALLOC16k );
for ( i = st_band + 2; i < nb_tot_bands_loc - 1; i++ )
{
if ( ener_vec[i] < ener_vec[i - 1] && ener_vec[i] < ener_vec[i + 1] ) /* i +1 and i -1 can be considered as 2 ptrs */
{
nb_pulse_per_band[i] = 1;
}
}
for ( j = st_band; j < nb_tot_bands_loc; j++ )
{
if ( j > 6 )
{
i = maximum_fx( ener_vec, nb_tot_bands_loc, &etmp );
}
else
{
i = j;
}
max_ener_band[j] = i;
ener_vec[i] = MIN16B;
}
/* Recompute the final bit distribution for HF */
if ( nb_tot_bands_loc > st_band )
{
/* This is not bit exact because of the precision lost */
/* mb = ( SWB_bit_budget * 2 / ( nb_tot_bands_loc - st_band ) ) - mp; */
d_tmp = Find_norm_inv( L_deposit_h( sub( nb_tot_bands_loc, st_band ) ), &e_div );
mb = L_sub( L_shr( Mpy_32_16_1( L_shl( SWB_bit_budget, 1 ), d_tmp ), e_div ), mp ); /* Q18 */
/* bit_fracf = ( mb - mp ) / ( nb_tot_bands_loc - st_band ); */
bit_fracf = L_shr( Mpy_32_16_1( L_sub( mb, mp ), d_tmp ), e_div ); /* Q18 */
mb -= bit_fracf;
/* Do the distribution */
for ( j = st_band; j < nb_tot_bands_loc; j++ )
{
bits_per_bands[max_ener_band[j]] = Q18_DSR_NB_PULSE;
if ( nb_pulse_per_band[max_ener_band[j]] > 1 )
{
bits_per_bands[max_ener_band[j]] = mb;
}
mb -= bit_fracf;
SWB_bit_budget -= bits_per_bands[max_ener_band[j]]; // Q18
}
}
/* Series of verification in case bit allocated != the budget */
if ( SWB_bit_budget > 0 )
{
i = st_band - 1;
while ( SWB_bit_budget > 0 )
{
/* bits_per_bands[i]++; */
bits_per_bands[i] += Q18_1_0;
/* SWB_bit_budget--; */
SWB_bit_budget -= Q18_1_0;
i--;
if ( i == -1 )
{
i = st_band - 1;
}
}
}
/*nb_bands = nb_tot_bands_loc;*/
sum_bit = 0;
j = 0;
for ( i = 0; i < nb_tot_bands_loc; i++ )
{
/* if (bits_per_bands[i] > 112) */
if ( bits_per_bands[i] > Q18_112 )
{
/* sum_bit += bits_per_bands[i] - 112; */
sum_bit = L_add( sum_bit, L_sub( bits_per_bands[i], Q18_112 ) );
/* bits_per_bands[i] = 112; */
bits_per_bands[i] = Q18_112;
j = add( j, add( i, 1 ) );
}
/* safety check for overage bit reallocation */
/* else if (bits_per_bands[i] + sum_bit / 3 > 112) */
else if ( L_add( bits_per_bands[i], Mpy_32_16_1( sum_bit, Q15_0_33 ) ) > Q18_112 )
{
j = add( j, add( i, 1 ) );
}
}
if ( sum_bit != 0 )
{
/* sum_bit /= (nb_bands - j); */
d_tmp = Find_norm_inv( L_deposit_h( sub( nb_tot_bands_loc, j ) ), &e_div );
sum_bit = L_shr( Mpy_32_16_1( sum_bit, d_tmp ), e_div ); /* Q18 */
for ( i = j; i < nb_tot_bands_loc; i++ )
{
bits_per_bands[i] = L_add( bits_per_bands[i], sum_bit );
}
}
for ( i = 0; i < MBANDS_GN_BITALLOC16k; i++ )
{
bits_per_bands_o[i] = (float) bits_per_bands[i] / 262144.0f; /* Q18 -> float */
}
return nb_tot_bands_loc;
}
/* Find normalized 1 / ToDivide */
static Word16 Find_norm_inv(
const Word32 ToDivide,
Word16 *e_div )
{
Word16 d_tmp, e_tmp;
e_tmp = norm_l( ToDivide );
d_tmp = round_fx( L_shl( ToDivide, e_tmp ) );
d_tmp = div_s( 16384, d_tmp ); /* 1.0 in Q14, dividend is normalize so >= 16384 as required for the division */
*e_div = sub( 14, e_tmp );
return d_tmp;
}
static Word16 maximum_fx( /* o : index of the maximum value in the input vector */
const Word16 *vec_fx, /* i : input vector */
const Word16 lvec_fx, /* i : length of input vector */
Word16 *max_fx /* o : maximum value in the input vector */
)
{
Word16 j, ind, tmp;
ind = 0;
move16();
tmp = vec_fx[0];
move16();
FOR( j = 1; j < lvec_fx; j++ )
{
if ( GT_16( vec_fx[j], tmp ) )
{
ind = j;
move16();
}
tmp = s_max( tmp, vec_fx[j] );
}
*max_fx = tmp;
move16();
return ind;
}
#endif
......@@ -1007,7 +1007,7 @@ static Word16 Find_bit_alloc_IVAS_fx( /*o: Number
/*nb_bands_max = (int16_t)(nb_bands_max * nb_bands_adj + 0.5f);*/
nb_bands_max = round_fx( Mpy_32_16_1( L_shl( nb_bands_adj, 5 ), shl( nb_bands_max, 10 - 2 ) ) ); /* Q0 */
nb_bands_max = check_bounds_s( nb_bands_max, 5, nb_tot_bands_in );
nb_bands_max = check_bounds_s_fx( nb_bands_max, 5, nb_tot_bands_in );
/* bit_fracf *= SWB_bit_budget;*/
......
......@@ -43,234 +43,6 @@
#include "prot_fx.h"
#include "wmc_auto.h"
#ifndef IVAS_FLOAT_FIXED
/*-------------------------------------------------------------------*
* Local function prototypes
*-------------------------------------------------------------------*/
static int16_t VDQ_vec( float *Qvec_out, const float *mean_dic, const float *dic, const int16_t index, const int16_t vec_en );
#endif
/*-------------------------------------------------------------------*
* Comp_and_apply_gain()
*
* Compute and apply the quantized per band gain
*-------------------------------------------------------------------*/
#ifndef IVAS_FLOAT_FIXED
void Comp_and_apply_gain(
float exc_diffQ[], /* i/o: Quantized excitation */
float Ener_per_bd_iQ[], /* o : Target ener per band */
float Ener_per_bd_yQ[], /* o : Ener per band for norm vector */
int16_t Mbands_gn, /* i : number of bands */
const int16_t ReUseGain /* i : Reuse the gain in Ener_per_bd_yQ */
)
{
int16_t i, i_band;
int16_t StartBin, NB_Qbins;
float y_gain;
/* Recreate excitation for local synthesis and decoder */
StartBin = 0;
NB_Qbins = 0;
for ( i_band = 0; i_band < Mbands_gn; i_band++ )
{
StartBin += NB_Qbins;
NB_Qbins = mfreq_bindiv_loc[i_band];
if ( ReUseGain == 1 )
{
y_gain = Ener_per_bd_yQ[i_band];
}
else
{
y_gain = (float) pow( 10, ( Ener_per_bd_iQ[i_band] - Ener_per_bd_yQ[i_band] ) );
Ener_per_bd_yQ[i_band] = y_gain;
}
for ( i = StartBin; i < NB_Qbins + StartBin; i++ )
{
exc_diffQ[i] *= y_gain;
}
}
return;
}
#endif
#ifndef IVAS_FLOAT_FIXED
/*------------------------------------------------------------------*
* Ener_per_band_comp()
*
* Compute the energy per band in log domain for quantization purposes
* Loops are decomposed to accomodate the PVQ quantization
*------------------------------------------------------------------*/
void Ener_per_band_comp(
const float exc_diff[], /* i : target signal */
float y_gain4[], /* o : Energy per band to quantize */
const int16_t Mband, /* i : Max band */
const int16_t Eflag, /* i : flag of highest band */
const int16_t L_frame /* i : frame length */
)
{
float etmp;
const float *pt;
int16_t i, j;
pt = exc_diff;
for ( j = 0; j < 2; j++ )
{
y_gain4[j] = 0;
etmp = 0.02f;
pt = exc_diff + j * 8;
for ( i = 0; i < 8; i++ )
{
etmp += ( *pt * *pt );
pt++;
}
/* normalized to 16 bins to easy the quantization */
y_gain4[j] = (float) log10( sqrt( 2 * etmp ) );
}
for ( j = 1; j < Mband - 2; j++ )
{
etmp = 0.01f;
pt = exc_diff + j * 16;
for ( i = 0; i < 16; i++ )
{
etmp += ( *pt * *pt );
pt++;
}
y_gain4[j + 1] = (float) log10( sqrt( etmp ) );
}
if ( Eflag == 1 )
{
etmp = 0.01f;
pt = exc_diff + j * 16;
for ( i = 0; i < 32; i++ )
{
etmp += ( *pt * *pt );
pt++;
}
y_gain4[j + 1] = (float) log10( sqrt( etmp / 2 ) );
}
if ( L_frame == L_FRAME16k )
{
etmp = 0.01f;
for ( i = 0; i < 32; i++ )
{
etmp += ( *pt * *pt );
pt++;
}
y_gain4[j + 2] = (float) log10( sqrt( etmp / 2 ) );
for ( i = 0; i < 32; i++ )
{
etmp += ( *pt * *pt );
pt++;
}
y_gain4[j + 3] = (float) log10( sqrt( etmp / 2 ) );
}
return;
}
#endif
#ifndef IVAS_FLOAT_FIXED
/*-------------------------------------------------------------------*
* GSC_gain_DQ()
*
* Form the final vector after gain quantization/Dequantization
* Common to both encoder and decoder
*-------------------------------------------------------------------*/
static void GSC_gain_DQ(
const int16_t element_mode, /* i : element mode */
const int16_t enc_dec, /* i : encoder/decoder flag */
const int16_t coder_type, /* i : Coder type */
const int16_t Mbands_gn, /* i : Number of band */
const int32_t core_brate, /* i : Core bitrate */
const float mean_g, /* i : Average gain */
const float *Gain_in, /* i : Unquantized gain vector */
float *Gain_out /* o : Level adjusted unquantized gain vector */
)
{
float Gain_off;
int16_t i;
/* Gain adjustment to fit ACELP generic inactive coding gain at low rate */
Gain_off = 0.0f;
if ( coder_type == INACTIVE || coder_type == UNVOICED )
{
if ( core_brate <= ACELP_5k00 && coder_type == UNVOICED )
{
Gain_off = 9.f;
}
else if ( core_brate <= ACELP_7k20 )
{
Gain_off = 8.f; /* 0 dB */
}
else if ( core_brate <= ACELP_8k00 )
{
Gain_off = 6.6f; /* ~-3.3 dB */
}
else if ( core_brate <= ACELP_9k60 )
{
Gain_off = 4.8f; /* ~-2.4 dB */
}
else if ( core_brate <= ACELP_11k60 )
{
Gain_off = 3.5f; /* ~-2.4 dB */
}
else if ( core_brate <= ACELP_13k20 )
{
Gain_off = 3.0f; /* ~-2.4 dB */
}
}
if ( coder_type != INACTIVE && coder_type != UNVOICED )
{
for ( i = 0; i < Mbands_gn; i++ )
{
Gain_out[i] = Gain_in[i] + mean_g;
}
}
else
{
/*mimic ACELP decay of energy for low rates*/
if ( element_mode == EVS_MONO && enc_dec == DEC )
{
/* This is to keep EVS mono bit-exact with the standard (there might be a small desynchronization between encoder and decoder but there is no real quality or interop. issue) */
for ( i = 0; i < Mbands_gn; i++ )
{
Gain_out[i] += mean_g - i * ( Gain_off / 20.f ) / ( (float) Mbands_gn );
}
}
else
{
for ( i = 0; i < Mbands_gn; i++ )
{
Gain_out[i] = Gain_in[i] + mean_g - ( i * ( Gain_off / 20.f ) / ( (float) Mbands_gn ) );
}
}
}
return;
}
#endif
static void GSC_gain_DQ_fx(
const Word16 element_mode, /* i : element mode */
const Word16 enc_dec, /* i : encoder/decoder flag */
......@@ -362,240 +134,6 @@ static void GSC_gain_DQ_fx(
return;
}
#ifndef IVAS_FLOAT_FIXED
/*-------------------------------------------------------------------*
* gsc_gainQ()
*
* Quantization of the energy per band
*-------------------------------------------------------------------*/
float gsc_gainQ(
BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */
const int16_t element_mode, /* i : element mode */
const int16_t idchan, /* i : channel ID */
const float y_gain4[], /* i : Energy per band */
float y_gainQ[], /* o : quantized energy per band */
const int32_t core_brate, /* i : Core rate */
const int16_t coder_type, /* i : coding type */
const int16_t bwidth, /* i : input signal bandwidth */
const int16_t L_frame, /* i : frame length */
const int16_t tdm_LRTD_flag, /* i : LRTD stereo mode flag */
const int32_t core_brate_inp /* i : true core bitrate */
)
{
float y_gain_tmp[MBANDS_GN16k], y_gain_tmp2[MBANDS_GN16k];
int16_t i, idx_g = 0;
float mean_4g[1], ftmp1;
int16_t Mbands_gn = MBANDS_GN;
float y_gain_tmp3[MBANDS_GN];
if ( L_frame == L_FRAME16k )
{
Mbands_gn = MBANDS_GN16k;
}
mean_4g[0] = 0;
if ( ( coder_type == AUDIO || coder_type == INACTIVE ) && bwidth == NB )
{
ftmp1 = mean( y_gain4, 10 ) - 0.6f;
for ( i = 0; i < Mbands_gn; i++ )
{
if ( y_gain4[i] < ftmp1 )
{
y_gain_tmp2[i] = ftmp1;
}
else
{
y_gain_tmp2[i] = y_gain4[i];
}
}
/* Quantized mean gain without clipping */
mean_4g[0] = mean( y_gain_tmp2, 10 );
idx_g = (int16_t) vquant( mean_4g, Gain_meanNB, mean_4g, Gain_mean_dicNB, 1, 64 );
push_indice( hBstr, IND_MEAN_GAIN2, idx_g, 6 );
for ( i = 0; i < Mbands_gn; i++ )
{
y_gain_tmp[i] = y_gain_tmp2[i] - mean_4g[0];
}
if ( y_gain_tmp[9] < -0.3f )
{
y_gain_tmp[9] = -0.3f;
}
set_f( y_gain_tmp + 10, 0.0f, MBANDS_GN - 10 );
idx_g = (int16_t) vquant( y_gain_tmp, Mean_dic_NB, y_gain_tmp, Gain_dic1_NB, 3, 64 );
push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 6 );
if ( core_brate < ACELP_9k60 )
{
idx_g = vquant( y_gain_tmp + 3, Mean_dic_NB + 3, y_gain_tmp + 3, Gain_dic2_NB, 3, 32 );
push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 5 );
idx_g = vquant( y_gain_tmp + 6, Mean_dic_NB + 6, y_gain_tmp + 6, Gain_dic3_NB, 4, 16 );
push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 4 );
}
else
{
idx_g = vquant( y_gain_tmp + 3, Mean_dic_NB + 3, y_gain_tmp + 3, Gain_dic2_NBHR, 3, 64 );
push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 6 );
idx_g = vquant( y_gain_tmp + 6, Mean_dic_NB + 6, y_gain_tmp + 6, Gain_dic3_NBHR, 4, 128 );
push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 7 );
}
if ( core_brate <= ACELP_9k60 && coder_type == INACTIVE )
{
/* Some energy is needed in high band for stat_noise_uv_enc() to be functional in inactive speech */
y_gain_tmp[10] = mean( y_gain_tmp + 6, 3 );
y_gain_tmp[11] = mean( y_gain_tmp + 7, 3 );
y_gain_tmp[12] = mean( y_gain_tmp + 8, 3 );
y_gain_tmp[13] = mean( y_gain_tmp + 9, 3 );
y_gain_tmp[14] = mean( y_gain_tmp + 10, 3 );
y_gain_tmp[15] = mean( y_gain_tmp + 11, 3 );
}
else
{
set_f( y_gain_tmp + 10, 0, MBANDS_GN - 10 );
}
}
else
{
ftmp1 = mean( y_gain4, 16 );
for ( i = 0; i < Mbands_gn; i++ )
{
if ( y_gain4[i] < ftmp1 - 0.6f )
{
y_gain_tmp2[i] = ftmp1 - .6f;
}
else if ( y_gain4[i] > ftmp1 + 0.6f )
{
y_gain_tmp2[i] = ftmp1 + 0.6f;
}
else
{
y_gain_tmp2[i] = y_gain4[i];
}
}
mean_4g[0] = mean( y_gain_tmp2, 16 );
idx_g = vquant( mean_4g, mean_m, mean_4g, mean_gain_dic, 1, 64 );
push_indice( hBstr, IND_MEAN_GAIN2, idx_g, 6 );
/* Subtraction of the average gain */
for ( i = 0; i < Mbands_gn; i++ )
{
y_gain_tmp[i] = y_gain_tmp2[i] - mean_4g[0];
}
if ( core_brate < ACELP_9k60 )
{
/* prediction and quantization of the average gain */
/*--------------------------------------------------------------------------------------*
* Quantization of the first 8 bands
* Keep only 4 bands out of the last 8 bands
*--------------------------------------------------------------------------------------*/
mvr2r( y_gain_tmp, y_gain_tmp2, 8 );
y_gain_tmp2[8] = y_gain_tmp[8];
y_gain_tmp2[9] = y_gain_tmp[10];
y_gain_tmp2[10] = y_gain_tmp[12];
y_gain_tmp2[11] = y_gain_tmp[14];
idx_g = 0;
idx_g = vquant( y_gain_tmp2, YGain_mean_LR, y_gain_tmp2, YGain_dic1_LR, 3, 32 );
push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 5 );
if ( !( coder_type == INACTIVE && tdm_LRTD_flag == 0 && idchan == 1 ) || core_brate_inp > GSC_LRES_GAINQ_LIMIT )
{
idx_g = vquant( y_gain_tmp2 + 3, YGain_mean_LR + 3, y_gain_tmp2 + 3, YGain_dic2_LR, 4, 32 );
push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 5 );
/*----------------------------------------------------------------------*
* Vector quantization of the first 8 bands + quantization of the 4 bands out of the last 8
* Interpolation of the last 4 bands Q to create bands 8-16
*----------------------------------------------------------------------*/
idx_g = vquant( y_gain_tmp2 + 7, YGain_mean_LR + 7, y_gain_tmp2 + 7, YGain_dic3_LR, 5, 32 );
push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 5 );
set_f( y_gain_tmp2 + 12, 0, MBANDS_GN - 12 );
/* Update to quantized vector */
mvr2r( y_gain_tmp2, y_gain_tmp, 8 );
mvr2r( y_gain_tmp2 + 8, y_gain_tmp3, 4 );
set_f( y_gain_tmp + 8, 0, 8 );
fft_rel( y_gain_tmp2 + 8, 4, 2 );
mvr2r( y_gain_tmp2 + 8, y_gain_tmp + 8, 3 );
y_gain_tmp[15] = y_gain_tmp2[11];
ifft_rel( y_gain_tmp + 8, 8, 3 );
for ( i = 8; i < 16; i++ )
{
y_gain_tmp[i] *= 1.41f;
}
y_gain_tmp[8] = y_gain_tmp3[0];
y_gain_tmp[10] = y_gain_tmp3[1];
y_gain_tmp[12] = y_gain_tmp3[2];
y_gain_tmp[14] = y_gain_tmp3[3];
}
else
{
mvr2r( y_gain_tmp2, y_gain_tmp, 3 );
set_f( y_gain_tmp + 3, 0.0f, MBANDS_GN16k - 3 );
}
}
else
{
if ( L_frame == L_FRAME )
{
idx_g = vquant( y_gain_tmp, YG_mean16, y_gain_tmp, YG_dicMR_1, 4, 64 );
push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 6 );
idx_g = vquant( y_gain_tmp + 4, YG_mean16 + 4, y_gain_tmp + 4, YG_dicMR_2, 4, 32 );
push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 5 );
idx_g = vquant( y_gain_tmp + 8, YG_mean16 + 8, y_gain_tmp + 8, YG_dicMR_3, 4, 32 );
push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 5 );
idx_g = vquant( y_gain_tmp + 12, YG_mean16 + 12, y_gain_tmp + 12, YG_dicMR_4, 4, 16 );
push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 4 );
}
else
{
idx_g = vquant( y_gain_tmp, YG_mean16HR, y_gain_tmp, YG_dicHR_1, 4, 128 );
push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 7 );
idx_g = vquant( y_gain_tmp + 4, YG_mean16HR + 4, y_gain_tmp + 4, YG_dicHR_2, 4, 64 );
push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 6 );
idx_g = vquant( y_gain_tmp + 8, YG_mean16HR + 8, y_gain_tmp + 8, YG_dicHR_3, 4, 64 );
push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 6 );
idx_g = vquant( y_gain_tmp + 12, YG_mean16HR_16kHz, y_gain_tmp + 12, YG_dicHR_4_16kHz, 4, 64 );
push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 6 );
idx_g = vquant( y_gain_tmp + 16, YG_meanL2G_16kHz, y_gain_tmp + 16, YG_dicL2G_16kHz, 2, 8 );
push_indice( hBstr, IND_Y_GAIN_HF, idx_g, 3 );
}
}
}
GSC_gain_DQ( element_mode, ENC, coder_type, Mbands_gn, core_brate, mean_4g[0], y_gain_tmp, y_gainQ );
return mean_4g[0];
}
#endif
Word16 gsc_gainQ_ivas_fx(
BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */
const Word16 element_mode, /* i : element mode */
......@@ -886,203 +424,3 @@ Word16 gsc_gainQ_ivas_fx(
return mean_4g_fx[0];
}
#ifndef IVAS_FLOAT_FIXED
/*-------------------------------------------------------------------*
* gsc_gaindec()
*
* Generic signal frequency band decoding and application
*-------------------------------------------------------------------*/
/*! r: average frequency gain */
float gsc_gaindec(
Decoder_State *st, /* i/o: decoder state structure */
float y_gainQ[], /* o : quantized gain per band */
const int32_t core_brate, /* i : core used */
float old_y_gain[], /* i/o: AR gain quantizer for low rate */
const int16_t coder_type, /* i : coding type */
const int16_t bwidth /* i : input signal bandwidth */
)
{
int16_t idx_g, i;
float mean_4g;
int16_t Mbands_gn = MBANDS_GN;
float y_gain_tmp3[MBANDS_GN];
if ( st->L_frame == L_FRAME16k )
{
Mbands_gn = MBANDS_GN16k;
}
if ( ( coder_type == AUDIO || coder_type == INACTIVE ) && bwidth == NB )
{
idx_g = get_next_indice( st, 6 );
VDQ_vec( &mean_4g, Gain_meanNB, Gain_mean_dicNB, idx_g, 1 );
idx_g = get_next_indice( st, 6 );
VDQ_vec( y_gainQ, Mean_dic_NB, Gain_dic1_NB, idx_g, 3 );
if ( core_brate < ACELP_9k60 )
{
idx_g = get_next_indice( st, 5 );
VDQ_vec( y_gainQ + 3, Mean_dic_NB + 3, Gain_dic2_NB, idx_g, 3 );
idx_g = get_next_indice( st, 4 );
VDQ_vec( y_gainQ + 6, Mean_dic_NB + 6, Gain_dic3_NB, idx_g, 4 );
}
else
{
idx_g = get_next_indice( st, 6 );
VDQ_vec( y_gainQ + 3, Mean_dic_NB + 3, Gain_dic2_NBHR, idx_g, 3 );
idx_g = get_next_indice( st, 7 );
VDQ_vec( y_gainQ + 6, Mean_dic_NB + 6, Gain_dic3_NBHR, idx_g, 4 );
}
if ( core_brate <= ACELP_9k60 && coder_type == INACTIVE )
{
/* Some energy is needed in high band for stat_noise_uv_enc to be functional in inactive speech */
y_gainQ[10] = mean( y_gainQ + 6, 3 );
y_gainQ[11] = mean( y_gainQ + 7, 3 );
y_gainQ[12] = mean( y_gainQ + 8, 3 );
y_gainQ[13] = mean( y_gainQ + 9, 3 );
y_gainQ[14] = mean( y_gainQ + 10, 3 );
y_gainQ[15] = mean( y_gainQ + 11, 3 );
}
else
{
set_f( y_gainQ + 10, 0, MBANDS_GN - 10 );
}
}
else
{
idx_g = get_next_indice( st, 6 );
VDQ_vec( &mean_4g, mean_m, mean_gain_dic, idx_g, 1 );
if ( core_brate < ACELP_9k60 )
{
/*--------------------------------------------------------------------------------------*
* UQ of the first 8 bands and half of the last 8 bands
*--------------------------------------------------------------------------------------*/
idx_g = get_next_indice( st, 5 );
VDQ_vec( y_gainQ, YGain_mean_LR, YGain_dic1_LR, idx_g, 3 );
if ( !( coder_type == INACTIVE && st->tdm_LRTD_flag == 0 && st->idchan == 1 ) || st->core_brate > GSC_LRES_GAINQ_LIMIT )
{
idx_g = get_next_indice( st, 5 );
VDQ_vec( y_gainQ + 3, YGain_mean_LR + 3, YGain_dic2_LR, idx_g, 4 );
/*----------------------------------------------------------------------*
* Interpolation of the last 4 Q bands to create bands 8-16
* And scaling
*----------------------------------------------------------------------*/
idx_g = get_next_indice( st, 5 );
VDQ_vec( y_gainQ + 7, YGain_mean_LR + 7, YGain_dic3_LR, idx_g, 5 );
mvr2r( y_gainQ + 8, y_gain_tmp3, 4 );
set_f( y_gainQ + 12, 0.0f, 4 );
fft_rel( y_gainQ + 8, 4, 2 );
y_gainQ[15] = y_gainQ[11];
y_gainQ[11] = 0.0f;
ifft_rel( y_gainQ + 8, 8, 3 );
for ( i = 8; i < 16; i++ )
{
y_gainQ[i] *= 1.41f;
}
/*----------------------------------------------------------------------*
* Copy the true Q values in the specific bands
*----------------------------------------------------------------------*/
y_gainQ[8] = y_gain_tmp3[0];
y_gainQ[10] = y_gain_tmp3[1];
y_gainQ[12] = y_gain_tmp3[2];
y_gainQ[14] = y_gain_tmp3[3];
}
else
{
set_f( y_gainQ + 3, 0.0f, MBANDS_GN16k - 3 );
}
}
else
{
if ( st->L_frame == L_FRAME )
{
idx_g = get_next_indice( st, 6 );
VDQ_vec( y_gainQ, YG_mean16, YG_dicMR_1, idx_g, 4 );
idx_g = get_next_indice( st, 5 );
VDQ_vec( y_gainQ + 4, YG_mean16 + 4, YG_dicMR_2, idx_g, 4 );
idx_g = get_next_indice( st, 5 );
VDQ_vec( y_gainQ + 8, YG_mean16 + 8, YG_dicMR_3, idx_g, 4 );
idx_g = get_next_indice( st, 4 );
VDQ_vec( y_gainQ + 12, YG_mean16 + 12, YG_dicMR_4, idx_g, 4 );
}
else
{
idx_g = get_next_indice( st, 7 );
VDQ_vec( y_gainQ, YG_mean16HR, YG_dicHR_1, idx_g, 4 );
idx_g = get_next_indice( st, 6 );
VDQ_vec( y_gainQ + 4, YG_mean16HR + 4, YG_dicHR_2, idx_g, 4 );
idx_g = get_next_indice( st, 6 );
VDQ_vec( y_gainQ + 8, YG_mean16HR + 8, YG_dicHR_3, idx_g, 4 );
idx_g = get_next_indice( st, 6 );
VDQ_vec( y_gainQ + 12, YG_mean16HR_16kHz, YG_dicHR_4_16kHz, idx_g, 4 );
idx_g = get_next_indice( st, 3 );
VDQ_vec( y_gainQ + 16, YG_meanL2G_16kHz, YG_dicL2G_16kHz, idx_g, 2 );
}
}
}
mvr2r( y_gainQ, old_y_gain, Mbands_gn );
GSC_gain_DQ( st->element_mode, DEC, coder_type, Mbands_gn, core_brate, mean_4g, y_gainQ, y_gainQ );
return mean_4g;
}
#endif
#ifndef IVAS_FLOAT_FIXED
/*-------------------------------------------------------------------*
* VDQ_vec()
*
* Return the dequantized vector of index
*-------------------------------------------------------------------*/
static int16_t VDQ_vec(
float *Qvec_out, /* o : Quanitzed vector */
const float *mean_dic, /* i : average codebook */
const float *dic, /* i : codebook */
const int16_t index, /* i : index of codebook*/
const int16_t vec_en /* i : vector length */
)
{
int16_t i, j;
j = index * vec_en;
for ( i = 0; i < vec_en; i++ )
{
Qvec_out[i] = dic[j++];
}
for ( i = 0; i < vec_en; i++ )
{
Qvec_out[i] += mean_dic[i];
}
return index;
}
#endif
/******************************************************************************************************
(C) 2022-2024 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
contributors to this repository. All Rights Reserved.
This software is protected by copyright law and by international treaties.
The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
contributors to this repository retain full ownership rights in their respective contributions in
the software. This notice grants no license of any kind, including but not limited to patent
license, nor is any license granted by implication, estoppel or otherwise.
Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
contributions.
This software is provided "AS IS", without any express or implied warranties. The software is in the
development stage. It is intended exclusively for experts who have experience with such software and
solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
and fitness for a particular purpose are hereby disclaimed and excluded.
Any dispute, controversy or claim arising under or in relation to providing this software shall be
submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
the United Nations Convention on Contracts on the International Sales of Goods.
*******************************************************************************************************/
/*====================================================================================
EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0
====================================================================================*/
#include <stdint.h>
#include "options.h"
#include <math.h>
#include "cnst.h"
#include "rom_com.h"
#include "prot.h"
#include "wmc_auto.h"
#ifndef IVAS_FLOAT_FIXED
/*-------------------------------------------------------------------*
* gs_noisf()
*
* Noise fill-in function
*-------------------------------------------------------------------*/
static void gs_noisf(
const int16_t Start_BIN, /* i : First bin for noise fill */
const int16_t NB_Qbins, /* i : Number of bin per band */
const float Noise_fac, /* i : Noise level */
const float *y_norm, /* i : Quantized pulses */
float *exc_diffQ, /* o : Quantized pulses with noise added */
int16_t *seed_tcx, /* i : Random generator seed */
const int16_t coder_type /* i : coder type */
)
{
float ftmp;
int16_t i, k;
int16_t NB_zer = NB_Qbins / 2;
if ( coder_type == INACTIVE )
{
NB_zer = 2;
}
/*----------------------------------------------*
* noise fill-in on unquantized subvector *
* injected only from 1066Hz to 6400Hz. *
*----------------------------------------------*/
for ( k = Start_BIN; k < NB_Qbins + Start_BIN; k += NB_zer )
{
ftmp = 0.0;
for ( i = k; i < k + NB_zer; i++ )
{
exc_diffQ[i] = (float) y_norm[i];
ftmp += exc_diffQ[i] * exc_diffQ[i];
}
if ( ftmp < .5 )
{
for ( i = k; i < k + NB_zer; i++ )
{
exc_diffQ[i] += Noise_fac * ( (float) own_random( seed_tcx ) / PCM16_TO_FLT_FAC );
}
}
else
{
/* This is added only to keep the seed in sync between different compilers */
for ( i = k; i < k + NB_zer; i++ )
{
own_random( seed_tcx );
}
}
}
return;
}
/*-------------------------------------------------------------------*
* EstimateNoiseLevel_inner()
*
* Estimate noise level from the power spectrum
*-------------------------------------------------------------------*/
static void EstimateNoiseLevel_inner(
float *noisepb, /* o : Noise per band */
const int32_t bitrate, /* i : Bitrate of the codec */
const int16_t i_band, /* i : First band to compute the noise */
const int16_t Mbands_gn /* i : number of bands */
)
{
int16_t i;
float noise_offset;
noise_offset = 0.25f;
if ( bitrate > ACELP_24k40 )
{
noise_offset = .2f;
}
else if ( bitrate >= ACELP_22k60 )
{
noise_offset = .3f;
}
else if ( bitrate >= ACELP_9k60 )
{
noise_offset = 0.35f;
}
else
{
noise_offset = .4f;
}
set_f( noisepb + i_band, noise_offset, Mbands_gn - i_band );
for ( i = i_band; i < 5; i++ )
{
if ( noisepb[i] > 0.2f )
{
noisepb[i] = 0.2f;
}
}
return;
}
/*-------------------------------------------------------------------*
* EstimateNoiseLevel()
*
*
*-------------------------------------------------------------------*/
static void EstimateNoiseLevel(
float *noisepb, /* o : Noise per band */
const int32_t bitrate, /* i : Bitrate of the codec */
const int16_t Diff_len, /* i : number of bin before cut-off frequency */
const int16_t Mbands_gn, /* i : number of bands */
const int16_t coder_type, /* i : coder type */
const int16_t noise_lev, /* i : pulses dynamic */
const int16_t pit_band_idx, /* i : bin position of the cut-off frequency */
const int16_t last_bin, /* i : the last bin of bit allocation */
const int16_t bwidth,
const int16_t L_frame /* i : frame length */
)
{
int16_t i_band;
i_band = 0;
if ( Diff_len < L_frame )
{
EstimateNoiseLevel_inner( noisepb, bitrate, i_band, Mbands_gn );
if ( coder_type != INACTIVE )
{
if ( ( bitrate == ACELP_8k00 && last_bin > 8 ) && bwidth != NB )
{
while ( Mbands_gn > i_band )
{
noisepb[i_band] *= 2.0f;
i_band++;
}
}
else
{
while ( pit_band_idx > i_band )
{
noisepb[i_band] /= 2.0f;
i_band++;
}
}
}
}
if ( ( coder_type == INACTIVE || noise_lev >= NOISE_LEVEL_SP3 ) && L_frame == L_FRAME )
{
for ( i_band = 9; i_band < Mbands_gn; i_band++ )
{
noisepb[i_band] *= 1.15f;
}
}
else if ( L_frame == L_FRAME16k )
{
if ( bitrate == ACELP_13k20 )
{
set_f( noisepb, .45f, Mbands_gn );
}
if ( coder_type == INACTIVE )
{
for ( ; i_band < Mbands_gn; i_band++ )
{
noisepb[i_band] = .4f;
}
}
else if ( ( noise_lev <= NOISE_LEVEL_SP1 ) && bitrate > ACELP_16k40 )
{
for ( ; i_band < Mbands_gn - 4; i_band++ )
{
noisepb[i_band] *= .6f;
}
}
else if ( ( noise_lev <= NOISE_LEVEL_SP2 ) && bitrate > ACELP_16k40 )
{
for ( ; i_band < Mbands_gn - 4; i_band++ )
{
noisepb[i_band] *= .8f;
}
}
}
return;
}
/*-------------------------------------------------------------------*
* Apply_NoiseFill()
*
*
*-------------------------------------------------------------------*/
static void Apply_NoiseFill(
float *exc_diffQ, /* i/o: Noise per band */
int16_t *seed_tcx, /* i : Seed for noise */
const float *noisepb, /* i : Noise per band */
const int16_t Diff_len, /* i : number of bin before cut-off frequency */
const int16_t Mbands_gn, /* i : number of bands */
const int16_t coder_type, /* i : coder type */
const int16_t *freq_nsbin_per_band /* i : bin per bands tables */
)
{
int16_t StartBin, NB_Qbins, i_band;
StartBin = 0;
NB_Qbins = 0;
for ( i_band = 0; i_band < Mbands_gn; i_band++ )
{
StartBin += NB_Qbins;
NB_Qbins = freq_nsbin_per_band[i_band];
if ( Diff_len < L_FRAME )
{
gs_noisf( StartBin, NB_Qbins, noisepb[i_band], exc_diffQ, exc_diffQ, seed_tcx, coder_type );
}
}
return;
}
/*-------------------------------------------------------------------*
* freq_dnw_scaling()
*
*
*-------------------------------------------------------------------*/
void freq_dnw_scaling(
const int16_t cor_strong_limit, /* i : HF correlation */
const int16_t coder_type, /* i : coder type */
const int16_t noise_lev, /* i : Noise level */
const int32_t core_brate, /* i : Core bitrate */
float fy_norm[], /* i/o: Frequency quantized parameter */
const int16_t L_frame /* i : frame length */
)
{
float sc_dyn;
int16_t start_sc, i;
sc_dyn = 1.0f;
start_sc = L_frame;
if ( core_brate <= ACELP_8k00 && coder_type == INACTIVE )
{
sc_dyn *= .15f;
start_sc = 64;
}
else if ( coder_type == INACTIVE )
{
sc_dyn *= .25f;
start_sc = 80;
}
else
{
sc_dyn = (float) ( NOISE_LEVEL_SP3 - noise_lev ) / 10.0f + 0.4f;
start_sc = 112 + ( NOISE_LEVEL_SP3 - noise_lev ) * 16;
if ( noise_lev == NOISE_LEVEL_SP0 )
{
start_sc = L_FRAME;
}
}
if ( L_frame == L_FRAME16k && core_brate <= ACELP_24k40 )
{
sc_dyn += 0.125f;
if ( sc_dyn > 1.0f )
{
sc_dyn = 1.0f;
}
}
for ( i = start_sc; i < L_frame; i++ )
{
fy_norm[i] *= sc_dyn;
}
if ( ( core_brate < ACELP_13k20 && cor_strong_limit == 0 ) || core_brate < ACELP_9k60 )
{
for ( i = 160; i < L_frame; i++ )
{
if ( fy_norm[i] > 1.0f )
{
fy_norm[i] = 1.0f;
}
if ( fy_norm[i] < -1.0f )
{
fy_norm[i] = -1.0f;
}
}
}
else if ( core_brate < ACELP_22k60 )
{
for ( i = 160; i < L_frame; i++ )
{
if ( fy_norm[i] > 1.5f )
{
fy_norm[i] = 1.5f;
}
if ( fy_norm[i] < -1.5f )
{
fy_norm[i] = -1.5f;
}
}
}
return;
}
/*-------------------------------------------------------------------*
* Decreas_freqPeak()
*
*
*-------------------------------------------------------------------*/
static void Decreas_freqPeak(
const float *lsf_new, /* i : ISFs at the end of the frame */
float *exc_diffQ, /* i/o: frequency coefficients of per band */
float thr_rat /* i : threshold of ratio between consecutive lsf_new_diff */
)
{
int16_t i, j, k;
int16_t last_bin = 0;
int16_t pos = 0;
float *src;
float avrg, max_val;
float lsf_new_diff[M];
lsf_new_diff[0] = 0; /* prevent unitialized value */
for ( j = 1; j < ( M - 1 ); j++ )
{
lsf_new_diff[j] = lsf_new[j] - lsf_new[j - 1];
}
avrg = 0.0f;
/* This is to prevent a possible div by 0 in the '*(src) = (*src > 0) ?...'
loop. The value of 'max' is not important because it will be mutiplied
by 'avrg' and the result will be close to 0. The 'fabs(*src)/max'
div by 0 error will be avoided. */
max_val = 0.001f;
for ( i = 160; i < L_FRAME; i++ )
{
if ( fabs( exc_diffQ[i] ) > max_val )
{
max_val = (float) fabs( exc_diffQ[i] );
pos = i;
}
avrg += (float) fabs( exc_diffQ[i] );
}
avrg /= 96;
last_bin = M - 1; /* When the search is false, should equate the end of the vector, not the beginning */
for ( i = 0; i < ( M - 1 ); i++ )
{
if ( lsf_new[i] > 4000 )
{
last_bin = i;
break;
}
}
for ( i = last_bin; i < 14; i++ )
{
if ( lsf_new_diff[i] < thr_rat * lsf_new_diff[i - 1] )
{
src = &exc_diffQ[( i - 1 ) * 16];
for ( j = 0; j < 2; j++ )
{
for ( k = 0; k < 16; k++ )
{
if ( fabs( *src ) > 2.0f * avrg )
{
*( src ) = ( *src > 0 ) ? (float) ( avrg * ( 2.0f - fabs( *src ) / max_val ) ) : (float) ( -avrg * ( 2.0f - fabs( *src ) / max_val ) );
}
src++;
}
}
}
}
if ( fabs( exc_diffQ[pos] ) == max_val && max_val > 4.0f * avrg )
{
for ( i = pos - 1; i < pos + 2; i++ )
{
exc_diffQ[pos] *= 0.5f;
}
}
return;
}
/*-------------------------------------------------------------------*
* envelop_modify()
*
*
*-------------------------------------------------------------------*/
static void envelop_modify(
float *exc_diffQ, /* i/o: frequency coefficients of per band */
int16_t *seed_tcx, /* i : Seed for noise */
int16_t last_bin, /* i : last bin of bit allocation */
float *Ener_per_bd_iQ /* i : Quantized energy of targeted vector */
)
{
int16_t i, j, end_band;
float Ener, Ener1, *src;
float weight = 1.0f;
end_band = L_FRAME;
Ener = 0.1f;
for ( i = last_bin * 16; i < end_band; i++ )
{
Ener += exc_diffQ[i] * exc_diffQ[i];
}
Ener = (float) sqrt( ( end_band - last_bin * 16 ) / Ener );
weight = 0.5f;
src = &exc_diffQ[16 * last_bin];
for ( i = last_bin; i < last_bin + 4; i++ )
{
Ener1 = (float) ( 0.4f * pow( 10, Ener_per_bd_iQ[i + 1] ) );
for ( j = 0; j < 16; j++ )
{
*src = Ener1 * ( weight * ( *src ) * Ener + ( 1.0f - weight ) * own_random( seed_tcx ) / PCM16_TO_FLT_FAC );
src++;
}
}
Ener1 = (float) ( 0.4f * pow( 10, Ener_per_bd_iQ[15] ) );
src = &exc_diffQ[224];
for ( j = 0; j < 32; j++ )
{
*src = Ener1 * ( weight * ( *src ) * Ener + ( 1.0f - weight ) * own_random( seed_tcx ) / PCM16_TO_FLT_FAC );
src++;
}
return;
}
/*-------------------------------------------------------------------*
* highband_exc_dct_in()
*
*
*-------------------------------------------------------------------*/
void highband_exc_dct_in(
const int32_t core_brate, /* i : core bitrate */
const int16_t *mfreq_bindiv, /* i : bin per bands tables */
int16_t last_bin, /* i : last bin of bit allocation */
int16_t Diff_len, /* i : number of bin before cut-off frequency */
int16_t noise_lev, /* i : pulses dynamic */
int16_t pit_band_idx, /* i : bin position of the cut-off frequency */
float *exc_diffQ, /* i : frequency coefficients of per band */
int16_t *seed_tcx, /* i : Seed for noise */
float *Ener_per_bd_iQ, /* i : Quantized energy of targeted vector */
int16_t nb_subfr, /* i : Number of subframe considered */
float *exc_dct_in, /* o : dct of residual signal */
int16_t last_coder_type, /* i : coding type of last frame */
int16_t *bitallocation_band, /* i : bit allocation flag of each band */
const float *lsf_new, /* i : LSFs at the end of the frame */
float *last_exc_dct_in, /* i : dct of residual signal of last frame */
float *last_ener, /* i : frequency energy of last frame */
int16_t *last_bitallocation_band, /* i : bit allocation flag of each band of last frame */
int16_t *bitallocation_exc, /* i : flag of decoded coefficients */
const int16_t bfi, /* i : bad frame indicator */
const int16_t coder_type, /* i : coder type */
const int16_t bwidth, /* i : audio bandwidth */
float *exc_wo_nf, /* o : temporal excitation (in f domain) without noisefill */
const int16_t GSC_noisy_speech, /* i : GSC noisy speech flag */
float *lt_ener_per_band, /* i/o: Average per band energy */
const int16_t L_frame, /* i : frame length */
const int16_t element_mode, /* i : IVAS element mode */
const int16_t GSC_IVAS_mode /* i : GSC IVAS mode */
)
{
int16_t i, j;
int16_t MAX_Bin = 0;
int16_t last_bin_tmp;
float noisepb[MBANDS_GN16k];
float Ener_per_bd_yQ[MBANDS_GN16k];
float *src, *dst, *end;
float ener = 0.0f;
int16_t length_bin, bwe_flag = 0;
for ( j = 10; j < MBANDS_GN; j++ )
{
ener += (float) pow( 10, Ener_per_bd_iQ[j] );
}
if ( core_brate == ACELP_8k00 && bwidth != NB )
{
if ( last_coder_type != AUDIO )
{
*last_ener = ener;
}
if ( ( last_bin > 8 || Diff_len != 0 ) && last_coder_type == AUDIO )
{
MAX_Bin = 10;
bwe_flag = 1;
}
else
{
MAX_Bin = 15;
}
last_bin_tmp = last_bin;
if ( last_bin < MAX_Bin )
{
last_bin = MAX_Bin;
}
last_bin += 1;
}
else
{
if ( L_frame == L_FRAME16k )
{
last_bin = MBANDS_GN16k;
}
else
{
last_bin = MBANDS_GN;
}
last_bin_tmp = last_bin;
}
if ( bfi || core_brate < 6000 || ( core_brate < 8600 && coder_type == UNVOICED ) )
{
set_f( noisepb, 0.4f, MBANDS_GN );
}
else if ( GSC_IVAS_mode == 3 || ( GSC_IVAS_mode > 0 && GSC_noisy_speech == 1 ) )
{
set_f( noisepb, 0.4f, MBANDS_GN16k );
}
else
{
EstimateNoiseLevel( noisepb, core_brate, Diff_len, last_bin, coder_type, noise_lev, pit_band_idx, last_bin_tmp, bwidth, L_frame );
}
if ( exc_wo_nf != NULL )
{
mvr2r( exc_diffQ, exc_wo_nf, L_frame );
}
if ( GSC_IVAS_mode == 0 && GSC_noisy_speech && !bfi && element_mode <= IVAS_SCE )
{
set_f( noisepb, 0.1f, MBANDS_GN );
}
if ( core_brate < 6000 && coder_type <= UNVOICED )
{
for ( i = 0; i < L_frame; i++ )
{
if ( exc_diffQ[i] == 0.0f )
{
exc_diffQ[i] += 2.0f * noisepb[0] * ( (float) own_random( seed_tcx ) / PCM16_TO_FLT_FAC );
}
}
}
else
{
Apply_NoiseFill( exc_diffQ, seed_tcx, noisepb, Diff_len, last_bin, coder_type, mfreq_bindiv );
}
/*--------------------------------------------------------------------------------------*
* Quantize average gain
* Subtract Q averaged gain
* VQ of remaining gain per band
*--------------------------------------------------------------------------------------*/
if ( core_brate == ACELP_8k00 && bwidth != NB )
{
Ener_per_band_comp( exc_diffQ, Ener_per_bd_yQ, last_bin + 1, 0, L_frame );
}
else
{
Ener_per_band_comp( exc_diffQ, Ener_per_bd_yQ, MBANDS_GN, 1, L_frame );
if ( nb_subfr < 4 && L_frame < L_FRAME16k )
{
for ( i = L_FRAME - 16; i < L_FRAME; i++ )
{
exc_diffQ[i] *= ( 0.067f * i - 15.0f );
}
}
}
/*--------------------------------------------------------------------------------------*
* Check potential energy excitation overshoot
*--------------------------------------------------------------------------------------*/
if ( bfi )
{
if ( GSC_noisy_speech == 0 && coder_type > UNVOICED ) /* Here coder_type == last_coder_type because of the bfi */
{
for ( i = 0; i < last_bin; i++ )
{
Ener_per_bd_iQ[i] = min( Ener_per_bd_iQ[i], ( lt_ener_per_band[i] - 0.0376f ) - Ener_per_bd_yQ[i] );
lt_ener_per_band[i] -= 0.0188f;
}
for ( ; i < MBANDS_GN; i++ )
{
Ener_per_bd_iQ[i] = min( Ener_per_bd_iQ[i], ( lt_ener_per_band[i] - 0.0376f ) );
lt_ener_per_band[i] -= 0.0188f;
}
}
else
{
for ( i = 0; i < last_bin; i++ )
{
Ener_per_bd_iQ[i] = min( Ener_per_bd_iQ[i], ( lt_ener_per_band[i] + 0.3f ) - Ener_per_bd_yQ[i] );
lt_ener_per_band[i] -= 0.0188f;
}
for ( ; i < MBANDS_GN; i++ )
{
Ener_per_bd_iQ[i] = min( Ener_per_bd_iQ[i], ( lt_ener_per_band[i] + 0.3f ) );
lt_ener_per_band[i] -= 0.0188f;
}
}
}
/*--------------------------------------------------------------------------------------*
* Apply decoded gain onto the difference signal
*--------------------------------------------------------------------------------------*/
if ( GSC_IVAS_mode >= 1 )
{
float scale_factLF = 0.9f;
float scale_factHF = 0.9f;
if ( GSC_IVAS_mode == 1 && GSC_noisy_speech == 0 )
{
scale_factHF = 0.8f;
}
else if ( GSC_IVAS_mode == 2 || GSC_noisy_speech == 1 )
{
scale_factHF = 0.71f;
}
else if ( GSC_IVAS_mode == 3 )
{
scale_factHF = 0.9f;
}
for ( i = 0; i < pit_band_idx * 16; i++ )
{
exc_diffQ[i] *= scale_factLF;
}
for ( ; i < L_frame; i++ )
{
exc_diffQ[i] *= scale_factHF;
}
}
else if ( GSC_noisy_speech )
{
float scale_fact = 0.9f;
if ( element_mode == IVAS_CPE_TD )
{
if ( coder_type == INACTIVE )
{
scale_fact = 1.0f;
}
else
{
scale_fact = 0.95f;
}
}
else if ( element_mode > IVAS_SCE )
{
scale_fact = 0.71f;
}
for ( i = 0; i < L_frame; i++ )
{
exc_diffQ[i] *= scale_fact;
}
}
if ( GSC_noisy_speech && element_mode > IVAS_SCE && core_brate < ACELP_7k20 )
{
for ( i = 80; i < L_frame; i++ )
{
exc_diffQ[i] *= ( +0.0024f * (float) i + 1.192f );
}
}
Comp_and_apply_gain( exc_diffQ, Ener_per_bd_iQ, Ener_per_bd_yQ, last_bin, 0 );
if ( exc_wo_nf != NULL )
{
Comp_and_apply_gain( exc_wo_nf, Ener_per_bd_iQ, Ener_per_bd_yQ, last_bin, 1 );
v_add( exc_dct_in, exc_wo_nf, exc_wo_nf, L_frame );
}
/*--------------------------------------------------------------------------------------*
* add the correction layer to the LF bins,
* and add the quantized pulses or the noise for the higher part of the spectrum
* (non valuable temporal content already zeroed)
* DC is Zeroed
*--------------------------------------------------------------------------------------*/
v_add( exc_dct_in, exc_diffQ, exc_dct_in, L_frame );
if ( core_brate == ACELP_8k00 && bwidth != NB )
{
if ( bwe_flag == 1 )
{
last_bin -= 1;
src = &exc_diffQ[L_FRAME - 1];
dst = &exc_dct_in[MAX_Bin * 16 - 1];
end = &exc_diffQ[last_bin * 16 - 1];
while ( src > end )
{
*src-- = *dst--;
}
if ( ( bitallocation_exc[0] != 0 || bitallocation_exc[1] != 0 ) && core_brate == ACELP_8k00 )
{
exc_diffQ[160] = 0.0f;
}
envelop_modify( exc_diffQ, seed_tcx, last_bin, Ener_per_bd_iQ );
mvr2r( &exc_diffQ[last_bin * 16], &exc_dct_in[last_bin * 16], L_FRAME - last_bin * 16 );
}
if ( nb_subfr < 4 )
{
for ( i = L_FRAME - 16; i < L_FRAME; i++ )
{
exc_dct_in[i] *= ( 0.067f * i - 15.f );
}
}
if ( ener < 2 * ( *last_ener ) && ener > 0.5f * ( *last_ener ) )
{
length_bin = 6;
if ( last_coder_type != AUDIO )
{
set_s( last_bitallocation_band, 0, 6 );
mvr2r( &exc_dct_in[( 4 + length_bin ) * 16], &last_exc_dct_in[( 4 + length_bin ) * 16], length_bin * 16 );
}
for ( i = 4; i < ( 4 + length_bin ); i++ )
{
if ( !( bitallocation_band[i] == 0 && last_bitallocation_band[i - 4] == 0 ) )
{
src = &exc_dct_in[( i + length_bin ) * 16];
dst = &last_exc_dct_in[( i + length_bin ) * 16];
for ( j = 0; j < 16; j++ )
{
if ( fabs( *src ) > 3.0f * fabs( *dst ) )
{
*src = ( *src > 0 ) ? (float) ( 0.5f * ( *src + fabs( *dst ) ) ) : (float) ( 0.5f * ( *src - fabs( *dst ) ) );
}
else if ( fabs( *dst ) > 3.0f * fabs( *src ) )
{
*src = ( *src > 0 ) ? (float) ( 0.7f * ( *src ) + 0.3f * fabs( *dst ) ) : (float) ( 0.7f * ( *src ) - 0.3f * fabs( *dst ) );
}
src++;
dst++;
}
}
}
}
if ( bwe_flag == 1 )
{
Decreas_freqPeak( lsf_new, exc_dct_in, 0.3f );
}
else
{
Decreas_freqPeak( lsf_new, exc_dct_in, 0.5f );
}
}
mvr2r( &exc_dct_in[64], &last_exc_dct_in[64], L_frame - 64 );
mvs2s( &bitallocation_band[4], last_bitallocation_band, 6 );
*last_ener = ener;
return;
}
#endif
......@@ -48,106 +48,10 @@
*-------------------------------------------------------------------*/
#define ATT_LENGHT16k 80
#ifndef IVAS_FLOAT_FIXED
#define INV_L_FRAME16k ( 1.0f / L_FRAME16k )
#endif
#define ATT_LENGHT 64
#define ATT_SEG_LEN ( L_FRAME / ATT_LENGHT )
#ifndef IVAS_FLOAT_FIXED
#define INV_ATT_SEG_LEN ( 1.0f / ATT_SEG_LEN )
#define INV_L_FRAME ( 1.0f / L_FRAME )
#endif
#ifndef IVAS_FLOAT_FIXED
/*-------------------------------------------------------------------*
* pre_echo_att()
*
* Attenuation of the pre-echo when encoder specifies an attack
*-------------------------------------------------------------------*/
void pre_echo_att(
float *Last_frame_ener, /* i/o: Energy of the last frame */
float *exc, /* i/o: Excitation of the current frame */
const int16_t attack_flag, /* i : attack flag (GSC or TC) */
const int16_t last_coder_type, /* i : Last coder type */
const int16_t L_frame /* i : frame length */
)
{
float etmp;
float etmp1;
float finc[ATT_LENGHT16k], ratio_float, inv_l_frame;
int16_t att_len;
int16_t attack_pos, i;
if ( attack_flag > 0 && last_coder_type == AUDIO )
{
/*-------------------------------------------------------------------------*
* Find where the onset (attack) occurs by computing the energy per section
* The inverse weighting aims to favor the first maxima in case of
* gradual onset
*-------------------------------------------------------------------------*/
att_len = ATT_LENGHT;
if ( L_frame == L_FRAME16k )
{
att_len = ATT_LENGHT16k;
}
for ( i = 0; i < att_len; i++ )
{
finc[i] = sum2_f( exc + i * ATT_SEG_LEN, ATT_SEG_LEN ) * ( (float) ( att_len - i ) / ( att_len ) );
}
etmp = -1;
attack_pos = maximum( finc, att_len, &etmp );
/* Scaled the maximum energy and allowed 6 dB increase*/
etmp *= INV_ATT_SEG_LEN;
etmp1 = etmp;
*Last_frame_ener *= 4.0f;
/* If the maximum normalized energy > last frame energy + 6dB */
if ( etmp > *Last_frame_ener && attack_pos > 0 )
{
/* Find the average energy before the attack */
etmp = sum_f( finc, attack_pos ) + 0.01f;
etmp /= ( attack_pos * ATT_SEG_LEN );
/* Find the correction factor and apply it before the attack */
ratio_float = (float) sqrt( *Last_frame_ener / etmp );
/* Pre-echo atttenuation should never increase the energy */
ratio_float = min( ratio_float, 1.0f );
for ( i = 0; i < attack_pos * ATT_SEG_LEN; i++ )
{
exc[i] *= ratio_float;
}
}
*Last_frame_ener = etmp1;
}
else
{
/*-------------------------------------------------------*
* In normal cases, just compute the energy of the frame
*-------------------------------------------------------*/
etmp = sum2_f( exc, L_frame ) + 0.01f;
inv_l_frame = INV_L_FRAME;
if ( L_frame == L_FRAME16k )
{
inv_l_frame = INV_L_FRAME16k;
}
etmp *= inv_l_frame;
*Last_frame_ener = etmp;
}
return;
}
#endif
#ifdef IVAS_FLOAT_FIXED
#ifdef IVAS_FLOAT_FIXED
void pre_echo_att_fx(
Word32 *Last_frame_ener_fx, /* i/o: Energy of the last frame 2*Q_new+1*/
Word16 *exc_fx, /* i/o: Excitation of the current frame Q_new*/
......@@ -271,7 +175,6 @@ void pre_echo_att_fx(
return;
}
#endif
void pre_echo_att_ivas_fx(
......@@ -398,4 +301,3 @@ void pre_echo_att_ivas_fx(
return;
}
#endif
......@@ -51,90 +51,8 @@
* void
*/
#ifndef IVAS_FLOAT_FIXED
void hp20_flt(
Float32 signal[],
const Word16 lg,
Float32 mem[],
const Word32 Fs )
{
Word16 i;
Float32 x0, x1, x2, y0, y1, y2;
Float32 a1, a2, b1, b2;
y1 = mem[0];
y2 = mem[1];
x0 = mem[2];
x1 = mem[3];
if ( Fs == 8000 )
{
/* hp filter 20Hz at 3dB for 8000KHz input sampling rate
[b,a] = butter(2, 20.0/4000.0, 'high');
b = [0.988954248067140 -1.977908496134280 0.988954248067140]
a =[1.000000000000000 -1.977786483776764 0.978030508491796]*/
a1 = 1.977786483776764f;
a2 = -0.978030508491796f;
b1 = -1.977908496134280f;
b2 = 0.988954248067140f;
}
else if ( Fs == 16000 )
{
/* hp filter 20Hz at 3dB for 16000KHz sampling rate
[b,a] = butter(2, 20.0/8000.0, 'high');
b =[ 0.994461788958195 -1.988923577916390 0.994461788958195]
a =[1.000000000000000 -1.988892905899653 0.988954249933127] */
a1 = 1.988892905899653f;
a2 = -0.988954249933127f;
b1 = -1.988923577916390f;
b2 = 0.994461788958195f;
}
else if ( Fs == 32000 )
{
/* hp filter 20Hz at 3dB for 32000KHz sampling rate
[b,a] = butter(2, 20.0/16000.0, 'high');
b =[0.997227049904470 -1.994454099808940 0.997227049904470]
a =[1.000000000000000 -1.994446410541927 0.994461789075954]*/
a1 = 1.994446410541927f;
a2 = -0.994461789075954f;
b1 = -1.994454099808940f;
b2 = 0.997227049904470f;
}
else
{
/* hp filter 20Hz at 3dB for 48000KHz sampling rate
[b,a] = butter(2, 20.0/24000.0, 'high');
b =[ 0.998150511190452 -1.996301022380904 0.998150511190452]
a =[1.000000000000000 -1.996297601769122 0.996304442992686]*/
a1 = 1.996297601769122f;
a2 = -0.996304442992686f;
b1 = -1.996301022380904f;
b2 = 0.998150511190452f;
}
for ( i = 0; i < lg; i++ )
{
x2 = x1;
x1 = x0;
x0 = signal[i];
y0 = ( y1 * a1 ) + ( y2 * a2 ) + ( x0 * b2 ) + ( x1 * b1 ) + ( x2 * b2 );
signal[i] = y0;
y2 = y1;
y1 = y0;
}
mem[0] = ( ( y1 > 1e-10 ) | ( y1 < -1e-10 ) ) ? y1 : 0;
mem[1] = ( ( y2 > 1e-10 ) | ( y2 < -1e-10 ) ) ? y2 : 0;
mem[2] = ( ( x0 > 1e-10 ) | ( x0 < -1e-10 ) ) ? x0 : 0;
mem[3] = ( ( x1 > 1e-10 ) | ( x1 < -1e-10 ) ) ? x1 : 0;
return;
}
#endif
#define HP20_COEFF_SCALE ( 2 )
#ifdef IVAS_FLOAT_FIXED
/*
* hp20
*
......@@ -797,4 +715,3 @@ void hp20_fx_32(
return;
}
#endif
#endif
......@@ -35,7 +35,6 @@
#include "prot_fx.h"
#include "oper_32b.h"
#include "move.h"
#include "count.h"
/*--------------------------------------------------------------------------*
* hq2_noise_inject()
......
......@@ -36,6 +36,7 @@
#include <stdint.h>
#include "options.h"
#include "cnst.h"
#include "typedef.h"
/* clang-format off */
......@@ -1389,7 +1390,8 @@ typedef enum
#define MCMASA_LFE_THETA_Q14 (21299) // Q14
#define MCMASA_LFE_QLOW_Q12 (-26624) // Q12
#define MCMASA_LFE_DELTA_Q11 (2048) // Q11
#define MCMASA_LFE_QLOW_Q11 (-13312) // Q11
#define MCMASA_LFE_DELTA_Q10 (1024) // Q10
#define NUM_ELEVATED_SPEAKERS 4
#define MCMASA_MIN_SPEAKERS_SEPARATE_CENTER 4
......
......@@ -1480,14 +1480,16 @@ void calculate_hodirac_sector_parameters_fx(
tmp16 = BASOP_util_atan2( *p_sec_I_vec_smth_y_fx, *p_sec_I_vec_smth_x_fx, sub( *p_sec_I_vec_smth_y_exp, *p_sec_I_vec_smth_x_exp ) ); // Q13
*p_azi_fx = Mpy_32_32( L_deposit_h( tmp16 ), _180_OVER_PI_Q25 ); // (Q13 + 16) + Q25 - 31 = 54 - 31 = Q23
tmp16 = BASOP_util_atan2( *p_sec_I_vec_smth_z_fx, tmp_xy_hypo, sub( *p_sec_I_vec_smth_z_exp, tmp_e ) ); // Q13
move32();
tmp16 = BASOP_util_atan2( *p_sec_I_vec_smth_z_fx, L_add( tmp_xy_hypo, EPSILON_FX_SMALL ), sub( *p_sec_I_vec_smth_z_exp, tmp_e ) ); // Q13
*p_ele_fx = Mpy_32_32( L_deposit_h( tmp16 ), _180_OVER_PI_Q25 ); // (Q13 + 16) + Q25 - 31 = 54 - 31 = Q23
move32();
*p_ene_fx = *p_energy_smth_fx;
move32();
*p_ene_exp = *p_energy_smth_exp;
move16();
tmp32 = L_deposit_h( BASOP_Util_Divide3232_Scale( normI_fx, *p_energy_smth_fx, &tmp_e ) );
tmp32 = L_deposit_h( BASOP_Util_Divide3232_Scale( normI_fx, L_add( *p_energy_smth_fx, EPSILON_FX_SMALL ), &tmp_e ) );
tmp_e = add( tmp_e, sub( normI_exp, *p_energy_smth_exp ) );
tmp32 = BASOP_Util_Add_Mant32Exp( ONE_IN_Q30, 1, L_negate( tmp32 ), tmp_e, &tmp_e );
*p_diff_fx = tmp32;
......@@ -1500,16 +1502,17 @@ void calculate_hodirac_sector_parameters_fx(
move32();
tmp_diff_exp = *p_diff_exp;
move16();
if ( tmp_diff_fx < 0 )
{
tmp_diff_fx = 0;
move32();
}
tmp_diff_fx = L_shr( tmp_diff_fx, sub( 2, tmp_diff_exp ) ); // Q29
tmp_diff_exp = 2;
move16();
IF( tmp_diff_fx < 0 )
{
*p_diff_fx = 0;
move32();
}
IF( GT_32( tmp_diff_fx, ( ONE_IN_Q29 / 2 ) ) )
IF( GT_32( tmp_diff_fx, ONE_IN_Q28 ) )
{
IF( hDirAC->firstrun_sector_params )
{
......
......@@ -31,12 +31,13 @@
*******************************************************************************************************/
#include <stdint.h>
#include "options.h"
#include <assert.h>
#include <math.h>
#include "options.h"
#include "prot.h"
#include "ivas_prot.h"
#include "rom_com.h"
#include "ivas_rom_com.h"
#include <assert.h>
#include "wmc_auto.h"
#include "ivas_prot_fx.h"
#include "prot_fx.h"
......@@ -743,6 +744,7 @@ void ivas_fb_mixer_process_fx(
const Word32 *pFilterbank_bin_to_band_re_fx;
const Word32 *pFilterbank_bin_to_band_im_fx;
Word16 q_pMdft_out_fx[2];
Word32 *pMdft_out_fx[2];
Word32 *pOut_fr_re_fx, *pOut_fr_im_fx;
Word16 q_pOut_fr_fx = 31;
......@@ -837,11 +839,17 @@ void ivas_fb_mixer_process_fx(
move16();
}
}
Word16 scale = sub( s_min( L_norm_arr( pOut_fr_re_fx, frame_len ), L_norm_arr( pOut_fr_im_fx, frame_len ) ), find_guarded_bits_fx( shl( frame_len, 1 ) ) );
scale_sig32( pOut_fr_re_fx, frame_len, scale );
scale_sig32( pOut_fr_im_fx, frame_len, scale );
ivas_imdft_fx( pOut_fr_re_fx, pOut_fr_im_fx, pMdft_out_fx[hist], frame_len );
q_pMdft_out_fx[hist] = add( q_pOut_fr_fx, scale );
move16();
}
scale_sig32( pMdft_out_fx[0], shl( frame_len, 1 ), sub( s_min( q_pMdft_out_fx[0], q_pMdft_out_fx[1] ), q_pMdft_out_fx[0] ) );
scale_sig32( pMdft_out_fx[1], shl( frame_len, 1 ), sub( s_min( q_pMdft_out_fx[0], q_pMdft_out_fx[1] ), q_pMdft_out_fx[1] ) );
ivas_fb_mixer_cross_fading_fx( hFbMixer, ppOut_pcm_fx, pMdft_out_fx[0], pMdft_out_fx[1], ch, frame_len, frame_len );
q_ppOut_pcm_fx[ch] = q_pOut_fr_fx;
q_ppOut_pcm_fx[ch] = s_min( q_pMdft_out_fx[0], q_pMdft_out_fx[1] );
move16();
}
......@@ -853,7 +861,6 @@ void ivas_fb_mixer_process_fx(
*
*
*-----------------------------------------------------------------------------------------*/
#ifdef IVAS_FLOAT_FIXED
void ivas_fb_mixer_get_in_out_mapping_fx(
const IVAS_FB_CFG *fb_cfg, /* i : FB config. handle */
Word16 in_out_mixer_map[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH] /* i/o: mixing mapping */
......@@ -887,7 +894,6 @@ void ivas_fb_mixer_get_in_out_mapping_fx(
return;
}
#endif
/*-----------------------------------------------------------------------------------------*
* Function ivas_calculate_abs_fr()
......
......@@ -50,12 +50,6 @@
*-----------------------------------------------------------------------*/
#define BITS_ISM_INACTIVE ( BRATE_ISM_INACTIVE / FRAMES_PER_SEC )
#ifndef IVAS_FLOAT_FIXED
#define BETA_ISM_LOW_IMP 0.6f
#define BETA_ISM_MEDIUM_IMP 0.8f
#endif
#define BETA_ISM_LOW_IMP_Q31 ( 1288490189 ) // 0.6 in Q31
#define BETA_ISM_MEDIUM_IMP_Q31 ( 1717986918 ) // 0.8 in Q31
#define BETA_ISM_MEDIUM_IMP_BY_8_Q31 ( 214748365 ) // 0.8 in Q29
......
......@@ -248,7 +248,12 @@ ivas_error pre_proc_front_ivas_fx(
const Word16 front_vad_dtx_flag, /* i : front-VAD DTX flag to overwrite VAD decision*/
const IVAS_FORMAT ivas_format, /* i : IVAS format */
const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) */
const Word32 ivas_total_brate /* i : IVAS total bitrate - for setting the DTX */
const Word32 ivas_total_brate, /* i : IVAS total bitrate - for setting the DTX */
Word16 *Q_new
#ifdef DEBUG_MODE_INFO
,
const Word16 ch_idx
#endif
);
ivas_error pre_proc_ivas(
Encoder_State *st, /* i/o: encoder state structure */
......@@ -282,20 +287,6 @@ ivas_error pre_proc_ivas(
Word16 *Q_new
);
/*! r: number of clipped samples */
uint32_t ivas_syn_output(
float *synth[], /* i/o: float synthesis signal */
const int16_t output_frame, /* i : output frame length (one channel) */
const int16_t n_channels, /* i : number of output channels */
int16_t *synth_out /* o : integer 16 bits synthesis signal */
);
void ivas_syn_output_f(
float *synth[], /* i/o: float synthesis signal */
const int16_t output_frame, /* i : output frame length (one channel) */
const int16_t n_channels, /* i : number of output channels */
float *synth_out /* o : integer 16 bits synthesis signal */
);
void ivas_initialize_handles_enc(
Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */
);
......@@ -418,6 +409,7 @@ ivas_error ivas_core_enc(
const int16_t n_CoreChannels, /* i : number of core channels to be coded */
Word16 old_inp_12k8_fx[][L_INP_12k8], /* i : buffer of old input signal */
Word16 old_inp_16k_fx[][L_INP], /* i : buffer of old input signal */
Word16 Q_new[],
Word32 ener_fx[], /* i : residual energy from Levinson-Durbin Q6*/
Word16 A_fx[][NB_SUBFR16k * ( M + 1 )], /* i : A(z) unquantized for the 4 subframes */
Word16 Aw_fx[][NB_SUBFR16k * ( M + 1 )], /* i : weighted A(z) unquantized for subframes*/
......@@ -650,11 +642,6 @@ void TonalMdctConceal_whiten_noise_shape_ivas(
const TONALMDCTCONC_NOISE_SHAPE_WHITENING_MODE
);
float rand_triangular_signed(
int16_t *seed );
void dtx_read_padding_bits(
DEC_CORE_HANDLE st,
const int16_t num_bits
......@@ -941,18 +928,6 @@ void update_last_metadata(
const int16_t updt_flag[] /* i : last metadata update flag */
);
#ifndef IVAS_FLOAT_FIXED
void ivas_get_ism_sid_quan_bitbudget(
const int16_t nchan_ism, /* i : number of objects */
int16_t *nBits_azimuth, /* o : number of Q bits for azimuth */
int16_t *nBits_elevation, /* o : number of Q bits for elevation */
float *q_step, /* o : quantization step */
float *q_step_border, /* o : quantization step at the border */
int16_t *nBits_coh, /* o : number of Q bits for coherence */
int16_t *nBits_sce_id /* o : number of Q bits for sce_id_dtx */
);
#endif
void ivas_ism_dtx_limit_noise_energy_for_near_silence(
SCE_DEC_HANDLE hSCE[], /* i/o: SCE decoder structures */
const int16_t sce_id_dtx, /* i : SCE DTX ID */
......@@ -1989,28 +1964,6 @@ void convert_coeffs_to_higher_res(
const int16_t len /* i : length of subframes */
);
#ifndef IVAS_FLOAT_FIXED
void sns_compute_scf(
float spectrum[],
const PsychoacousticParameters *pPsychParams,
const int16_t L_frame,
float *scf
);
void sns_interpolate_scalefactors(
float *scf_int, /* o : interpolated scalefactors for spectrum shaping */
const float *scf, /* i : sns scalefactors as derived from the signal or read from the bitstream */
int16_t encoder_side /* i : flag, if scalefactors have to be inverted */
);
void sns_shape_spectrum(
float spectrum[], /* i/o: spectrum to be shaped */
const PsychoacousticParameters *pPsychParams, /* i : psychoacoustic parameters used to get the frequency bands */
const float *scf_int, /* i : already interpolated SNS scalefactors */
const int16_t L_frame /* i : frame length */
);
#endif
int16_t quantize_sns(
float sns_in[CPE_CHANNELS][NB_DIV][M],
float snsQ_out[CPE_CHANNELS][NB_DIV][M],
......@@ -2182,112 +2135,13 @@ void dtx_enc_init(
* Framework general prototypes
*----------------------------------------------------------------------------------*/
void mvr2r_inc(
const float x[], /* i : input vector */
const int16_t x_inc, /* i : increment for vector x[] */
float y[], /* o : output vector */
const int16_t y_inc, /* i : increment for vector y[] */
const int16_t n /* i : vector size */
);
void v_add_inc(
const float x1[], /* i : Input vector 1 */
const int16_t x_inc, /* i : Increment for input vector 1 */
const float x2[], /* i : Input vector 2 */
const int16_t x2_inc, /* i : Increment for input vector 2 */
float y[], /* o : Output vector that contains vector 1 + vector 2 */
const int16_t y_inc, /* i : increment for vector y[] */
const int16_t N /* i : Vector length */
);
void v_mult_inc(
const float x1[], /* i : Input vector 1 */
const int16_t x1_inc, /* i : Increment for input vector 1 */
const float x2[], /* i : Input vector 2 */
const int16_t x2_inc, /* i : Increment for input vector 1 */
float y[], /* o : Output vector that contains vector 1 .* vector 2 */
const int16_t y_inc, /* i : increment for vector y[] */
const int16_t N /* i : Vector length */
);
void v_addc(
const float x[], /* i : Input vector */
const float c, /* i : Constant */
float y[], /* o : Output vector that contains c*x */
const int16_t N /* i : Vector length */
);
void v_min(
const float x1[], /* i : Input vector 1 */
const float x2[], /* i : Input vector 2 */
float y[], /* o : Output vector that contains vector 1 .* vector 2 */
const int16_t N /* i : Vector length */
);
void v_sqrt(
const float x[], /* i : Input vector */
float y[], /* o : Output vector that contains sqrt(x) */
const int16_t N /* i : Vector length */
);
/*! r: sum abs of all vector elements */
float sumAbs(
const float *vec, /* i : input vector */
const int16_t lvec /* i : length of input vector */
);
void mvc2c(
const uint8_t x[], /* i : input vector */
uint8_t y[], /* o : output vector */
const int16_t n /* i : vector size */
);
/*! r: the dot product x'*A*A'*x */
float dot_product_cholesky(
const float *x, /* i : vector x */
const float *A, /* i : Cholesky matrix A */
const int16_t N /* i : vector & matrix size */
);
void v_mult_mat(
float *y, /* o : the product x*A */
const float *x, /* i : vector x */
const float *A, /* i : matrix A */
const int16_t N, /* i : number of rows */
const int16_t C /* i : number of columns */
);
/*! r: log(sum(exp(X)) of the input array X */
float logsumexp(
const float X[], /* i : input array X */
const int16_t N /* i : number of elements in array X */
);
/*! r: mapped output value */
float lin_interp(
const float x, /* i : the value to be mapped */
const float x1, /* i : source range interval: low end */
const float y1, /* i : source range interval: high end */
const float x2, /* i : target range interval: low */
const float y2, /* i : target range interval: high */
const int16_t flag_sat /* i : flag to indicate whether to apply saturation */
);
/*! r: Adjusted value */
float check_bounds(
const float value, /* i : Input value */
const float low, /* i : Low limit */
const float high /* i : High limit */
);
/*! r: Adjusted value */
int16_t check_bounds_s(
const int16_t value, /* i : Input value */
const int16_t low, /* i : Low limit */
const int16_t high /* i : High limit */
);
ivas_error stereo_memory_dec(
const int32_t ivas_total_brate, /* i : IVAS total bitrate */
CPE_DEC_HANDLE hCPE, /* i : CPE decoder structure */
......@@ -2376,15 +2230,6 @@ void write_mct_bitstream(
const int16_t nchan /* i : number of channels */
);
#ifndef IVAS_FLOAT_FIXED
void splitAvailableBitsMCT(
void **sts, /* i/o: encoder/decoder state structure */
const int16_t total_bits, /* i : total number of available bits */
const int16_t split_ratio[MCT_MAX_CHANNELS], /* i : ratio for splitting the bits */
const int16_t enc_dec, /* i : encoder or decoder flag */
const int16_t nchan /* i : number of channels */
);
#else
void splitAvailableBitsMCT_fx(
void **sts, /* i/o: encoder/decoder state structure */
const Word16 total_bits, /* i : total number of available bits */
......@@ -2392,7 +2237,6 @@ void splitAvailableBitsMCT_fx(
const Word16 enc_dec, /* i : encoder or decoder flag */
const Word16 nchan /* i : number of channels */
);
#endif
void getChannelEnergies(
Encoder_State **sts, /* i : Encoder state structure */
......@@ -2484,14 +2328,6 @@ void mctStereoIGF_dec(
const int16_t bfi /* i : bad frame flag */
);
#ifndef IVAS_FLOAT_FIXED
void ivas_mdct_tcx10_bit_distribution(
int16_t target_bitsTCX10[NB_DIV], /* o : target bit distribution */
const int16_t bits_frame_channel, /* i : bits frame channel */
const int16_t nTnsBitsTCX10[NB_DIV] /* i : TNS bits */
);
#endif
void enc_prm_igf_mdct(
Encoder_State *st, /* i : Encoder state handle */
BSTR_ENC_HANDLE hBstr /* i/o: Bitstream handle */
......@@ -2520,21 +2356,12 @@ ivas_error ivas_qmetadata_enc_encode_hr_384_512(
const int16_t bits_sp_coh
);
#ifndef IVAS_FLOAT_FIXED
void deindex_sph_idx(
const uint16_t sphIndex, /* i : Spherical index */
const SPHERICAL_GRID_DATA *gridData, /* i : Prepared spherical grid */
float *theta, /* o : Elevation */
float *phi /* o : Azimuth */
);
#else
void deindex_sph_idx_fx(
const UWord16 sphIndex, /* i : Spherical index */
const SPHERICAL_GRID_DATA *gridData, /* i : Prepared spherical grid */
Word32 *theta_fx, /* o : Elevation Q22*/
Word32 *phi_fx /* o : Azimuth Q22 */
);
#endif
/*! r: output index for direction */
uint16_t index_theta_phi_16(
......@@ -2605,14 +2432,6 @@ void ivas_qmetadata_azimuth_elevation_to_direction_vector(
float *dv /* o : direction vector */
);
#ifndef IVAS_FLOAT_FIXED
void ivas_qmetadata_direction_vector_to_azimuth_elevation(
const float *dv, /* i : direction vector */
float *az, /* o : azimuth */
float *el /* o : elevation */
);
#endif
ivas_error only_reduce_bits_direction(
int16_t *reduce_bits_out,
IVAS_QDIRECTION *q_direction, /* i/o: quantized direction structure */
......@@ -2649,32 +2468,6 @@ int16_t quantize_direction2D(
const MC_LS_SETUP mc_format /* i : channel format if in MC-mode */
);
#ifndef IVAS_FLOAT_FIXED
/*! r :companded azimuth value */
float companding_azimuth(
const float azi, /* i : input azimuth value */
const MC_LS_SETUP mc_format, /* i : input channel format */
const int16_t theta_flag, /* i : zero/non zero elevation flag */
const int16_t direction /* i : direction of companding (direct or inverse)*/
);
/*! r: index azimuth */
int16_t quantize_phi_chan_lbr(
const float phi, /* i : azimuth value */
float *phi_hat, /* o : quantized azimuth */
const int16_t n /* i : azimuth codebook size */
);
/*! r: index azimuth */
int16_t quantize_phi_chan_compand(
float phi, /* i : azimuth value */
float *phi_hat, /* o : quantized azimuth */
const int16_t n, /* i : azimuth codebook size */
const int16_t theta_flag, /* i : flag signaling high elevation */
const MC_LS_SETUP mc_format /* i : channel format if in MC-mode */
);
#endif
void quantize_direction_frame2D(
IVAS_QDIRECTION *q_direction, /* i/o: quantized direction structure */
float azimuth_orig[MASA_MAXIMUM_CODING_SUBBANDS][MAX_PARAM_SPATIAL_SUBFRAMES], /* i : input azimuth values */
......@@ -3014,63 +2807,6 @@ UWord16 ivas_param_mc_get_configuration_index_fx(
const Word32 ivas_total_brate /* i : IVAS total bitrate */
);
int16_t matrix_product(
const float *X, /* i : left hand matrix */
const int16_t rowsX, /* i : number of rows of the left hand matrix */
const int16_t colsX, /* i : number of columns of the left hand matrix */
const int16_t transpX, /* i : flag indicating the transposition of the left hand matrix prior to the multiplication */
const float *Y, /* i : right hand matrix */
const int16_t rowsY, /* i : number of rows of the right hand matrix */
const int16_t colsY, /* i : number of columns of the right hand matrix */
const int16_t transpY, /* i : flag indicating the transposition of the right hand matrix prior to the multiplication */
float *Z /* o : resulting matrix after the matrix multiplication */
);
int16_t matrix_diag_product(
const float *X, /* i : left hand matrix */
const int16_t rowsX, /* i : number of rows of the left hand matrix */
const int16_t colsX, /* i : number of columns of the left hand matrix */
const int16_t transpX, /* i : flag indicating the transposition of the left hand matrix prior to the multiplication */
const float *Y, /* i : right hand diagonal matrix as vector containing the diagonal elements */
const int16_t entriesY, /* i : number of entries in the diagonal */
float *Z /* o : resulting matrix after the matrix multiplication */
);
int16_t diag_matrix_product(
const float *Y, /* i : left hand diagonal matrix as vector containing the diagonal elements */
const int16_t entriesY, /* i : length of the diagonal of the left hand matrix */
const float *X, /* i : right hand matrix */
const int16_t rowsX, /* i : number of rows of the right hand matrix */
const int16_t colsX, /* i : number of columns of the right hand matrix */
const int16_t transpX, /* i : flag indicating the transposition of the right hand matrix prior to the multiplication */
float *Z /* o : resulting matrix after the matrix multiplication */
);
int16_t matrix_product_diag(
const float *X, /* i : left hand matrix */
const int16_t rowsX, /* i : number of rows of the left hand matrix */
const int16_t colsX, /* i : number of columns of the left hand matrix */
const int16_t transpX, /* i : flag indicating the transposition of the left hand matrix prior to the multiplication */
const float *Y, /* i : right hand matrix */
const int16_t rowsY, /* i : number of rows of the right hand matrix */
const int16_t colsY, /* i : number of columns of the right hand matrix */
const int16_t transpY, /* i : flag indicating the transposition of the right hand matrix prior to the multiplication */
float *Z /* o : resulting matrix after the matrix multiplication */
);
void cmplx_matrix_square(
const float *realX, /* i : real part of the matrix */
const float *imagX, /* i : imaginary part of the matrix */
const int16_t mRows, /* i : number of rows of the matrix */
const int16_t nCols, /* i : number of columns of the matrix */
float *realZ, /* o : real part of the resulting matrix */
float *imagZ /* o : imaginary part of the resulting matrix */
);
ivas_error ivas_dirac_dec_output_synthesis_cov_open(
DIRAC_OUTPUT_SYNTHESIS_PARAMS *h_dirac_output_synthesis_params, /* i/o: handle for the covariance synthesis parameters */
DIRAC_OUTPUT_SYNTHESIS_COV_STATE *h_dirac_output_synthesis_state, /* i/o: handle for the covariance synthesis state */
......@@ -3605,74 +3341,6 @@ void ivas_pca_dec(
float *pcm_out[] /* o : output audio channels */
);
#ifndef IVAS_FLOAT_FIXED
/* PCA utilities */
void eye_matrix(
float *mat,
const int16_t n,
const float d
);
void cov_subfr(
float **ptr_sig,
float *r,
const int16_t n_channels,
const int16_t len
);
void eig_qr(
const float *A,
const int16_t num_iter,
float *EV, float *Vals,
const int16_t n
);
void exhst_4x4(
float *cost_mtx,
int16_t *path,
const int16_t maximize
);
float mat_det4(
const float *m
);
/* quaternion utilities */
void mat2dquat(
const float *a,
float *ql,
float *qr
);
void dquat2mat(
const float *ql,
const float *qr,
float *m
);
void quat_shortestpath(
const float *q00,
float *q01,
const float *q10,
float *q11
);
void pca_interp_preproc(
const float *prev_ql,
const float *prev_qr,
const float *ql,
const float *qr,
const int16_t len,
float *ql_interp,
float *qr_interp
);
void pca_enc_s3(
float *q,
int32_t *index
);
#endif
void pca_dec_s3(
const int32_t index,
float *q
......@@ -3913,14 +3581,6 @@ int16_t calculate_brate_limit_flag(
const int16_t nchan_ism /* i : number of objects */
);
#ifndef IVAS_FLOAT_FIXED
void ivas_get_stereo_panning_gains(
const float aziDeg,
const float eleDeg,
float panningGains[2]
);
#endif
void ivas_masa_set_coding_config(
MASA_CODEC_CONFIG* config, /* i/o: MASA coding config structure */
int16_t* band_mapping, /* o : Band mapping used */
......@@ -3945,19 +3605,10 @@ void masa_compensate_two_dir_energy_ratio_index(
const int16_t hodirac_flag /* i : flag to indicate HO-DirAC mode */
);
#ifndef IVAS_FLOAT_FIXED
void ivas_set_qmetadata_maxbit_req(
IVAS_QMETADATA_HANDLE hQMetaData, /* o : qmetadata structure where the requirement value is set */
const IVAS_FORMAT ivas_format /* i : IVAS format */
);
#else
void ivas_set_qmetadata_maxbit_req_fx(
IVAS_QMETADATA_HANDLE hQMetaData, /* o : qmetadata structure where the requirement value is set */
const IVAS_FORMAT ivas_format /* i : IVAS format */
);
#endif
void masa_sample_rate_band_correction(
MASA_CODEC_CONFIG *config, /* i/o: MASA codec config */
......@@ -4057,12 +3708,6 @@ void panning_wrap_angles(
float *ele_wrapped /* o : wrapped elevation component */
);
void v_sort_ind(
float *x, /* i/o: Vector to be sorted */
int16_t *idx, /* o : Original index positions */
const int16_t len /* i : vector length */
);
/*----------------------------------------------------------------------------------*
* LS Renderer prototypes
*----------------------------------------------------------------------------------*/
......@@ -4151,22 +3796,6 @@ void ivas_mcmasa_dmx_modify_fx(
const Word16 n_chnls_dmx_new /* i : number of downmix channels in the target format Q0*/
);
void v_multc_acc(
const float x[], /* i : Input vector */
const float c, /* i : Constant */
float y[], /* o : Output vector that contains y + c*x */
const int16_t N /* i : Vector length */
);
void lls_interp_n(
float x[], /* i/o: input/output vector */
const int16_t N, /* i : length of the input vector */
float *a, /* o : calculated slope */
float *b, /* o : calculated offset */
const int16_t upd /* i : use 1 to update x[] with the interpolated output*/
);
ivas_error ivas_mono_dmx_renderer_open(
Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */
);
......
......@@ -864,7 +864,8 @@ void td_stereo_param_updt_fx(
);
void updt_enc_common_ivas_fx(
Encoder_State *st /* i/o: encoder state structure */
Encoder_State *st, /* i/o: encoder state structure */
const Word16 Q_new /* i : CUrrent frame scaling */
);
......@@ -5812,8 +5813,8 @@ ivas_error ivas_cpe_enc_fx(
Word32 data_fx_ch1[], /* i : input signal for channel 1 Q(q_data_fx) */
Word16 q_data_fx, /* i : Q-factor of input signal for both channels */
const Word16 input_frame, /* i : input frame length per channel */
const Word16 nb_bits_metadata /* i : number of metadata bits */
);
const Word16 nb_bits_metadata, /* i : number of metadata bits */
Word16 Q_new_out[] );
ivas_error ivas_mct_enc_fx(
Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */
......@@ -5839,7 +5840,8 @@ ivas_error ivas_compute_core_buffers_fx(
Word16 lsp_mid_fx[M], /* i/o: LSPs in the middle of the frame */
Word16 Q_old_inp_16k,
Word16 Q_r[2],
Word16 *Q_new );
Word16 *Q_new,
Word16 downscale_buf_speech_enc_pe );
ivas_error ivas_enc_fx(
Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */
......
......@@ -668,7 +668,15 @@ Word16 quantize_phi_chan_compand_fx(
delta_phi = L_shr( delta_phi, sub( 9, tmp_e ) ); // Q22
// id_phi = (int16_t) round_f( ( phi / (float) delta_phi ) );
id_phi = BASOP_Util_Divide3232_Scale( phi, delta_phi, &tmp_e ); // Q15
IF( GE_16( abs_s( id_phi ), shl_sat( 1, sub( 15, tmp_e ) ) ) )
{
id_phi = shr( id_phi, sub( 15, tmp_e ) ); // Q0
}
ELSE
{
id_phi = 0;
move16();
}
IF( add( id_phi, shr( n, 1 ) ) < 0 )
{
......
......@@ -464,25 +464,6 @@ const UWord16 ECSQ_tab_inverse[1 + ECSQ_SEGMENT_SIZE] =
};
/*-------------------------------------------------------------------------
* Stereo ICA analysis ROM tables
*------------------------------------------------------------------------*/
const float ica_sincInterp2[2*SINC_ORDER1+1] =
{
0.0f,-0.002323f,0.0f, 0.003486f, 0.0f,-0.005865f,0.0f, 0.009735f, 0.0f,-0.015447f,0.0f, 0.023503f,
0.0f,-0.034727f,0.0f, 0.050649f, 0.0f,-0.074578f,0.0f, 0.115220f, 0.0f,-0.204776f,0.0f, 0.634114f,
1.0f, 0.634114f,0.0f,-0.204776f, 0.0f, 0.115220f,0.0f,-0.074578f, 0.0f, 0.050649f,0.0f,-0.034727f,
0.0f, 0.023503f,0.0f,-0.015447f, 0.0f, 0.009735f,0.0f,-0.005865f, 0.0f, 0.003486f,0.0f,-0.002323f, 0.0f
};
const float ica_sincInterp4[2*SINC_ORDER1+1] =
{
0.0f,-0.003285f,-0.005537f,-0.004930f, 0.0f, 0.008295f, 0.015189f, 0.013767f, 0.0f,-0.021845f,-0.038282f,-0.033239f,
0.0f, 0.049111f, 0.083913f, 0.071628f, 0.0f,-0.105469f,-0.183615f,-0.162946f, 0.0f, 0.289597f, 0.626641f, 0.896773f,
1.0f, 0.896773f, 0.626641f, 0.289597f, 0.0f,-0.162946f,-0.183615f,-0.105469f, 0.0f, 0.071628f, 0.083913f, 0.049111f,
0.0f,-0.033239f,-0.038282f,-0.021845f, 0.0f, 0.013767f, 0.015189f, 0.008295f, 0.0f,-0.004930f,-0.005537f,-0.003285f, 0.0f
};
const Word16 tdm_bit_allc_tbl[5][6] =
{
/* IC -- UC -- GC -- TM --AC */
......@@ -494,41 +475,6 @@ const Word16 tdm_bit_allc_tbl[5][6] =
};
const float tdm_LSF_MEAN_PRED_QNT[M] =
{
391.31345F, 608.50453F, 968.00585F, 1354.23965F, 1709.71084F, 2080.49872F, 2450.64009F, 2796.96588F,
3196.19608F, 3554.17092F, 3915.02370F, 4283.81121F, 4707.59835F, 5109.79026F, 5526.44936F, 5903.42625F
};
const float tdm_LSF_MEAN_PRED_QNT_IN[M] =
{
288.540f, 535.469f, 899.738f, 1342.313f, 1730.736f, 2107.070f, 2491.455f, 2859.828f, 3239.279f, 3625.673f, 3992.540f, 4356.748f, 4752.356f, 5153.685f, 5567.107f, 5972.623f,
};
const float tdm_LSF_MEAN_PRED_QNT_OUT[M] =
{
286.414f, 522.366f, 887.297f, 1347.961f, 1725.604f, 2102.356f, 2511.703f, 2853.093f, 3211.319f, 3612.072f, 3970.889f, 4327.774f, 4732.423f, 5154.984f, 5572.849f, 5964.332f,
};
const float tdm_PRED_QNT_fixed_beta_prd_diag_3[15 + 16 + 15] =
{
0.7040f, 0.1203f,
-0.1119f, 0.7340f, 0.1803f,
0.0253f, 0.6702f, 0.1901f,
-0.1847f, 0.7892f, 0.3010f,
-0.0418f, 0.8716f, 0.1837f,
0.0033f, 0.6915f, 0.2394f,
0.0213f, 0.6728f, 0.2441f,
0.0705f, 0.7549f, 0.1983f,
0.0752f, 0.7152f, 0.2173f,
0.0886f, 0.6163f, 0.3067f,
0.0217f, 0.8121f, 0.2021f,
0.1584f, 0.7311f, 0.1746f,
0.1204f, 0.7296f, 0.1978f,
0.1231f, 0.7502f, 0.1234f,
0.1709f, 0.6372f, 0.1060f,
0.1193f, 0.6574f,
};
const Word16 fast_FCB_bits_2sfr[] = {8, 14, 18, 20, 24, 128/*stop value*/};
const Word16 fast_FCB_rates_2sfr[] = {/*16*50,*/ (8+14)*50, 28*50, 32*50, 34*50, 36*50, 38*50, 40*50, 42*50, 44*50, 48*50};
......@@ -2534,22 +2480,22 @@ const Word16 mcmasa_bits[IVAS_NUM_ACTIVE_BRATES] =
50, 70, 80, 120, 140, 160, 220, 256, 288, 432, 528, 832, 1024, MASA_MAX_BITS
};
const uint8_t masa_nbands[IVAS_NUM_ACTIVE_BRATES] =
const UWord8 masa_nbands[IVAS_NUM_ACTIVE_BRATES] =
{
5, 5, 5, 5, 5, 5, 5, 5, 8, 12, 18, 24, 24, 24
};
const uint8_t masa_joined_nbands[IVAS_NUM_ACTIVE_BRATES] =
const UWord8 masa_joined_nbands[IVAS_NUM_ACTIVE_BRATES] =
{
5, 5, 5, 8, 12, 12, 12, 18, 18, 18, 18, 24, 24, 24
};
const uint8_t masa_twodir_bands[IVAS_NUM_ACTIVE_BRATES] =
const UWord8 masa_twodir_bands[IVAS_NUM_ACTIVE_BRATES] =
{
0, 0, 0, 0, 0, 1, 1, 1, 3, 4, 6, 6, 9, 24
};
const uint8_t masa_twodir_bands_joined[IVAS_NUM_ACTIVE_BRATES] =
const UWord8 masa_twodir_bands_joined[IVAS_NUM_ACTIVE_BRATES] =
{
0, 0, 0, 0, 0, 2, 2, 3, 4, 6, 8, 9, 12, MASA_MAXIMUM_TWO_DIR_BANDS
};
......@@ -2646,291 +2592,6 @@ const Word16 dirac_gains_P_idx[16] =
-1, 1, 0, 1, 4, 3, 2, 3, 4, 8, 7, 6, 5, 6, 7, 8
};
const float dirac_gains_norm_term[9] =
{
1.000000e+00f, 7.071068e-01f, 1.000000e+00f, 4.082483e-01f, 2.041242e-01f, 1.000000e+00f, 2.886751e-01f, 9.128709e-02f, 3.726780e-02f
};
const float dirac_gains_Pnm[91][9] =
{
{-1.000000e+00f,-0.000000e+00f,1.000000e+00f,-0.000000e+00f,0.000000e+00f,-1.000000e+00f,-0.000000e+00f,0.000000e+00f,-0.000000e+00f},
{-9.998477e-01f,1.745221e-02f,9.995431e-01f,-5.234867e-02f,9.137391e-04f,-9.990864e-01f,1.046734e-01f,-4.568000e-03f,7.973384e-05f},
{-9.993909e-01f,3.489930e-02f,9.981732e-01f,-1.046341e-01f,3.653884e-03f,-9.963478e-01f,2.090770e-01f,-1.825829e-02f,6.375900e-04f},
{-9.986295e-01f,5.233614e-02f,9.958913e-01f,-1.567932e-01f,8.217215e-03f,-9.917910e-01f,3.129416e-01f,-4.102976e-02f,2.150287e-03f},
{-9.975641e-01f,6.975590e-02f,9.927012e-01f,-2.087579e-01f,1.459766e-02f,-9.854290e-01f,4.159897e-01f,-7.281048e-02f,5.091363e-03f},
{-9.961947e-01f,8.715547e-02f,9.886059e-01f,-2.604715e-01f,2.278823e-02f,-9.772766e-01f,5.179674e-01f,-1.135075e-01f,9.930593e-03f},
{-9.945220e-01f,1.045284e-01f,9.836106e-01f,-3.118673e-01f,3.277856e-02f,-9.673560e-01f,6.186047e-01f,-1.629950e-01f,1.713145e-02f},
{-9.925461e-01f,1.218695e-01f,9.777218e-01f,-3.628832e-01f,4.455650e-02f,-9.556924e-01f,7.176415e-01f,-2.211219e-01f,2.715038e-02f},
{-9.902681e-01f,1.391732e-01f,9.709461e-01f,-4.134564e-01f,5.810756e-02f,-9.423163e-01f,8.148217e-01f,-2.877103e-01f,4.043508e-02f},
{-9.876884e-01f,1.564343e-01f,9.632925e-01f,-4.635251e-01f,7.341509e-02f,-9.272624e-01f,9.098945e-01f,-3.625562e-01f,5.742321e-02f},
{-9.848077e-01f,1.736484e-01f,9.547693e-01f,-5.130307e-01f,9.046126e-02f,-9.105685e-01f,1.002619e+00f,-4.454347e-01f,7.854224e-02f},
{-9.816272e-01f,1.908091e-01f,9.453878e-01f,-5.619103e-01f,1.092244e-01f,-8.922793e-01f,1.092752e+00f,-5.360881e-01f,1.042050e-01f},
{-9.781475e-01f,2.079115e-01f,9.351591e-01f,-6.101044e-01f,1.296816e-01f,-8.724410e-01f,1.180063e+00f,-6.342387e-01f,1.348115e-01f},
{-9.743701e-01f,2.249510e-01f,9.240957e-01f,-6.575567e-01f,1.518089e-01f,-8.511051e-01f,1.264332e+00f,-7.395903e-01f,1.707479e-01f},
{-9.702957e-01f,2.419219e-01f,9.122107e-01f,-7.042075e-01f,1.755787e-01f,-8.283265e-01f,1.345341e+00f,-8.518162e-01f,2.123816e-01f},
{-9.659258e-01f,2.588191e-01f,8.995191e-01f,-7.500002e-01f,2.009620e-01f,-8.041639e-01f,1.422883e+00f,-9.705719e-01f,2.600640e-01f},
{-9.612616e-01f,2.756374e-01f,8.860360e-01f,-7.948789e-01f,2.279279e-01f,-7.786796e-01f,1.496760e+00f,-1.095492e+00f,3.141272e-01f},
{-9.563048e-01f,2.923716e-01f,8.717782e-01f,-8.387891e-01f,2.564435e-01f,-7.519395e-01f,1.566788e+00f,-1.226191e+00f,3.748840e-01f},
{-9.510565e-01f,3.090171e-01f,8.567626e-01f,-8.816782e-01f,2.864747e-01f,-7.240118e-01f,1.632789e+00f,-1.362268e+00f,4.426280e-01f},
{-9.455186e-01f,3.255681e-01f,8.410082e-01f,-9.234920e-01f,3.179837e-01f,-6.949692e-01f,1.694595e+00f,-1.503298e+00f,5.176268e-01f},
{-9.396926e-01f,3.420202e-01f,8.245332e-01f,-9.641815e-01f,3.509334e-01f,-6.648846e-01f,1.752055e+00f,-1.648848e+00f,6.001316e-01f},
{-9.335804e-01f,3.583678e-01f,8.073587e-01f,-1.003696e+00f,3.852825e-01f,-6.338369e-01f,1.805025e+00f,-1.798461e+00f,6.903643e-01f},
{-9.271840e-01f,3.746064e-01f,7.895051e-01f,-1.041987e+00f,4.209899e-01f,-6.019047e-01f,1.853375e+00f,-1.951675e+00f,7.885275e-01f},
{-9.205049e-01f,3.907311e-01f,7.709939e-01f,-1.079010e+00f,4.580124e-01f,-5.691693e-01f,1.896987e+00f,-2.108013e+00f,8.947984e-01f},
{-9.135456e-01f,4.067366e-01f,7.518480e-01f,-1.114717e+00f,4.963039e-01f,-5.357154e-01f,1.935757e+00f,-2.266981e+00f,1.009325e+00f},
{-9.063079e-01f,4.226184e-01f,7.320906e-01f,-1.149067e+00f,5.358188e-01f,-5.016273e-01f,1.969593e+00f,-2.428084e+00f,1.132234e+00f},
{-8.987941e-01f,4.383712e-01f,7.117461e-01f,-1.182016e+00f,5.765077e-01f,-4.669925e-01f,1.998415e+00f,-2.590808e+00f,1.263622e+00f},
{-8.910065e-01f,4.539906e-01f,6.908387e-01f,-1.213526e+00f,6.183225e-01f,-4.318987e-01f,2.022162e+00f,-2.754647e+00f,1.403563e+00f},
{-8.829476e-01f,4.694716e-01f,6.693946e-01f,-1.243556e+00f,6.612108e-01f,-3.964354e-01f,2.040781e+00f,-2.919073e+00f,1.552099e+00f},
{-8.746198e-01f,4.848095e-01f,6.474397e-01f,-1.272072e+00f,7.051207e-01f,-3.606927e-01f,2.054234e+00f,-3.083563e+00f,1.709246e+00f},
{-8.660253e-01f,5.000000e-01f,6.250001e-01f,-1.299038e+00f,7.500000e-01f,-3.247595e-01f,2.062500e+00f,-3.247595e+00f,1.875000e+00f},
{-8.571672e-01f,5.150381e-01f,6.021037e-01f,-1.324421e+00f,7.957926e-01f,-2.887278e-01f,2.065570e+00f,-3.410637e+00f,2.049318e+00f},
{-8.480480e-01f,5.299194e-01f,5.787782e-01f,-1.348191e+00f,8.424437e-01f,-2.526874e-01f,2.063448e+00f,-3.572164e+00f,2.232136e+00f},
{-8.386706e-01f,5.446391e-01f,5.550525e-01f,-1.370318e+00f,8.898951e-01f,-2.167299e-01f,2.056155e+00f,-3.731644e+00f,2.423358e+00f},
{-8.290377e-01f,5.591928e-01f,5.309552e-01f,-1.390776e+00f,9.380897e-01f,-1.809446e-01f,2.043725e+00f,-3.888559e+00f,2.622865e+00f},
{-8.191521e-01f,5.735765e-01f,5.065152e-01f,-1.409539e+00f,9.869699e-01f,-1.454202e-01f,2.026202e+00f,-4.042392e+00f,2.830513e+00f},
{-8.090171e-01f,5.877852e-01f,4.817629e-01f,-1.426585e+00f,1.036474e+00f,-1.102460e-01f,2.003651e+00f,-4.192627e+00f,3.046121e+00f},
{-7.986355e-01f,6.018150e-01f,4.567280e-01f,-1.441893e+00f,1.086544e+00f,-7.550830e-02f,1.976144e+00f,-4.338763e+00f,3.269493e+00f},
{-7.880108e-01f,6.156614e-01f,4.314414e-01f,-1.455444e+00f,1.137117e+00f,-4.129366e-02f,1.943771e+00f,-4.480302e+00f,3.500396e+00f},
{-7.771459e-01f,6.293205e-01f,4.059335e-01f,-1.467221e+00f,1.188133e+00f,-7.685401e-03f,1.906632e+00f,-4.616763e+00f,3.738582e+00f},
{-7.660444e-01f,6.427876e-01f,3.802360e-01f,-1.477211e+00f,1.239528e+00f,2.523343e-02f,1.864843e+00f,-4.747667e+00f,3.983766e+00f},
{-7.547096e-01f,6.560589e-01f,3.543800e-01f,-1.485402e+00f,1.291240e+00f,5.738307e-02f,1.818529e+00f,-4.872555e+00f,4.235647e+00f},
{-7.431449e-01f,6.691306e-01f,3.283964e-01f,-1.491783e+00f,1.343207e+00f,8.868646e-02f,1.767831e+00f,-4.990988e+00f,4.493906e+00f},
{-7.313538e-01f,6.819984e-01f,3.023174e-01f,-1.496346e+00f,1.395365e+00f,1.190676e-01f,1.712898e+00f,-5.102528e+00f,4.758184e+00f},
{-7.193397e-01f,6.946585e-01f,2.761744e-01f,-1.499086e+00f,1.447651e+00f,1.484544e-01f,1.653893e+00f,-5.206765e+00f,5.028115e+00f},
{-7.071068e-01f,7.071068e-01f,2.500000e-01f,-1.500000e+00f,1.500000e+00f,1.767767e-01f,1.590990e+00f,-5.303301e+00f,5.303301e+00f},
{-6.946585e-01f,7.193397e-01f,2.238256e-01f,-1.499086e+00f,1.552349e+00f,2.039685e-01f,1.524373e+00f,-5.391762e+00f,5.583331e+00f},
{-6.819984e-01f,7.313538e-01f,1.976825e-01f,-1.496346e+00f,1.604635e+00f,2.299670e-01f,1.454233e+00f,-5.471792e+00f,5.867779e+00f},
{-6.691307e-01f,7.431448e-01f,1.716038e-01f,-1.491783e+00f,1.656792e+00f,2.547115e-01f,1.380777e+00f,-5.543053e+00f,6.156183e+00f},
{-6.560589e-01f,7.547096e-01f,1.456200e-01f,-1.485402e+00f,1.708760e+00f,2.781472e-01f,1.304214e+00f,-5.605237e+00f,6.448089e+00f},
{-6.427876e-01f,7.660444e-01f,1.197639e-01f,-1.477212e+00f,1.760472e+00f,3.002205e-01f,1.224767e+00f,-5.658049e+00f,6.743000e+00f},
{-6.293203e-01f,7.771461e-01f,9.406608e-02f,-1.467221e+00f,1.811868e+00f,3.208840e-01f,1.142662e+00f,-5.701226e+00f,7.040430e+00f},
{-6.156614e-01f,7.880108e-01f,6.855855e-02f,-1.455444e+00f,1.862883e+00f,3.400929e-01f,1.058135e+00f,-5.734527e+00f,7.339859e+00f},
{-6.018151e-01f,7.986354e-01f,4.327216e-02f,-1.441893e+00f,1.913455e+00f,3.578070e-01f,9.714287e-01f,-5.757732e+00f,7.640767e+00f},
{-5.877852e-01f,8.090171e-01f,1.823708e-02f,-1.426585e+00f,1.963526e+00f,3.739910e-01f,8.827875e-01f,-5.770657e+00f,7.942629e+00f},
{-5.735764e-01f,8.191520e-01f,-6.515074e-03f,-1.409539e+00f,2.013030e+00f,3.886124e-01f,7.924678e-01f,-5.773133e+00f,8.244888e+00f},
{-5.591928e-01f,8.290376e-01f,-3.095508e-02f,-1.390776e+00f,2.061910e+00f,4.016449e-01f,7.007229e-01f,-5.765026e+00f,8.547005e+00f},
{-5.446391e-01f,8.386706e-01f,-5.505246e-02f,-1.370318e+00f,2.110105e+00f,4.130656e-01f,6.078163e-01f,-5.746228e+00f,8.848414e+00f},
{-5.299193e-01f,8.480480e-01f,-7.877823e-02f,-1.348191e+00f,2.157557e+00f,4.228564e-01f,5.140093e-01f,-5.716654e+00f,9.148557e+00f},
{-5.150380e-01f,8.571674e-01f,-1.021038e-01f,-1.324421e+00f,2.204208e+00f,4.310043e-01f,4.195672e-01f,-5.676254e+00f,9.446875e+00f},
{-5.000001e-01f,8.660253e-01f,-1.249999e-01f,-1.299038e+00f,2.250000e+00f,4.375000e-01f,3.247599e-01f,-5.625000e+00f,9.742785e+00f},
{-4.848095e-01f,8.746197e-01f,-1.474395e-01f,-1.272072e+00f,2.294879e+00f,4.423398e-01f,2.298521e-01f,-5.562896e+00f,1.003573e+01f},
{-4.694715e-01f,8.829476e-01f,-1.693947e-01f,-1.243556e+00f,2.338789e+00f,4.455244e-01f,1.351145e-01f,-5.489975e+00f,1.032514e+01f},
{-4.539906e-01f,8.910065e-01f,-1.908388e-01f,-1.213526e+00f,2.381678e+00f,4.470587e-01f,4.081347e-02f,-5.406296e+00f,1.061045e+01f},
{-4.383711e-01f,8.987940e-01f,-2.117461e-01f,-1.182016e+00f,2.423492e+00f,4.469530e-01f,-5.278682e-02f,-5.311945e+00f,1.089110e+01f},
{-4.226183e-01f,9.063078e-01f,-2.320906e-01f,-1.149067e+00f,2.464181e+00f,4.452218e-01f,-1.454199e-01f,-5.207041e+00f,1.116653e+01f},
{-4.067367e-01f,9.135454e-01f,-2.518479e-01f,-1.114717e+00f,2.503696e+00f,4.418841e-01f,-2.368270e-01f,-5.091725e+00f,1.143620e+01f},
{-3.907311e-01f,9.205048e-01f,-2.709937e-01f,-1.079010e+00f,2.541987e+00f,4.369636e-01f,-3.267503e-01f,-4.966168e+00f,1.169956e+01f},
{-3.746066e-01f,9.271839e-01f,-2.895049e-01f,-1.041988e+00f,2.579010e+00f,4.304885e-01f,-4.149371e-01f,-4.830570e+00f,1.195608e+01f},
{-3.583679e-01f,9.335804e-01f,-3.073587e-01f,-1.003696e+00f,2.614717e+00f,4.224911e-01f,-5.011396e-01f,-4.685155e+00f,1.220525e+01f},
{-3.420201e-01f,9.396927e-01f,-3.245333e-01f,-9.641814e-01f,2.649067e+00f,4.130083e-01f,-5.851153e-01f,-4.530170e+00f,1.244654e+01f},
{-3.255681e-01f,9.455186e-01f,-3.410081e-01f,-9.234920e-01f,2.682016e+00f,4.020810e-01f,-6.666291e-01f,-4.365895e+00f,1.267948e+01f},
{-3.090170e-01f,9.510564e-01f,-3.567626e-01f,-8.816779e-01f,2.713525e+00f,3.897543e-01f,-7.454509e-01f,-4.192628e+00f,1.290358e+01f},
{-2.923717e-01f,9.563047e-01f,-3.717781e-01f,-8.387894e-01f,2.743556e+00f,3.760769e-01f,-8.213612e-01f,-4.010692e+00f,1.311838e+01f},
{-2.756374e-01f,9.612617e-01f,-3.860361e-01f,-7.948790e-01f,2.772072e+00f,3.611015e-01f,-8.941467e-01f,-3.820433e+00f,1.332343e+01f},
{-2.588190e-01f,9.659258e-01f,-3.995190e-01f,-7.499999e-01f,2.799038e+00f,3.448846e-01f,-9.636030e-01f,-3.622222e+00f,1.351832e+01f},
{-2.419219e-01f,9.702957e-01f,-4.122107e-01f,-7.042072e-01f,2.824421e+00f,3.274858e-01f,-1.029536e+00f,-3.416446e+00f,1.370262e+01f},
{-2.249510e-01f,9.743701e-01f,-4.240956e-01f,-6.575566e-01f,2.848191e+00f,3.089685e-01f,-1.091760e+00f,-3.203517e+00f,1.387596e+01f},
{-2.079118e-01f,9.781476e-01f,-4.351591e-01f,-6.101051e-01f,2.870318e+00f,2.893990e-01f,-1.150101e+00f,-2.983865e+00f,1.403797e+01f},
{-1.908090e-01f,9.816272e-01f,-4.453879e-01f,-5.619099e-01f,2.890776e+00f,2.688461e-01f,-1.204397e+00f,-2.757931e+00f,1.418832e+01f},
{-1.736482e-01f,9.848077e-01f,-4.547695e-01f,-5.130303e-01f,2.909539e+00f,2.473820e-01f,-1.254495e+00f,-2.526181e+00f,1.432668e+01f},
{-1.564344e-01f,9.876883e-01f,-4.632923e-01f,-4.635254e-01f,2.926584e+00f,2.250811e-01f,-1.300254e+00f,-2.289093e+00f,1.445277e+01f},
{-1.391731e-01f,9.902681e-01f,-4.709463e-01f,-4.134560e-01f,2.941893e+00f,2.020205e-01f,-1.341547e+00f,-2.047161e+00f,1.456631e+01f},
{-1.218693e-01f,9.925461e-01f,-4.777218e-01f,-3.628827e-01f,2.955444e+00f,1.782789e-01f,-1.378258e+00f,-1.800889e+00f,1.466707e+01f},
{-1.045285e-01f,9.945219e-01f,-4.836107e-01f,-3.118677e-01f,2.967221e+00f,1.539375e-01f,-1.410285e+00f,-1.550796e+00f,1.475483e+01f},
{-8.715577e-02f,9.961947e-01f,-4.886058e-01f,-2.604724e-01f,2.977212e+00f,1.290786e-01f,-1.437538e+00f,-1.297406e+00f,1.482941e+01f},
{-6.975648e-02f,9.975641e-01f,-4.927011e-01f,-2.087597e-01f,2.985402e+00f,1.037861e-01f,-1.459940e+00f,-1.041256e+00f,1.489065e+01f},
{-5.233594e-02f,9.986295e-01f,-4.958915e-01f,-1.567926e-01f,2.991783e+00f,7.814553e-02f,-1.477429e+00f,-7.828888e-01f,1.493841e+01f},
{-3.489946e-02f,9.993909e-01f,-4.981730e-01f,-1.046346e-01f,2.996346e+00f,5.224292e-02f,-1.489957e+00f,-5.228543e-01f,1.497260e+01f},
{-1.745235e-02f,9.998478e-01f,-4.995431e-01f,-5.234908e-02f,2.999086e+00f,2.616524e-02f,-1.497488e+00f,-2.617055e-01f,1.499315e+01f},
{-4.371139e-08f,1.000000e+00f,-5.000000e-01f,-1.311342e-07f,3.000000e+00f,6.556709e-08f,-1.500000e+00f,-6.556709e-07f,1.500000e+01f}
};
const float dirac_gains_trg_term[181][2] =
{
{-1.000000e+00f,8.742278e-08f},
{-9.998477e-01f,-1.745246e-02f},
{-9.993908e-01f,-3.489945e-02f},
{-9.986295e-01f,-5.233605e-02f},
{-9.975641e-01f,-6.975647e-02f},
{-9.961947e-01f,-8.715564e-02f},
{-9.945219e-01f,-1.045285e-01f},
{-9.925461e-01f,-1.218693e-01f},
{-9.902681e-01f,-1.391732e-01f},
{-9.876884e-01f,-1.564344e-01f},
{-9.848077e-01f,-1.736483e-01f},
{-9.816272e-01f,-1.908090e-01f},
{-9.781476e-01f,-2.079116e-01f},
{-9.743701e-01f,-2.249511e-01f},
{-9.702957e-01f,-2.419219e-01f},
{-9.659258e-01f,-2.588191e-01f},
{-9.612617e-01f,-2.756374e-01f},
{-9.563048e-01f,-2.923716e-01f},
{-9.510565e-01f,-3.090170e-01f},
{-9.455186e-01f,-3.255681e-01f},
{-9.396926e-01f,-3.420202e-01f},
{-9.335805e-01f,-3.583679e-01f},
{-9.271839e-01f,-3.746065e-01f},
{-9.205049e-01f,-3.907312e-01f},
{-9.135455e-01f,-4.067366e-01f},
{-9.063078e-01f,-4.226183e-01f},
{-8.987941e-01f,-4.383711e-01f},
{-8.910065e-01f,-4.539906e-01f},
{-8.829476e-01f,-4.694716e-01f},
{-8.746198e-01f,-4.848095e-01f},
{-8.660254e-01f,-5.000001e-01f},
{-8.571673e-01f,-5.150380e-01f},
{-8.480480e-01f,-5.299193e-01f},
{-8.386706e-01f,-5.446390e-01f},
{-8.290377e-01f,-5.591928e-01f},
{-8.191521e-01f,-5.735765e-01f},
{-8.090171e-01f,-5.877852e-01f},
{-7.986355e-01f,-6.018151e-01f},
{-7.880108e-01f,-6.156614e-01f},
{-7.771459e-01f,-6.293205e-01f},
{-7.660444e-01f,-6.427876e-01f},
{-7.547097e-01f,-6.560590e-01f},
{-7.431448e-01f,-6.691306e-01f},
{-7.313537e-01f,-6.819983e-01f},
{-7.193397e-01f,-6.946585e-01f},
{-7.071068e-01f,-7.071068e-01f},
{-6.946585e-01f,-7.193397e-01f},
{-6.819983e-01f,-7.313537e-01f},
{-6.691307e-01f,-7.431448e-01f},
{-6.560590e-01f,-7.547097e-01f},
{-6.427876e-01f,-7.660444e-01f},
{-6.293203e-01f,-7.771460e-01f},
{-6.156614e-01f,-7.880108e-01f},
{-6.018151e-01f,-7.986355e-01f},
{-5.877852e-01f,-8.090170e-01f},
{-5.735765e-01f,-8.191520e-01f},
{-5.591928e-01f,-8.290376e-01f},
{-5.446391e-01f,-8.386706e-01f},
{-5.299193e-01f,-8.480480e-01f},
{-5.150380e-01f,-8.571673e-01f},
{-5.000001e-01f,-8.660254e-01f},
{-4.848095e-01f,-8.746197e-01f},
{-4.694716e-01f,-8.829476e-01f},
{-4.539906e-01f,-8.910065e-01f},
{-4.383711e-01f,-8.987941e-01f},
{-4.226183e-01f,-9.063078e-01f},
{-4.067367e-01f,-9.135454e-01f},
{-3.907312e-01f,-9.205049e-01f},
{-3.746066e-01f,-9.271839e-01f},
{-3.583679e-01f,-9.335805e-01f},
{-3.420201e-01f,-9.396926e-01f},
{-3.255681e-01f,-9.455186e-01f},
{-3.090170e-01f,-9.510565e-01f},
{-2.923717e-01f,-9.563047e-01f},
{-2.756374e-01f,-9.612617e-01f},
{-2.588190e-01f,-9.659258e-01f},
{-2.419219e-01f,-9.702957e-01f},
{-2.249510e-01f,-9.743701e-01f},
{-2.079117e-01f,-9.781476e-01f},
{-1.908090e-01f,-9.816272e-01f},
{-1.736482e-01f,-9.848077e-01f},
{-1.564344e-01f,-9.876884e-01f},
{-1.391731e-01f,-9.902681e-01f},
{-1.218693e-01f,-9.925461e-01f},
{-1.045285e-01f,-9.945219e-01f},
{-8.715577e-02f,-9.961947e-01f},
{-6.975648e-02f,-9.975641e-01f},
{-5.233594e-02f,-9.986295e-01f},
{-3.489946e-02f,-9.993908e-01f},
{-1.745235e-02f,-9.998477e-01f},
{-4.371139e-08f,-1.000000e+00f},
{1.745238e-02f,-9.998477e-01f},
{3.489950e-02f,-9.993908e-01f},
{5.233597e-02f,-9.986295e-01f},
{6.975651e-02f,-9.975641e-01f},
{8.715580e-02f,-9.961947e-01f},
{1.045284e-01f,-9.945219e-01f},
{1.218693e-01f,-9.925461e-01f},
{1.391731e-01f,-9.902681e-01f},
{1.564345e-01f,-9.876884e-01f},
{1.736482e-01f,-9.848077e-01f},
{1.908089e-01f,-9.816272e-01f},
{2.079117e-01f,-9.781476e-01f},
{2.249510e-01f,-9.743701e-01f},
{2.419219e-01f,-9.702957e-01f},
{2.588191e-01f,-9.659258e-01f},
{2.756374e-01f,-9.612617e-01f},
{2.923717e-01f,-9.563048e-01f},
{3.090170e-01f,-9.510565e-01f},
{3.255681e-01f,-9.455186e-01f},
{3.420202e-01f,-9.396926e-01f},
{3.583680e-01f,-9.335804e-01f},
{3.746066e-01f,-9.271839e-01f},
{3.907311e-01f,-9.205049e-01f},
{4.067366e-01f,-9.135455e-01f},
{4.226182e-01f,-9.063078e-01f},
{4.383712e-01f,-8.987941e-01f},
{4.539905e-01f,-8.910065e-01f},
{4.694716e-01f,-8.829476e-01f},
{4.848096e-01f,-8.746197e-01f},
{5.000000e-01f,-8.660254e-01f},
{5.150381e-01f,-8.571673e-01f},
{5.299193e-01f,-8.480481e-01f},
{5.446390e-01f,-8.386706e-01f},
{5.591929e-01f,-8.290375e-01f},
{5.735765e-01f,-8.191521e-01f},
{5.877852e-01f,-8.090170e-01f},
{6.018150e-01f,-7.986355e-01f},
{6.156615e-01f,-7.880107e-01f},
{6.293204e-01f,-7.771460e-01f},
{6.427876e-01f,-7.660444e-01f},
{6.560590e-01f,-7.547095e-01f},
{6.691306e-01f,-7.431449e-01f},
{6.819984e-01f,-7.313537e-01f},
{6.946584e-01f,-7.193398e-01f},
{7.071068e-01f,-7.071068e-01f},
{7.193398e-01f,-6.946584e-01f},
{7.313537e-01f,-6.819983e-01f},
{7.431448e-01f,-6.691306e-01f},
{7.547096e-01f,-6.560590e-01f},
{7.660444e-01f,-6.427876e-01f},
{7.771460e-01f,-6.293204e-01f},
{7.880108e-01f,-6.156615e-01f},
{7.986355e-01f,-6.018150e-01f},
{8.090170e-01f,-5.877852e-01f},
{8.191521e-01f,-5.735765e-01f},
{8.290376e-01f,-5.591929e-01f},
{8.386706e-01f,-5.446391e-01f},
{8.480481e-01f,-5.299193e-01f},
{8.571673e-01f,-5.150381e-01f},
{8.660254e-01f,-5.000000e-01f},
{8.746197e-01f,-4.848096e-01f},
{8.829476e-01f,-4.694716e-01f},
{8.910065e-01f,-4.539905e-01f},
{8.987941e-01f,-4.383712e-01f},
{9.063078e-01f,-4.226183e-01f},
{9.135454e-01f,-4.067366e-01f},
{9.205049e-01f,-3.907311e-01f},
{9.271839e-01f,-3.746066e-01f},
{9.335804e-01f,-3.583679e-01f},
{9.396926e-01f,-3.420201e-01f},
{9.455186e-01f,-3.255681e-01f},
{9.510565e-01f,-3.090170e-01f},
{9.563048e-01f,-2.923717e-01f},
{9.612617e-01f,-2.756374e-01f},
{9.659258e-01f,-2.588190e-01f},
{9.702957e-01f,-2.419219e-01f},
{9.743701e-01f,-2.249510e-01f},
{9.781476e-01f,-2.079117e-01f},
{9.816272e-01f,-1.908090e-01f},
{9.848077e-01f,-1.736482e-01f},
{9.876884e-01f,-1.564345e-01f},
{9.902681e-01f,-1.391731e-01f},
{9.925461e-01f,-1.218693e-01f},
{9.945219e-01f,-1.045285e-01f},
{9.961947e-01f,-8.715574e-02f},
{9.975641e-01f,-6.975647e-02f},
{9.986295e-01f,-5.233596e-02f},
{9.993908e-01f,-3.489950e-02f},
{9.998477e-01f,-1.745241e-02f},
{1.000000e+00f,0.000000e+00f}
};
/*----------------------------------------------------------------------------------*
* FB ROM tables
*----------------------------------------------------------------------------------*/
......
......@@ -78,8 +78,6 @@ extern const UWord16 ECSQ_tab_inverse[1 + ECSQ_SEGMENT_SIZE];
/*----------------------------------------------------------------------------------*
* Stereo ICA ROM tables
*----------------------------------------------------------------------------------*/
extern const float ica_sincInterp4[];
extern const float ica_sincInterp2[];
extern const Word16 tdm_bit_allc_tbl[5][6];
/* LSFs Intra-frame prediction tables */
......@@ -100,11 +98,6 @@ extern const Word16 tdm_LSF_MEAN_PRED_QNT_fx[M];
extern const Word16 tdm_PRED_QNT_fixed_beta_prd_diag_3_fx[15 + 16 + 15];
extern const float tdm_LSF_MEAN_PRED_QNT_OUT[M];
extern const float tdm_LSF_MEAN_PRED_QNT_IN[M];
extern const float tdm_LSF_MEAN_PRED_QNT[M];
extern const float tdm_PRED_QNT_fixed_beta_prd_diag_3[15 + 16 + 15];
extern const Word16 fast_FCB_bits_2sfr[];
extern const Word16 fast_FCB_rates_2sfr[];
......@@ -288,9 +281,6 @@ extern const ivas_lfe_freq_models ivas_str_lfe_freq_models;
extern const Word16 ivas_lfe_lpf_delay_Q15[2];
extern const Word16 dirac_gains_P_idx[16];
extern const float dirac_gains_norm_term[9];
extern const float dirac_gains_Pnm[91][9];
extern const float dirac_gains_trg_term[181][2];
/*------------------------------------------------------------------------------------------*
* FB ROM tables
......
/******************************************************************************************************
(C) 2022-2024 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
contributors to this repository. All Rights Reserved.
This software is protected by copyright law and by international treaties.
The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
contributors to this repository retain full ownership rights in their respective contributions in
the software. This notice grants no license of any kind, including but not limited to patent
license, nor is any license granted by implication, estoppel or otherwise.
Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
contributions.
This software is provided "AS IS", without any express or implied warranties. The software is in the
development stage. It is intended exclusively for experts who have experience with such software and
solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
and fitness for a particular purpose are hereby disclaimed and excluded.
Any dispute, controversy or claim arising under or in relation to providing this software shall be
submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
the United Nations Convention on Contracts on the International Sales of Goods.
*******************************************************************************************************/
#include <stdint.h>
#include "options.h"
#include "cnst.h"
#include "prot.h"
#include "ivas_prot.h"
#include "rom_com.h"
#include "ivas_rom_com.h"
#include <math.h>
#include <assert.h>
#include "wmc_auto.h"
#ifndef IVAS_FLOAT_FIXED
/*-------------------------------------------------------------------
* sns_compute_scf()
*
*
*-------------------------------------------------------------------*/
void sns_compute_scf(
float spectrum[],
const PsychoacousticParameters *pPsychParams,
const int16_t L_frame,
float *scf )
{
int16_t i, n, k;
float x[FDNS_NPTS], xs[FDNS_NPTS], sum, mean, xl4[SNS_NPTS], nf, xl[FDNS_NPTS];
float tilt;
const uint8_t nBands = pPsychParams->nBands;
const uint8_t *bandLengths = pPsychParams->bandLengths;
int8_t bw = 0;
const float w_0 = 1.0f / 12.0f;
const float w_1 = 2.0f / 12.0f;
const float w_2 = 0.25f; /* 3.0f / 12.0f */
const float w_3 = w_2;
const float w_4 = w_1;
const float w_5 = w_0;
const float scale_log = INV_LOG_2 * 0.5f;
assert( nBands == FDNS_NPTS );
set_f( x, 0.0f, FDNS_NPTS );
if ( bandLengths == NULL )
{
bw = (int8_t) ( L_frame / nBands );
/* Energy per band */
k = 0;
for ( i = 0; i < nBands; ++i )
{
x[i] = 0.0f;
for ( n = 0; n < bw; ++n, ++k )
{
x[i] += spectrum[k];
}
x[i] /= bw;
}
}
else
{
/* Energy per band */
k = 0;
for ( i = 0; i < nBands; ++i )
{
x[i] = 0.0f;
for ( n = 0; n < bandLengths[i]; ++n, ++k )
{
x[i] += spectrum[k];
}
x[i] /= bandLengths[i];
}
}
/* Smoothing */
xs[0] = 0.75f * x[0] + 0.25f * x[1];
for ( i = 1; i < FDNS_NPTS - 1; i++ )
{
xs[i] = 0.5f * x[i] + 0.25f * x[i - 1] + 0.25f * x[i + 1];
}
xs[FDNS_NPTS - 1] = 0.75f * x[FDNS_NPTS - 1] + 0.25f * x[FDNS_NPTS - 2];
/* Pre-emphasis */
switch ( L_frame )
{
case L_FRAME16k:
tilt = 19.f;
break;
case L_FRAME25_6k:
tilt = 22.f;
break;
case L_FRAME32k:
tilt = 23.5f;
break;
default:
tilt = 0.f;
assert( !"illegal frame length in sns_compute_scf" );
}
for ( i = 0; i < FDNS_NPTS; i++ )
{
xs[i] = xs[i] * powf( 10.0f, (float) i * (float) tilt / ( (float) FDNS_NPTS - 1.0f ) / 10.0f );
}
/* Noise floor at -40dB */
sum = sum_f( xs, FDNS_NPTS );
mean = sum / FDNS_NPTS;
nf = mean * powf( 10.0f, -4.0f );
nf = max( nf, powf( 2.0f, -32.0f ) );
for ( i = 0; i < FDNS_NPTS; i++ )
{
if ( xs[i] < nf )
{
xs[i] = nf;
}
}
/* Log-domain */
for ( i = 0; i < FDNS_NPTS; i++ )
{
xl[i] = logf( xs[i] ) * scale_log;
}
/* Downsampling */
xl4[0] = w_0 * xl[0] +
w_1 * xl[0] +
w_2 * xl[1] +
w_3 * xl[2] +
w_4 * xl[3] +
w_5 * xl[4];
for ( n = 1; n < SNS_NPTS - 1; n++ )
{
int16_t n4 = 4 * n;
xl4[n] = w_0 * xl[n4 - 1] +
w_1 * xl[n4] +
w_2 * xl[n4 + 1] +
w_3 * xl[n4 + 2] +
w_4 * xl[n4 + 3] +
w_5 * xl[n4 + 4];
}
xl4[SNS_NPTS - 1] = w_0 * xl[FDNS_NPTS - 5] +
w_1 * xl[FDNS_NPTS - 4] +
w_2 * xl[FDNS_NPTS - 3] +
w_3 * xl[FDNS_NPTS - 2] +
w_4 * xl[FDNS_NPTS - 1] +
w_5 * xl[FDNS_NPTS - 1];
/* Remove mean and scaling */
sum = sum_f( xl4, SNS_NPTS );
mean = sum / SNS_NPTS;
for ( i = 0; i < SNS_NPTS; i++ )
{
scf[i] = 0.85f * ( xl4[i] - mean );
}
return;
}
/*-------------------------------------------------------------------
* sns_interpolate_scalefactors()
*
*
*-------------------------------------------------------------------*/
void sns_interpolate_scalefactors(
float *scf_int, /* o : interpolated scalefactors for spectrum shaping*/
const float *scf, /* i : sns scalefactors as derived from the signal or read from the bitstream */
int16_t encoder_side /* i : flag, if scalefactors have to be inverted */
)
{
int16_t n;
/* Interpolation */
scf_int[0] = scf[0];
scf_int[1] = scf[0];
for ( n = 0; n <= M - 2; n++ )
{
scf_int[n * 4 + 2] = scf[n] + ( scf[n + 1] - scf[n] ) / 8.f;
scf_int[n * 4 + 3] = scf[n] + 3.f * ( scf[n + 1] - scf[n] ) / 8.f;
scf_int[n * 4 + 4] = scf[n] + 5.f * ( scf[n + 1] - scf[n] ) / 8.f;
scf_int[n * 4 + 5] = scf[n] + 7.f * ( scf[n + 1] - scf[n] ) / 8.f;
}
scf_int[FDNS_NPTS - 2] = scf[M - 1] + ( scf[M - 1] - scf[M - 2] ) / 8.f;
scf_int[FDNS_NPTS - 1] = scf[M - 1] + 3.f * ( scf[M - 1] - scf[M - 2] ) / 8.f;
/* Inversion at encoder-side */
if ( encoder_side == ENC )
{
for ( n = 0; n < FDNS_NPTS; n++ )
{
scf_int[n] = -scf_int[n];
}
}
/* Linear domain */
for ( n = 0; n < FDNS_NPTS; n++ )
{
scf_int[n] = powf( 2.f, scf_int[n] );
}
return;
}
/*-------------------------------------------------------------------
* sns_shape_spectrum()
*
*
*-------------------------------------------------------------------*/
void sns_shape_spectrum(
float spectrum[], /* i/o: spectrum to be shaped */
const PsychoacousticParameters *pPsychParams, /* i : psychoacoustic parameters used to get the frequency bands */
const float *scf_int, /* i : already interpolated SNS scalefactors */
const int16_t L_frame /* i : frame length */
)
{
int16_t i, n, k, bw;
const uint8_t nBands = pPsychParams->nBands;
const uint8_t *bandLengths = pPsychParams->bandLengths;
if ( bandLengths == NULL )
{
bw = L_frame / nBands;
/* Shape spectrum */
k = 0;
for ( i = 0; i < nBands; ++i )
{
for ( n = 0; n < bw; ++n, ++k )
{
spectrum[k] *= scf_int[i];
}
}
}
else
{
/* Shape spectrum */
k = 0;
for ( i = 0; i < nBands; ++i )
{
for ( n = 0; n < bandLengths[i]; ++n, ++k )
{
spectrum[k] *= scf_int[i];
}
}
}
return;
}
#endif
......@@ -51,24 +51,6 @@
* sum of absolute values
* ---------------------------------------------------------------*/
/*! r: sum abs of all vector elements */
float sumAbs(
const float *vec, /* i : input vector */
const int16_t lvec /* i : length of input vector */
)
{
int16_t i;
float tmp;
tmp = 0.0f;
for ( i = 0; i < lvec; i++ )
{
tmp += fabsf( vec[i] );
}
return tmp;
}
Word32 sumAbs_fx(
const Word32 *vec, /* i : input vector Qx*/
const Word16 lvec /* i : length of input vector Q0*/
......@@ -94,31 +76,33 @@ Word32 sumAbs_fx(
*---------------------------------------------------------------------*/
void mvc2c(
const uint8_t x[], /* i : input vector */
uint8_t y[], /* o : output vector */
const int16_t n /* i : vector size */
const UWord8 x[], /* i : input vector */
UWord8 y[], /* o : output vector */
const Word16 n /* i : vector size */
)
{
int16_t i;
Word16 i;
if ( n <= 0 )
IF( n <= 0 )
{
/* no need to transfer vectors with size 0 */
return;
}
if ( y < x )
IF( y < x )
{
for ( i = 0; i < n; i++ )
FOR( i = 0; i < n; i++ )
{
y[i] = x[i];
move16();
}
}
else
ELSE
{
for ( i = n - 1; i >= 0; i-- )
FOR( i = n - 1; i >= 0; i-- )
{
y[i] = x[i];
move16();
}
}
......@@ -134,34 +118,6 @@ void mvc2c(
*-------------------------------------------------------------------*/
/*! r: number of clipped samples */
uint32_t ivas_syn_output(
float *synth[], /* i/o: float synthesis signal */
const int16_t output_frame, /* i : output frame length (one channel) */
const int16_t n_channels, /* i : number of output channels */
int16_t *synth_out /* o : integer 16 bits synthesis signal */
)
{
int16_t i, n;
int16_t synth_loc[MAX_JBM_L_FRAME48k];
uint32_t noClipping = 0;
/*-----------------------------------------------------------------*
* float to integer conversion with saturation control
*-----------------------------------------------------------------*/
for ( n = 0; n < n_channels; n++ )
{
noClipping += mvr2s( synth[n], synth_loc, output_frame );
for ( i = 0; i < output_frame; i++ )
{
synth_out[i * n_channels + n] = synth_loc[i];
}
}
return noClipping;
}
UWord32 ivas_syn_output_fx(
Word32 *synth[], /* i/o: float synthesis signal q_synth*/
const Word16 q_synth,
......@@ -204,30 +160,6 @@ UWord32 ivas_syn_output_fx(
*-------------------------------------------------------------------*/
/*! r: number of clipped samples */
void ivas_syn_output_f(
float *synth[], /* i/o: float synthesis signal */
const int16_t output_frame, /* i : output frame length (one channel) */
const int16_t n_channels, /* i : number of output channels */
float *synth_out /* o : integer 16 bits synthesis signal */
)
{
int16_t i, n;
/*-----------------------------------------------------------------*
* float to integer conversion with saturation control
*-----------------------------------------------------------------*/
for ( n = 0; n < n_channels; n++ )
{
for ( i = 0; i < output_frame; i++ )
{
synth_out[i * n_channels + n] = synth[n][i];
}
}
return;
}
void ivas_syn_output_f_fx(
Word32 *synth[], /* i/o: float synthesis signal Q11*/
const Word16 output_frame, /* i : output frame length (one channel) Q0*/
......@@ -288,8 +220,8 @@ void mvr2r_inc_fixed_one(
y_fx[iy] = x_fx[ix]; /*Q29*/
move32();
ix = add( ix, x_inc );
iy = add( iy, y_inc );
ix = ix + x_inc;
iy = iy + y_inc;
}
}
ELSE
......@@ -301,8 +233,8 @@ void mvr2r_inc_fixed_one(
y_fx[iy] = x_fx[ix]; /*Q29*/
move32();
ix = sub( ix, x_inc );
iy = sub( iy, y_inc );
ix = ix - x_inc;
iy = iy - y_inc;
}
}
......@@ -338,8 +270,8 @@ void mvr2r_inc_fixed(
y_fx[iy] = x_fx[ix]; /*Q29*/
move32();
ix = add( ix, x_inc );
iy = add( iy, y_inc );
ix = ix + x_inc;
iy = iy + y_inc;
}
}
ELSE
......@@ -351,52 +283,8 @@ void mvr2r_inc_fixed(
y_fx[iy] = x_fx[ix]; /*Q29*/
move32();
ix = sub( ix, x_inc );
iy = sub( iy, y_inc );
}
}
return;
}
void mvr2r_inc(
const float x[], /* i : input vector */
const int16_t x_inc, /* i : increment for vector x[] */
float y[], /* o : output vector */
const int16_t y_inc, /* i : increment for vector y[] */
const int16_t n /* i : vector size */
)
{
int16_t i;
int16_t ix;
int16_t iy;
if ( n <= 0 )
{
/* cannot transfer vectors with size 0 */
return;
}
if ( y < x )
{
ix = 0;
iy = 0;
for ( i = 0; i < n; i++ )
{
y[iy] = x[ix];
ix += x_inc;
iy += y_inc;
}
}
else
{
ix = ( n - 1 ) * x_inc;
iy = ( n - 1 ) * y_inc;
for ( i = n - 1; i >= 0; i-- )
{
y[iy] = x[ix];
ix -= x_inc;
iy -= y_inc;
ix = ix - x_inc;
iy = iy - y_inc;
}
}
......@@ -409,32 +297,6 @@ void mvr2r_inc(
* Addition of two vectors sample by sample with explicit increments
*-------------------------------------------------------------------*/
void v_add_inc(
const float x1[], /* i : Input vector 1 */
const int16_t x_inc, /* i : Increment for input vector 1 */
const float x2[], /* i : Input vector 2 */
const int16_t x2_inc, /* i : Increment for input vector 2 */
float y[], /* o : Output vector that contains vector 1 + vector 2 */
const int16_t y_inc, /* i : increment for vector y[] */
const int16_t N /* i : Vector length */
)
{
int16_t i;
int16_t ix1 = 0;
int16_t ix2 = 0;
int16_t iy = 0;
for ( i = 0; i < N; i++ )
{
y[iy] = x1[ix1] + x2[ix2];
ix1 += x_inc;
ix2 += x2_inc;
iy += y_inc;
}
return;
}
// for same q//
void v_add_inc_fx(
const Word32 x1[], /* i : Input vector 1 Qx*/
......@@ -446,10 +308,35 @@ void v_add_inc_fx(
const Word16 N /* i : Vector length Q0*/
)
{
#ifndef FIX_1107_VADDINC
Word16 i;
Word16 ix1 = 0;
Word16 ix2 = 0;
Word16 iy = 0;
#else
Word16 i, ix1, ix2, iy;
/* The use of this function is currently always for the interleaved input format, */
/* that means, the following conditions are always true and thus obsolete. */
test();
test();
test();
test();
IF( ( sub( x_inc, 2 ) == 0 ) && ( sub( x2_inc, 2 ) == 0 ) && ( sub( y_inc, 1 ) == 0 ) && ( &x1[1] == &x2[0] ) )
{
/* Interleaved input case, linear output */
FOR( i = 0; i < N; i++ )
{
y[i] = L_add( x1[2 * i + 0], x1[2 * i + 1] ); /*Qx*/
move32();
}
return;
}
ix1 = 0;
ix2 = 0;
iy = 0;
#endif
move16();
move16();
move16();
......@@ -540,38 +427,6 @@ void v_mult_inc_fixed(
return;
}
/*-------------------------------------------------------------------*
* v_mult_inc()
*
* Multiplication of two vectors with explicit increments
*-------------------------------------------------------------------*/
void v_mult_inc(
const float x1[], /* i : Input vector 1 */
const int16_t x1_inc, /* i : Increment for input vector 1 */
const float x2[], /* i : Input vector 2 */
const int16_t x2_inc, /* i : Increment for input vector 1 */
float y[], /* o : Output vector that contains vector 1 .* vector 2 */
const int16_t y_inc, /* i : increment for vector y[i] */
const int16_t N /* i : Vector length */
)
{
int16_t i;
int16_t ix1 = 0;
int16_t ix2 = 0;
int16_t iy = 0;
for ( i = 0; i < N; i++ )
{
y[iy] = x1[ix1] * x2[ix2];
ix1 += x1_inc;
ix2 += x2_inc;
iy += y_inc;
}
return;
}
/*-------------------------------------------------------------------*
* v_addc_fx()
*
......@@ -618,23 +473,6 @@ void v_addc_fixed(
return;
}
void v_addc(
const float x[], /* i : Input vector */
const float c, /* i : Constant */
float y[], /* o : Output vector that contains c*x */
const int16_t N /* i : Vector length */
)
{
int16_t i;
for ( i = 0; i < N; i++ )
{
y[i] = c + x[i];
}
return;
}
/*-------------------------------------------------------------------*
* v_min_fx()
*
......@@ -693,29 +531,6 @@ void v_min_fx(
return;
}
/*-------------------------------------------------------------------*
* v_min()
*
* minimum of two vectors
*-------------------------------------------------------------------*/
void v_min(
const float x1[], /* i : Input vector 1 */
const float x2[], /* i : Input vector 2 */
float y[], /* o : Output vector that contains vector 1 .* vector 2 */
const int16_t N /* i : Vector length */
)
{
int16_t i;
for ( i = 0; i < N; i++ )
{
y[i] = ( x1[i] < x2[i] ) ? x1[i] : x2[i];
}
return;
}
/*-------------------------------------------------------------------*
* v_sqrt()
......@@ -740,23 +555,6 @@ void v_sqrt_fx(
return;
}
void v_sqrt(
const float x[], /* i : Input vector */
float y[], /* o : Output vector that contains sqrt(x) */
const int16_t N /* i : Vector length */
)
{
int16_t i;
for ( i = 0; i < N; i++ )
{
y[i] = sqrtf( x[i] );
}
return;
}
/*-------------------------------------------------------------------*
* v_sub_s()
*
......@@ -800,24 +598,6 @@ void v_sub32_fx(
return;
}
void v_sub_s(
const int16_t x1[], /* i : Input vector 1 */
const int16_t x2[], /* i : Input vector 2 */
int16_t y[], /* o : Output vector that contains vector 1 - vector 2 */
const int16_t N /* i : Vector length */
)
{
int16_t i;
for ( i = 0; i < N; i++ )
{
y[i] = x1[i] - x2[i];
}
return;
}
/*---------------------------------------------------------------------*
* dot_product_cholesky()
*
......@@ -827,34 +607,6 @@ void v_sub_s(
*---------------------------------------------------------------------*/
/*! r: the dot product x'*A*A'*x */
float dot_product_cholesky(
const float *x, /* i : vector x */
const float *A, /* i : Cholesky matrix A */
const int16_t N /* i : vector & matrix size */
)
{
int16_t i, j;
float suma, tmp_sum;
const float *pt_x, *pt_A;
pt_A = A;
suma = 0;
for ( i = 0; i < N; i++ )
{
tmp_sum = 0;
pt_x = x;
for ( j = 0; j <= i; j++ )
{
float mul = *pt_x++ * *pt_A++;
tmp_sum += mul;
}
suma += tmp_sum * tmp_sum;
}
return suma;
}
Word32 dot_product_cholesky_fixed(
const Word32 *x, /* i : vector x Q31 - exp_x*/
const Word32 *A, /* i : Cholesky matrix A Q31 - exp_A*/
......@@ -1024,47 +776,6 @@ void v_mult_mat_fx(
return;
}
/*---------------------------------------------------------------------*
* v_mult_mat()
*
* Multiplication of row vector x by matrix A, where x has size Nr and
* A has size Nr x Nc ans it is stored column-wise in memory.
* The resulting row vector y has size Nc
*---------------------------------------------------------------------*/
void v_mult_mat(
float *y, /* o : the product x*A */
const float *x, /* i : vector x */
const float *A, /* i : matrix A */
const int16_t Nr, /* i : number of rows */
const int16_t Nc /* i : number of columns */
)
{
int16_t i, j;
const float *pt_x, *pt_A;
float tmp_y[MAX_V_MULT_MAT];
float *pt_y;
pt_y = tmp_y;
pt_A = A;
for ( i = 0; i < Nc; i++ )
{
pt_x = x;
*pt_y = 0;
for ( j = 0; j < Nr; j++ )
{
*pt_y += ( *pt_x++ ) * ( *pt_A++ );
}
pt_y++;
}
mvr2r( tmp_y, y, Nc );
return;
}
/*---------------------------------------------------------------------*
* logsumexp()
......@@ -1073,32 +784,6 @@ void v_mult_mat(
*---------------------------------------------------------------------*/
/*! r: log(sum(exp(x)) of the input array x */
float logsumexp(
const float x[], /* i : input array x */
const int16_t N /* i : number of elements in array x */
)
{
float max_exp;
float sum;
int16_t i;
max_exp = x[0];
sum = 0;
for ( i = 1; i < N; i++ )
{
if ( x[i] > max_exp )
{
max_exp = x[i];
}
}
for ( i = 0; i < N; i++ )
{
sum += expf( x[i] - max_exp );
}
return logf( sum ) + max_exp;
}
Word32 logsumexp_fx(
const Word32 x[], /* i : input array x Q31 - x_e*/
const Word16 x_e,
......@@ -1188,76 +873,13 @@ Word32 lin_interp32_fx(
return temp32; /*Q_io*/
}
/*! r: mapped output value */
float lin_interp(
const float x, /* i : the value to be mapped */
const float x1, /* i : source range interval: low end */
const float y1, /* i : source range interval: high end */
const float x2, /* i : target range interval: low */
const float y2, /* i : target range interval: high */
const int16_t flag_sat /* i : flag to indicate whether to apply saturation */
)
{
if ( x2 - x1 == 0 )
{
return y1;
}
else if ( flag_sat )
{
if ( x >= max( x1, x2 ) )
{
return x1 > x2 ? y1 : y2;
}
else if ( x <= min( x1, x2 ) )
{
return x1 < x2 ? y1 : y2;
}
}
return y1 + ( x - x1 ) * ( y2 - y1 ) / ( x2 - x1 );
}
/*-------------------------------------------------------------------*
* check_bounds()
* check_bounds_s_fx()
*
* Ensure the input value is within the given limits
*-------------------------------------------------------------------*/
/*! r: Adjusted value */
float check_bounds(
const float value, /* i : Input value */
const float low, /* i : Low limit */
const float high /* i : High limit */
)
{
float value_adj;
value_adj = min( max( value, low ), high );
return value_adj;
}
/*-------------------------------------------------------------------*
* check_bounds_s()
*
* Ensure the input value is within the given limits
*-------------------------------------------------------------------*/
/*! r: Adjusted value */
int16_t check_bounds_s(
const int16_t value, /* i : Input value */
const int16_t low, /* i : Low limit */
const int16_t high /* i : High limit */
)
{
int16_t value_adj;
value_adj = min( max( value, low ), high );
return value_adj;
}
Word16 check_bounds_s_fx(
const Word16 value, /* i : Input value Q0*/
const Word16 low, /* i : Low limit Q0*/
......@@ -1302,105 +924,6 @@ Word32 check_bounds_l(
* comput the matrix product of two matrices (Z=X*Y)
*---------------------------------------------------------------------*/
/*! r: success or failure */
int16_t matrix_product(
const float *X, /* i : left hand matrix */
const int16_t rowsX, /* i : number of rows of the left hand matrix */
const int16_t colsX, /* i : number of columns of the left hand matrix */
const int16_t transpX, /* i : flag indicating the transposition of the left hand matrix prior to the multiplication */
const float *Y, /* i : right hand matrix */
const int16_t rowsY, /* i : number of rows of the right hand matrix */
const int16_t colsY, /* i : number of columns of the right hand matrix */
const int16_t transpY, /* i : flag indicating the transposition of the right hand matrix prior to the multiplication */
float *Z /* o : resulting matrix after the matrix multiplication */
)
{
int16_t i, j, k;
float *Zp = Z;
/* Processing */
if ( transpX == 1 && transpY == 0 ) /* We use X transpose */
{
if ( rowsX != rowsY )
{
return EXIT_FAILURE;
}
for ( j = 0; j < colsY; ++j )
{
for ( i = 0; i < colsX; ++i )
{
( *Zp ) = 0.0f;
for ( k = 0; k < rowsX; ++k )
{
( *Zp ) += X[k + i * rowsX] * Y[k + j * rowsY];
}
Zp++;
}
}
}
else if ( transpX == 0 && transpY == 1 ) /* We use Y transpose */
{
if ( colsX != colsY )
{
return EXIT_FAILURE;
}
for ( j = 0; j < rowsY; ++j )
{
for ( i = 0; i < rowsX; ++i )
{
( *Zp ) = 0.0f;
for ( k = 0; k < colsX; ++k )
{
( *Zp ) += X[i + k * rowsX] * Y[j + k * rowsY];
}
Zp++;
}
}
}
else if ( transpX == 1 && transpY == 1 ) /* We use both transpose */
{
if ( rowsX != colsY )
{
return EXIT_FAILURE;
}
for ( j = 0; j < rowsY; ++j )
{
for ( i = 0; i < colsX; ++i )
{
( *Zp ) = 0.0f;
for ( k = 0; k < colsX; ++k )
{
( *Zp ) += X[k + i * rowsX] * Y[j + k * rowsY];
}
Zp++;
}
}
}
else /* Regular case */
{
if ( colsX != rowsY )
{
return EXIT_FAILURE;
}
for ( j = 0; j < colsY; ++j )
{
for ( i = 0; i < rowsX; ++i )
{
( *Zp ) = 0.0f;
for ( k = 0; k < colsX; ++k )
{
( *Zp ) += X[i + k * rowsX] * Y[k + j * rowsY];
}
Zp++;
}
}
}
return EXIT_SUCCESS;
}
Word16 matrix_product_mant_exp_fx(
const Word32 *X_fx, /* i : left hand matrix Q31 - X_fx_e*/
const Word16 X_fx_e, /* i : left hand matrix */
......@@ -1992,60 +1515,6 @@ Word16 matrix_product_mant_exp(
}
/*---------------------------------------------------------------------*
* matrix_diag_product
*
* compute the product of a matrix with a diagonal of a matrix (Z=X*diag(Y))
*---------------------------------------------------------------------*/
/*! r: success or failure */
int16_t matrix_diag_product(
const float *X, /* i : left hand matrix */
const int16_t rowsX, /* i : number of rows of the left hand matrix */
const int16_t colsX, /* i : number of columns of the left hand matrix */
const int16_t transpX, /* i : flag indicating the transposition of the left hand matrix prior to the multiplication */
const float *Y, /* i : right hand diagonal matrix as vector containing the diagonal elements */
const int16_t entriesY, /* i : number of entries in the diagonal */
float *Z /* o : resulting matrix after the matrix multiplication */
)
{
int16_t i, j;
float *Zp = Z;
/* Processing */
if ( transpX == 1 ) /* We use X transpose */
{
if ( rowsX != entriesY )
{
return EXIT_FAILURE;
}
for ( j = 0; j < entriesY; ++j )
{
for ( i = 0; i < colsX; ++i )
{
*( Zp++ ) = X[j + i * rowsX] * Y[j];
}
}
}
else /* Regular case */
{
if ( colsX != entriesY )
{
return EXIT_FAILURE;
}
for ( j = 0; j < entriesY; ++j )
{
for ( i = 0; i < rowsX; ++i )
{
*( Zp++ ) = *( X++ ) * Y[j];
}
}
}
return EXIT_SUCCESS;
}
Word16 matrix_diag_product_fx(
const Word32 *X, /* i : left hand matrix Q31 - X_e*/
Word16 X_e,
......@@ -2227,60 +1696,6 @@ Word16 diag_matrix_product_fx(
return EXIT_SUCCESS;
}
/*---------------------------------------------------------------------*
* diag_matrix_product()
*
* compute the matrix product of a diagonal matrix X with a full matrix Y (Z=diag(Y)*X)
*---------------------------------------------------------------------*/
/*! r: success or failure */
int16_t diag_matrix_product(
const float *Y, /* i : left hand diagonal matrix as vector containing the diagonal elements */
const int16_t entriesY, /* i : length of the diagonal of the left hand matrix */
const float *X, /* i : right hand matrix */
const int16_t rowsX, /* i : number of rows of the right hand matrix */
const int16_t colsX, /* i : number of columns of the right hand matrix */
const int16_t transpX, /* i : flag indicating the transposition of the right hand matrix prior to the multiplication */
float *Z /* o : resulting matrix after the matrix multiplication */
)
{
int16_t i, j;
float *Zp = Z;
/* Processing */
if ( transpX == 1 ) /* We use X transpose */
{
if ( colsX != entriesY )
{
return EXIT_FAILURE;
}
for ( i = 0; i < rowsX; ++i )
{
for ( j = 0; j < entriesY; ++j )
{
*( Zp++ ) = X[i + j * rowsX] * Y[j];
}
}
}
else /* Regular case */
{
if ( rowsX != entriesY )
{
return EXIT_FAILURE;
}
for ( i = 0; i < colsX; ++i )
{
for ( j = 0; j < entriesY; ++j )
{
*( Zp++ ) = *( X++ ) * Y[j];
}
}
}
return EXIT_SUCCESS;
}
Word16 matrix_product_diag_fx(
const Word32 *X, /* i : left hand matrix Q31 - X_e*/
Word16 X_e,
......@@ -2401,96 +1816,6 @@ Word16 matrix_product_diag_fx(
* compute only the main diagonal of X*Y (Z=diag(X*Y))
*---------------------------------------------------------------------*/
/*! r: success or failure */
int16_t matrix_product_diag(
const float *X, /* i : left hand matrix */
const int16_t rowsX, /* i : number of rows of the left hand matrix */
const int16_t colsX, /* i : number of columns of the left hand matrix */
const int16_t transpX, /* i : flag indicating the transposition of the left hand matrix prior to the multiplication */
const float *Y, /* i : right hand matrix */
const int16_t rowsY, /* i : number of rows of the right hand matrix */
const int16_t colsY, /* i : number of columns of the right hand matrix */
const int16_t transpY, /* i : flag indicating the transposition of the right hand matrix prior to the multiplication */
float *Z /* o : resulting matrix after the matrix multiplication */
)
{
int16_t j, k;
float *Zp = Z;
/* Processing */
if ( transpX == 1 && transpY == 0 ) /* We use X transpose */
{
if ( rowsX != rowsY )
{
return EXIT_FAILURE;
}
for ( j = 0; j < colsY; ++j )
{
( *Zp ) = 0.0f;
for ( k = 0; k < rowsX; ++k )
{
( *Zp ) += X[k + j * rowsX] * Y[k + j * rowsY];
}
Zp++;
}
}
else if ( transpX == 0 && transpY == 1 ) /* We use Y transpose */
{
if ( colsX != colsY )
{
return EXIT_FAILURE;
}
for ( j = 0; j < rowsY; ++j )
{
( *Zp ) = 0.0f;
for ( k = 0; k < colsX; ++k )
{
( *Zp ) += X[j + k * rowsX] * Y[j + k * rowsY];
}
Zp++;
}
}
else if ( transpX == 1 && transpY == 1 ) /* We use both transpose */
{
if ( rowsX != colsY )
{
return EXIT_FAILURE;
}
for ( j = 0; j < rowsY; ++j )
{
( *Zp ) = 0.0f;
for ( k = 0; k < colsX; ++k )
{
( *Zp ) += X[k + j * rowsX] * Y[j + k * rowsY];
}
Zp++;
}
}
else /* Regular case */
{
if ( colsX != rowsY )
{
return EXIT_FAILURE;
}
for ( j = 0; j < colsY; ++j )
{
( *Zp ) = 0.0f;
for ( k = 0; k < colsX; ++k )
{
( *Zp ) += X[j + k * rowsX] * Y[k + j * rowsY];
}
Zp++;
}
}
return EXIT_SUCCESS;
}
void cmplx_matrix_square_fx(
const Word32 *realX, /* i : real part of the matrix Q31 - input_exp*/
const Word32 *imagX, /* i : imaginary part of the matrix Q31 - input_exp*/
......@@ -2560,87 +1885,6 @@ void cmplx_matrix_square_fx(
}
/*---------------------------------------------------------------------*
* cmplx_matrix_square()
*
* compute the square of a complex matrix (Z=X*X)
*---------------------------------------------------------------------*/
/*! r: success or failure */
void cmplx_matrix_square(
const float *realX, /* i : real part of the matrix */
const float *imagX, /* i : imaginary part of the matrix */
const int16_t mRows, /* i : number of rows of the matrix */
const int16_t nCols, /* i : number of columns of the matrix */
float *realZ, /* o : real part of the resulting matrix */
float *imagZ /* o : imaginary part of the resulting matrix */
)
{
int16_t i, j, k;
float *realZp, *imagZp;
const float *p_real1, *p_real2, *p_imag1, *p_imag2;
/* resulting matrix is hermitean, we only need to calc the upper triangle */
/* we assume transposition needed */
/* column*column = column/column */
for ( i = 0; i < nCols; i++ )
{
for ( j = i; j < nCols; j++ )
{
p_real1 = realX + i * mRows;
p_imag1 = imagX + i * mRows;
p_real2 = realX + j * mRows;
p_imag2 = imagX + j * mRows;
realZp = realZ + ( i + nCols * j );
imagZp = imagZ + ( i + nCols * j );
*( realZp ) = 0.0f;
*( imagZp ) = 0.0f;
for ( k = 0; k < mRows; k++ )
{
*( imagZp ) += *( p_real1 ) * ( *( p_imag2 ) ) - ( *( p_real2 ) ) * ( *( p_imag1 ) );
*( realZp ) += *( p_real1++ ) * ( *( p_real2++ ) ) + *( p_imag1++ ) * ( *( p_imag2++ ) );
}
}
}
/* fill lower triangle */
for ( i = 1; i < nCols; i++ )
{
for ( j = 0; j < i; j++ )
{
realZ[i + nCols * j] = realZ[j + nCols * i];
imagZ[i + nCols * j] = imagZ[j + nCols * i];
}
}
return;
}
/*-------------------------------------------------------------------*
* v_multc_acc()
*
* Multiplication of vector by constant, accumulate to the output
*-------------------------------------------------------------------*/
void v_multc_acc(
const float x[], /* i : Input vector */
const float c, /* i : Constant */
float y[], /* o : Output vector that contains y + c*x */
const int16_t N /* i : Vector length */
)
{
int16_t i;
for ( i = 0; i < N; i++ )
{
y[i] += c * x[i];
}
return;
}
void v_multc_acc_32_16(
const Word32 x[], /* i : Input vector Qx*/
const Word16 c, /* i : Constant Q31*/
......@@ -2685,51 +1929,6 @@ void v_multc_acc_32_32(
* the interpolated vector is return as x[], if requested
*---------------------------------------------------------------------*/
void lls_interp_n(
float x[], /* i/o: input/output vector */
const int16_t N, /* i : length of the input vector */
float *a, /* o : calculated slope */
float *b, /* o : calculated offset */
const int16_t upd /* i : use 1 to update x[] with the interpolated output */
)
{
int16_t i;
const float n_i[11] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
const float one_by_n[11] = { 0, 1, 0.5f, 0.333f, 0.25f, 0.2f, 0.1666f, 0.14286f, 0.125f, 0.111111f, 0.1f };
const float sum_i[12] = { 0, 0, 1, 3, 6, 10, 15, 21, 28, 36, 45, 55 };
const float sum_ii[12] = { 0, 0, 1, 5, 14, 30, 55, 91, 140, 204, 285, 385 };
float sum_x, sum_ix, slope, offset;
assert( N > 0 && N <= 10 );
sum_x = sum_f( x, N );
sum_ix = dotp( x, n_i, N );
slope = ( N * sum_ix - sum_i[N] * sum_x ) / ( N * sum_ii[N] - sum_i[N] * sum_i[N] );
offset = ( sum_x - slope * sum_i[N] ) * one_by_n[N];
if ( upd )
{
for ( i = 0; i < N; i++ )
{
x[i] = slope * i + offset;
}
}
if ( a != NULL )
{
*a = slope;
}
if ( b != NULL )
{
*b = offset;
}
return;
}
void lls_interp_n_fx(
Word16 x_fx[], /* i/o: input/output vector Q15*/
const Word16 N, /* i : length of the input vector Q0*/
......@@ -3032,44 +2231,6 @@ void panning_wrap_angles_fx(
}
}
/*-------------------------------------------------------------------------*
* v_sort_ind()
*
* Sort a float array
* (modified version of v_sort() to return an index array)
*-------------------------------------------------------------------------*/
void v_sort_ind(
float *x, /* i/o: Vector to be sorted */
int16_t *idx, /* o : Original index positions */
const int16_t len /* i : vector length */
)
{
int16_t i, j;
float tempr;
int16_t tempi;
for ( i = 0; i < len; i++ )
{
idx[i] = i;
}
for ( i = len - 2; i >= 0; i-- )
{
tempr = x[i];
tempi = idx[i];
for ( j = i + 1; ( j < len ) && ( tempr > x[j] ); j++ )
{
x[j - 1] = x[j];
idx[j - 1] = idx[j];
}
x[j - 1] = tempr;
idx[j - 1] = tempi;
}
return;
}
/*-------------------------------------------------------------------------*
* v_sort_ind_fixed()
*
......@@ -3204,23 +2365,6 @@ Word16 is_SIDrate(
* generate a random value with a triangular pdf in [-0.5, 0.5]
*-------------------------------------------------------------------*/
float rand_triangular_signed(
int16_t *seed )
{
float rand_val;
rand_val = own_random( seed ) * OUTMAX_INV;
if ( rand_val <= 0.0f )
{
/* rand_val in [-1, 0] */
return 0.5f * sqrtf( rand_val + 1.0f ) - 0.5f;
}
else
{
/* rand_val in (0, 1) */
return 0.5f - 0.5f * sqrtf( 1.0f - rand_val );
}
}
Word16 rand_triangular_signed_fx(
Word16 *seed, /*Q0*/
Word16 *exp_fac )
......