Commit e066ce10 authored by advasila's avatar advasila
Browse files

add SD measure for re-use mode

parent d5d52208
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -756,6 +756,9 @@ int main(

#ifdef DEBUGGING
    print_snr();
#ifdef SECONDARY_LSF_RE_USE_LSF_SD_INFO
	print_sd();
#endif
#endif

    /*------------------------------------------------------------------------------------------*
+1 −0
Original line number Diff line number Diff line
@@ -139,6 +139,7 @@
#ifdef LSF_RE_USE_SECONDARY_CHANNEL
/*#define LSF_RE_USE_SECONDARY_CHANNEL_REUSEMODE */     /* switch to isolate the reuse mode case */
#endif
#define SECONDARY_LSF_RE_USE_LSF_SD_INFO                /* measure SD for secondary re-use case */
#define DISABLE_ADAP_RES_COD_TMP                        /* temporary fix for IVAS-403, disables adaptive residual coding */
/*#define ITD_WINNER_GAIN_MODIFY */                     /* ITD optimization - WORK IN PROGRESS */

+11 −0
Original line number Diff line number Diff line
@@ -204,6 +204,17 @@ void print_snr( void );

#ifdef DEBUGGING

#ifdef SECONDARY_LSF_RE_USE_LSF_SD_INFO 
float sd(
	const float lsf[],       /* i  : vector of unquantized LSF values   */
	const float lsf_q[],     /* i  : vector of quantized LSF values     */
	const int16_t order,     /* i  : dimension of the vectors           */
	const int32_t fs,        /* i  : sampling frequency                 */
	const float min_freq,    /* i  : minimum frequency of interest      */
	const float max_freq    /* i  : maximum frequency of interest      */
);
#endif

/*! r: SD in a given frequency range */
float sd_range(
    const float lsf[],       /* i  : vector of unquantized LSF values   */

lib_debug/sd.c

0 → 100644
+213 −0
Original line number Diff line number Diff line
/*************************************************************************

       (C) Copyright Ericsson, Fraunhofer, Huawei, Nokia,
                     Qualcomm, VoiceAge

                       (2019) All Rights Reserved

This software and/or program is protected by copyright law and
international treaties. Any reproduction or distribution of this
software and/or program, or any portion of it, may result in severe
civil and criminal penalties, and will be prosecuted to the maximum
extent possible under law. No part of this material may be stored in a
retrieval system, or transmitted, in any form or by any means:
photocopying, electronic, mechanical, recording, or otherwise, without
the prior written permission of the copyright holder.

**************************************************************************/

/*====================================================================================
    EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0
  ====================================================================================*/

#include <math.h>
#include <stdlib.h>
#include <stdint.h>
#include "options.h"           
#ifdef DEBUGGING
#include "debug.h"             
#endif
#include "wmops.h"
#include "cnst.h"       
#include "prot.h"           
#include "rom_com.h"      
#include <string.h>

#ifdef DEBUGGING

/*-------------------------------------------------------------------*
 * Local constants
 *--------------------------------------------------------------------*/

#define ORDER_MAX               16     /* maximum order of LSF vectors */
#define N_SPEC_SD               256    /* number of spectral points */




/*-------------------------------------------------------------------*
 * Local variables
 *--------------------------------------------------------------------*/

static float cum_sd;
static int32_t cum_sd_count = 0;

/*-------------------------------------------------------------------*
 * Local functions
 *--------------------------------------------------------------------*/

static void az(float r[], float rr[], int l, short order);

/*-------------------------------------------------------------------*
 * Global functions
 *--------------------------------------------------------------------*/

float sd(                   /* o  : SD in a given frequency range      */
    const float lsf[],      /* i  : vector of unquantized LSF values   */
    const float lsf_q[],    /* i  : vector of quantized LSF values     */
    const short order,      /* i  : dimension of the vectors           */
    const int32_t  fs,      /* i  : sampling frequency                 */
    const float min_freq,   /* i  : minimum frequency of interest      */
    const float max_freq   /* i  : maximum frequency of interest      */ 
)
{
    float a[ORDER_MAX+1], q_a[ORDER_MAX+1], lsp[ORDER_MAX], q_lsp[ORDER_MAX];
    float spectrum1[N_SPEC_SD/2+1], spectrum2[N_SPEC_SD/2+1];
    float sd, tmp, f_res;
    int16_t   i,  cnt_sd, i_low, i_high;


    f_res = fs / (float)N_SPEC_SD;                                                


    lsf2lsp( lsf, lsp, order, fs );
    lsf2lsp( lsf_q, q_lsp, order, fs);

    lsp2a_stab( lsp, a, order );                                                     
    lsp2a_stab( q_lsp, q_a, order );
    
	/*  log spectra of A(z) and Aq(z)  */
    az(a, spectrum1, N_SPEC_SD, order);                                                
    az(q_a, spectrum2, N_SPEC_SD, order);                                               

/*----------------------------------------------------------------------------------*
 * Localize the input frequency limits 
 *----------------------------------------------------------------------------------*/
  
    i_low  = (int16_t)ceil(min_freq / f_res);
    i_high = (int16_t)floor(max_freq / f_res);


	/* do not consider the mean, nor the N_SPEC_SD/2-1   */
	if (i_low == 0)
	{
		i_low = 1;                                                 
	}
	if (i_high >= N_SPEC_SD / 2)
	{
		i_high = N_SPEC_SD / 2 - 1;                        
	}

   /* calculate the mean SD over the specified range */

    sd = 0.0f;
    cnt_sd = 0;
    for (i = i_low; i <= i_high; i++) {
        tmp = spectrum1[i] - spectrum2[i];
        sd += tmp * tmp;
        cnt_sd++;
    }

    sd = (float)sqrt( sd  * 100.0 / (float)cnt_sd  );

	cum_sd += sd;
	cum_sd_count++;
    return sd;
}




/*---------------------------------------------------------------------*
 * az()
 *                                                                    
 * To find the amplitude spectrum of A(z) = 1 + a1*z^-1 + a2*z^-2 + ... + ap*z^-p 
 * the evaluated values are those of log|A(w)|^2 at w= 2pi*k/N_SPEC_SD  k=0,...,N_SPEC_SD-1
 *---------------------------------------------------------------------*/

static void az(
    float r[],                          /* i:   original vector a[i]                */
    float rr[],                         /* o:   vector of spectral values           */
    int l,                              /* i:   number of points for DFT            */
    short order                         /* i:   dimension of vectors                */
)
{
    int k, n, ind;
    static double tcos[N_SPEC_SD], tsin[N_SPEC_SD];
    static int ifirst=0;
    static float pi2byl;
    double s1, s2;

    if (ifirst == 0)
    {
        ifirst = 1;
        pi2byl = PI2/((float) l);
        for (k = 0; k < l; k++)
        {
            tcos[k] = cos(pi2byl*k);
            tsin[k] = sin(pi2byl*k);
        }
    }

    for (n = 0; n <= l/2; n++)
    {
        s1 = 0.0;
        s2 = 0.0;
        ind = 0;
        for (k = 0; k <= order; k++)
        {
            s1 += r[k]*tcos[ind];
            s2 += r[k]*tsin[ind];
            ind += n;
            if (ind >= l) ind -= l;
        }
        s1 = s1*s1 + s2*s2;

        if (s1 < 0.00001)  s1 = 0.00001f;
        rr[n] = (float)log10(s1);
    }

    rr[0] -= (float)log10(2.0);
    if (l%2 == 0) rr[l/2] -= (float)log10(2.0);

    return;
}


/*-------------------------------------------------------------------*
 * print_sd
 *
 * Finalizes and presents the accumulated SD analysis data
 *--------------------------------------------------------------------*/

void print_sd()
{
    float av_sd;

    if ( cum_sd_count > 0 )
    {
        fprintf(stdout,"\n\n --- SD report ---  \n");
        av_sd = cum_sd / cum_sd_count;
          
        fprintf(stdout,"Average SD:  %.3f dB, count: %d\n", av_sd, cum_sd_count);
		fprintf(stdout, "\n\n ");
        
    }


}




#endif
+25 −1
Original line number Diff line number Diff line
@@ -120,7 +120,9 @@ ivas_error acelp_core_enc(

    /* bitstream */
    BSTR_ENC_HANDLE hBstr = st->hBstr;

#ifdef SECONDARY_LSF_RE_USE_LSF_SD_INFO
	float lsf_secondary_org[M];
#endif
    ivas_error error;

    error = IVAS_ERR_OK;
@@ -404,6 +406,9 @@ ivas_error acelp_core_enc(

        /* SC-VBR & channel-aware mode - back-up memories for LSF quantizer and synthesis filter */
        lsf_syn_mem_backup( st, &tilt_code_bck, &gc_threshold_bck, clip_var_bck, &next_force_sf_bck, lsp_new, lsp_mid, &clip_var, mem_AR, mem_MA, lsp_new_bck, lsp_mid_bck, Bin_E, Bin_E_old, mem_syn_bck, &mem_w0_bck, &streaklimit, &pstreaklen );
#ifdef SECONDARY_LSF_RE_USE_LSF_SD_INFO
		lsp2lsf(lsp_new, lsf_secondary_org, M, 12800);
#endif

        if ( !tdm_lp_reuse_flag )
        {
@@ -444,6 +449,25 @@ ivas_error acelp_core_enc(
                mvr2r( tdm_lsfQ_PCh, lsf_new, M );
            }
#endif
#ifdef SECONDARY_LSF_RE_USE_LSF_SD_INFO
			{
				float SD;
				/*float BWSD; */

				if (st->idchan == 0) {
					printf("st->idchan=%hd\n", st->idchan);
					exit(0);
				}

				if (st->vad_flag == 1) {
					SD = sd(lsf_secondary_org, lsf_new, M, 12800, 0.0, 6400.0);
					dbgwrite(&SD, sizeof(float), 1, 1, "SD_reuse_chan_1.dbg");

				}

			}
#endif

            pt_interp_2 = interpol_frac_12k8;
            if ( tdm_low_rate_mode == 1 && st->coder_type > UNVOICED )
            {