Loading lib_com/options.h +2 −1 Original line number Diff line number Diff line Loading @@ -174,7 +174,8 @@ #define HR_METADATA /* Nok: encode directional MASA metadata with more bits at 384k and 512k */ #define ERI_SNSVQ_ROMOPT /* BASOP ROM OPT store added SNS VQ stage 1 tables in DCT16 domain, as for FDCNGVQ stage 1 */ //#define ERI_SNSVQ_ROMOPT /* BASOP ROM OPT store added SNS VQ stage 1 tables in DCT16 domain, as for FDCNGVQ stage 1 */ #define SNS_MSVQ_DEBUG /* measure SD */ /* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */ Loading lib_debug/snr.c +192 −1 Original line number Diff line number Diff line Loading @@ -79,6 +79,16 @@ static float mem_deemph_y[MAX_INPUT_CHANNELS] = { 0 }; static float mem_synth_snr[MAX_INPUT_CHANNELS][M]; #ifdef SNS_MSVQ_DEBUG #define N_PCT ( 5 ) static double pctlims[N_PCT] = { 1.0, 1.5, 2.0, 3.0, 4.0 }; /* dB limits*/ static int32_t acc_sd_out_pct[N_PCT][N_SNRPTR]; /*0 -> 4dB */ static double acc_sd[N_SNRPTR]; static double wc_sd[N_SNRPTR]; static int32_t wc_sd_frame[N_SNRPTR]; #endif /*-------------------------------------------------------------------* * Local functions - they are copies of functions declared in prot.h but here we do not want to include prot.h due to its dependencies Loading Loading @@ -230,7 +240,138 @@ static void weight_a( * certain string. The signal is input in segments having certain length, * for which a global SNR, segmental SNR and weighted segmental SNR is computed. *--------------------------------------------------------------------*/ #ifdef SNS_MSVQ_DEBUG void snr( const float *const signal, const float *const noise, const int16_t length, const char *const name ) { int16_t index, i; double signal_sumsq, noise_sumsq, frame_snr, seg_en; double noise_lin[MAX_SIGNAL_LENGTH]; double noise_dB[MAX_SIGNAL_LENGTH]; double noise_sumsq_sd; index = lookup( name, (const char *const *) snr_name, snr_count ); if ( index == -1 ) { index = snr_count; signal_energy[index] = 0; noise_energy[index] = 0; acc_seg_snr[index] = 0; seg_count[index] = 0; acc_wseg_snr[index] = 0; wseg_count[index] = 0; snr_name[index] = malloc( sizeof( char ) * ( strlen( name ) + 1 ) ); strcpy( snr_name[index], name ); snr_count++; if ( strncmp( "SD", name, 2 ) == 0 ) { /* reset distribution of outliers stats */ acc_sd[index] = 0.0; for ( i = 0; i < N_PCT; i++ ) { acc_sd_out_pct[i][index] = 0; } wc_sd[index] = 0; wc_sd_frame[index] = -1; ; } } signal_sumsq = sum2_f( signal, length ) + 0.001f; noise_sumsq = sum2_f( noise, length ) + 0.001f; if ( signal_sumsq < noise_sumsq ) signal_sumsq = noise_sumsq; frame_snr = 10 * log10( signal_sumsq / noise_sumsq ); seg_en = 10 * log10( signal_sumsq / length ); if ( seg_en < 0.0 ) seg_en = 0.0; signal_energy[index] += signal_sumsq; noise_energy[index] += noise_sumsq; acc_seg_snr[index] += frame_snr; seg_count[index]++; acc_wseg_snr[index] += frame_snr * seg_en; wseg_count[index] += seg_en; if ( strncmp( "SD", name, 2 ) == 0 ) { double sd, base; base = 0.0; /* assume linear domain input noise values */ if ( strncmp( "SD2", name, 3 ) == 0 ) { base = 2.0; /* assuming log2 domain input deltanoise values*/ } if ( strncmp( "SD10", name, 4 ) == 0 ) { base = 10.0; /* assuming log10 domain input deltanoise values*/ } noise_sumsq_sd = 0.0001; if ( base != 0.0 ) { if ( base == 10.0 ) { /* assume log10 has been applied already */ /* convert to log10(x) to 10*log10(x) */ for ( i = 0; i < length; i++ ) { noise_lin[i] = (double) noise[i]; /* dB ratio */ noise_dB[i] = 10.0 * ( noise_lin[i] ); noise_sumsq_sd += noise_dB[i] * noise_dB[i]; /* SD summed up in 10log10 domain */ } } else { /* assume log2 has been applied already */ /* convert to log2(x) to 10*log10(x) */ for ( i = 0; i < length; i++ ) { noise_lin[i] = (double) noise[i]; /*dB ratio */ noise_dB[i] = 3.010299956639812 * ( noise_lin[i] ); noise_sumsq_sd += noise_dB[i] * noise_dB[i]; /* SD summed up in 10log10 domain */ } } } else { /* ,assume noise is already in 10log10() domain , i.e a dB(in log10) difference */ for ( i = 0; i < length; i++ ) { noise_lin[i] = (double) noise[i]; noise_dB[i] = ( noise_lin[i] ); noise_sumsq_sd += noise_dB[i] * noise_dB[i]; /* SD summed up in 10log10 domain */ } } /* measure SD(RMS noise energy in 10log10 dB) stats , useful for a spectral parameters already in a log domain */ /* RMS over full band , 100 = 10^2 in sqrt(1/N *sum( [10log10( P/P*)]^2, full band), P is input power spectra, P* is distored power spectra */ sd = (double) sqrt( ( noise_sumsq_sd ) / (double) length ); /* RMS calc for SD */ acc_sd[index] += sd; for ( i = 0; i < N_PCT; i++ ) { if ( sd > pctlims[i] ) { acc_sd_out_pct[i][index]++; } } if ( sd > wc_sd[index] ) { wc_sd[index] = sd; #ifdef DEBUGGING wc_sd_frame[index] = frame; #endif } } return; } #else void snr( const float *const signal, const float *const noise, Loading Loading @@ -273,7 +414,7 @@ void snr( return; } #endif /*-------------------------------------------------------------------* * snr_diff() Loading Loading @@ -425,8 +566,14 @@ void snr_celp( void print_snr() { #ifdef SNS_MSVQ_DEBUG int16_t i, j; double snr, segsnr, wsegsnr; double tot_sd, tot_out_pct[N_PCT]; #else int16_t i; double snr, segsnr, wsegsnr; #endif if ( snr_count > 0 ) { Loading @@ -434,10 +581,54 @@ void print_snr() for ( i = 0; i < snr_count; i++ ) { #ifdef SNS_MSVQ_DEBUG if ( ( seg_count[i] > 0 ) && ( strncmp( "SD", snr_name[i], 2 ) == 0 ) ) { tot_sd = acc_sd[i] / seg_count[i]; for ( j = 0; j < N_PCT; j++ ) { tot_out_pct[j] = (double) acc_sd_out_pct[j][i] / (double) seg_count[i] * 100.0; } } else { tot_sd = 0.0; for ( j = 0; j < N_PCT; j++ ) { tot_out_pct[j] = 0.0; } } snr = 10 * log10( signal_energy[i] / ( noise_energy[i] + 0.0001f ) ); segsnr = acc_seg_snr[i] / ( seg_count[i] + 0.0001f ); wsegsnr = acc_wseg_snr[i] / ( wseg_count[i] + 0.0001f ); if ( strncmp( "SD", snr_name[i], 2 ) == 0 ) { double secs_all, secs, mins; /* SD = noise energy statistics assuming SNR input is in a dB domain : 10log10 , log10 or log2 */ fprintf( stdout, "%-31s, %6.3f dB(SegSnr), %5.3f dB(Ave.SD), SD-outl:", snr_name[i], segsnr, tot_sd ); for ( j = 0; j < N_PCT; j++ ) { fprintf( stdout, ",(>%2.1fdB:%.1f%%)", pctlims[j], tot_out_pct[j] ); } secs_all = (double) wc_sd_frame[i] / 50.0; mins = floor( secs_all / 60.0 ); secs = secs_all - 60.0 * mins; fprintf( stdout, ", (SD-wc: %5.3f frame=%d %dm:%.2fs)", wc_sd[i], wc_sd_frame[i], (int) mins, secs ); fprintf( stdout, ", cnt:%d \n", seg_count[i] ); } else { fprintf( stdout, "%-31s %6.3f dB SNR %6.3f dB SegSNR %6.3f dB WSegSNR\n", snr_name[i], snr, segsnr, wsegsnr ); } #else snr = 10 * log10( signal_energy[i] / ( noise_energy[i] + 0.0001f ) ); segsnr = acc_seg_snr[i] / ( seg_count[i] + 0.0001f ); wsegsnr = acc_wseg_snr[i] / ( wseg_count[i] + 0.0001f ); fprintf( stdout, "%-22s %6.3f dB SNR %6.3f dB SegSNR %6.3f dB WSegSNR\n", snr_name[i], snr, segsnr, wsegsnr ); #endif } fprintf( stdout, "\n" ); } Loading lib_enc/ivas_sns_enc.c +26 −0 Original line number Diff line number Diff line Loading @@ -504,6 +504,32 @@ int16_t quantize_sns( msvq_dec( cdbks, NULL, NULL, nStages, M, M, &indices[idxIndices], 0, NULL, snsQ, NULL ); #endif #ifdef SNS_MSVQ_DEBUG { char vq_name[1024]; char v[1024]; int16_t nC; /* nCandidates */ int16_t tcx = 10; if ( nSubframes == 1) { tcx = 20; } #ifdef ERI_SNSVQ_ROMOPT sprintf( v, "ERI_Tcx%d",tcx ); nC = 3; #else sprintf( v, "BSL_Tcx%d", tcx ); nC = 3; #endif if ( sns_stereo_mode[ch] == 0) { sprintf( vq_name, "SD2_%s_Mid_Ch%dsub%dSt%dnC%d", v, ch, k, nStages,nC ); } else { sprintf( vq_name, "SD2_%s_LR_Ch%dsub%dSt%dnC%d", v, ch, k, nStages,nC ); } snr_diff( sns_ptr, snsQ, M, 0, vq_name ); } #endif } idxIndices += nStages; Loading Loading
lib_com/options.h +2 −1 Original line number Diff line number Diff line Loading @@ -174,7 +174,8 @@ #define HR_METADATA /* Nok: encode directional MASA metadata with more bits at 384k and 512k */ #define ERI_SNSVQ_ROMOPT /* BASOP ROM OPT store added SNS VQ stage 1 tables in DCT16 domain, as for FDCNGVQ stage 1 */ //#define ERI_SNSVQ_ROMOPT /* BASOP ROM OPT store added SNS VQ stage 1 tables in DCT16 domain, as for FDCNGVQ stage 1 */ #define SNS_MSVQ_DEBUG /* measure SD */ /* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */ Loading
lib_debug/snr.c +192 −1 Original line number Diff line number Diff line Loading @@ -79,6 +79,16 @@ static float mem_deemph_y[MAX_INPUT_CHANNELS] = { 0 }; static float mem_synth_snr[MAX_INPUT_CHANNELS][M]; #ifdef SNS_MSVQ_DEBUG #define N_PCT ( 5 ) static double pctlims[N_PCT] = { 1.0, 1.5, 2.0, 3.0, 4.0 }; /* dB limits*/ static int32_t acc_sd_out_pct[N_PCT][N_SNRPTR]; /*0 -> 4dB */ static double acc_sd[N_SNRPTR]; static double wc_sd[N_SNRPTR]; static int32_t wc_sd_frame[N_SNRPTR]; #endif /*-------------------------------------------------------------------* * Local functions - they are copies of functions declared in prot.h but here we do not want to include prot.h due to its dependencies Loading Loading @@ -230,7 +240,138 @@ static void weight_a( * certain string. The signal is input in segments having certain length, * for which a global SNR, segmental SNR and weighted segmental SNR is computed. *--------------------------------------------------------------------*/ #ifdef SNS_MSVQ_DEBUG void snr( const float *const signal, const float *const noise, const int16_t length, const char *const name ) { int16_t index, i; double signal_sumsq, noise_sumsq, frame_snr, seg_en; double noise_lin[MAX_SIGNAL_LENGTH]; double noise_dB[MAX_SIGNAL_LENGTH]; double noise_sumsq_sd; index = lookup( name, (const char *const *) snr_name, snr_count ); if ( index == -1 ) { index = snr_count; signal_energy[index] = 0; noise_energy[index] = 0; acc_seg_snr[index] = 0; seg_count[index] = 0; acc_wseg_snr[index] = 0; wseg_count[index] = 0; snr_name[index] = malloc( sizeof( char ) * ( strlen( name ) + 1 ) ); strcpy( snr_name[index], name ); snr_count++; if ( strncmp( "SD", name, 2 ) == 0 ) { /* reset distribution of outliers stats */ acc_sd[index] = 0.0; for ( i = 0; i < N_PCT; i++ ) { acc_sd_out_pct[i][index] = 0; } wc_sd[index] = 0; wc_sd_frame[index] = -1; ; } } signal_sumsq = sum2_f( signal, length ) + 0.001f; noise_sumsq = sum2_f( noise, length ) + 0.001f; if ( signal_sumsq < noise_sumsq ) signal_sumsq = noise_sumsq; frame_snr = 10 * log10( signal_sumsq / noise_sumsq ); seg_en = 10 * log10( signal_sumsq / length ); if ( seg_en < 0.0 ) seg_en = 0.0; signal_energy[index] += signal_sumsq; noise_energy[index] += noise_sumsq; acc_seg_snr[index] += frame_snr; seg_count[index]++; acc_wseg_snr[index] += frame_snr * seg_en; wseg_count[index] += seg_en; if ( strncmp( "SD", name, 2 ) == 0 ) { double sd, base; base = 0.0; /* assume linear domain input noise values */ if ( strncmp( "SD2", name, 3 ) == 0 ) { base = 2.0; /* assuming log2 domain input deltanoise values*/ } if ( strncmp( "SD10", name, 4 ) == 0 ) { base = 10.0; /* assuming log10 domain input deltanoise values*/ } noise_sumsq_sd = 0.0001; if ( base != 0.0 ) { if ( base == 10.0 ) { /* assume log10 has been applied already */ /* convert to log10(x) to 10*log10(x) */ for ( i = 0; i < length; i++ ) { noise_lin[i] = (double) noise[i]; /* dB ratio */ noise_dB[i] = 10.0 * ( noise_lin[i] ); noise_sumsq_sd += noise_dB[i] * noise_dB[i]; /* SD summed up in 10log10 domain */ } } else { /* assume log2 has been applied already */ /* convert to log2(x) to 10*log10(x) */ for ( i = 0; i < length; i++ ) { noise_lin[i] = (double) noise[i]; /*dB ratio */ noise_dB[i] = 3.010299956639812 * ( noise_lin[i] ); noise_sumsq_sd += noise_dB[i] * noise_dB[i]; /* SD summed up in 10log10 domain */ } } } else { /* ,assume noise is already in 10log10() domain , i.e a dB(in log10) difference */ for ( i = 0; i < length; i++ ) { noise_lin[i] = (double) noise[i]; noise_dB[i] = ( noise_lin[i] ); noise_sumsq_sd += noise_dB[i] * noise_dB[i]; /* SD summed up in 10log10 domain */ } } /* measure SD(RMS noise energy in 10log10 dB) stats , useful for a spectral parameters already in a log domain */ /* RMS over full band , 100 = 10^2 in sqrt(1/N *sum( [10log10( P/P*)]^2, full band), P is input power spectra, P* is distored power spectra */ sd = (double) sqrt( ( noise_sumsq_sd ) / (double) length ); /* RMS calc for SD */ acc_sd[index] += sd; for ( i = 0; i < N_PCT; i++ ) { if ( sd > pctlims[i] ) { acc_sd_out_pct[i][index]++; } } if ( sd > wc_sd[index] ) { wc_sd[index] = sd; #ifdef DEBUGGING wc_sd_frame[index] = frame; #endif } } return; } #else void snr( const float *const signal, const float *const noise, Loading Loading @@ -273,7 +414,7 @@ void snr( return; } #endif /*-------------------------------------------------------------------* * snr_diff() Loading Loading @@ -425,8 +566,14 @@ void snr_celp( void print_snr() { #ifdef SNS_MSVQ_DEBUG int16_t i, j; double snr, segsnr, wsegsnr; double tot_sd, tot_out_pct[N_PCT]; #else int16_t i; double snr, segsnr, wsegsnr; #endif if ( snr_count > 0 ) { Loading @@ -434,10 +581,54 @@ void print_snr() for ( i = 0; i < snr_count; i++ ) { #ifdef SNS_MSVQ_DEBUG if ( ( seg_count[i] > 0 ) && ( strncmp( "SD", snr_name[i], 2 ) == 0 ) ) { tot_sd = acc_sd[i] / seg_count[i]; for ( j = 0; j < N_PCT; j++ ) { tot_out_pct[j] = (double) acc_sd_out_pct[j][i] / (double) seg_count[i] * 100.0; } } else { tot_sd = 0.0; for ( j = 0; j < N_PCT; j++ ) { tot_out_pct[j] = 0.0; } } snr = 10 * log10( signal_energy[i] / ( noise_energy[i] + 0.0001f ) ); segsnr = acc_seg_snr[i] / ( seg_count[i] + 0.0001f ); wsegsnr = acc_wseg_snr[i] / ( wseg_count[i] + 0.0001f ); if ( strncmp( "SD", snr_name[i], 2 ) == 0 ) { double secs_all, secs, mins; /* SD = noise energy statistics assuming SNR input is in a dB domain : 10log10 , log10 or log2 */ fprintf( stdout, "%-31s, %6.3f dB(SegSnr), %5.3f dB(Ave.SD), SD-outl:", snr_name[i], segsnr, tot_sd ); for ( j = 0; j < N_PCT; j++ ) { fprintf( stdout, ",(>%2.1fdB:%.1f%%)", pctlims[j], tot_out_pct[j] ); } secs_all = (double) wc_sd_frame[i] / 50.0; mins = floor( secs_all / 60.0 ); secs = secs_all - 60.0 * mins; fprintf( stdout, ", (SD-wc: %5.3f frame=%d %dm:%.2fs)", wc_sd[i], wc_sd_frame[i], (int) mins, secs ); fprintf( stdout, ", cnt:%d \n", seg_count[i] ); } else { fprintf( stdout, "%-31s %6.3f dB SNR %6.3f dB SegSNR %6.3f dB WSegSNR\n", snr_name[i], snr, segsnr, wsegsnr ); } #else snr = 10 * log10( signal_energy[i] / ( noise_energy[i] + 0.0001f ) ); segsnr = acc_seg_snr[i] / ( seg_count[i] + 0.0001f ); wsegsnr = acc_wseg_snr[i] / ( wseg_count[i] + 0.0001f ); fprintf( stdout, "%-22s %6.3f dB SNR %6.3f dB SegSNR %6.3f dB WSegSNR\n", snr_name[i], snr, segsnr, wsegsnr ); #endif } fprintf( stdout, "\n" ); } Loading
lib_enc/ivas_sns_enc.c +26 −0 Original line number Diff line number Diff line Loading @@ -504,6 +504,32 @@ int16_t quantize_sns( msvq_dec( cdbks, NULL, NULL, nStages, M, M, &indices[idxIndices], 0, NULL, snsQ, NULL ); #endif #ifdef SNS_MSVQ_DEBUG { char vq_name[1024]; char v[1024]; int16_t nC; /* nCandidates */ int16_t tcx = 10; if ( nSubframes == 1) { tcx = 20; } #ifdef ERI_SNSVQ_ROMOPT sprintf( v, "ERI_Tcx%d",tcx ); nC = 3; #else sprintf( v, "BSL_Tcx%d", tcx ); nC = 3; #endif if ( sns_stereo_mode[ch] == 0) { sprintf( vq_name, "SD2_%s_Mid_Ch%dsub%dSt%dnC%d", v, ch, k, nStages,nC ); } else { sprintf( vq_name, "SD2_%s_LR_Ch%dsub%dSt%dnC%d", v, ch, k, nStages,nC ); } snr_diff( sns_ptr, snsQ, M, 0, vq_name ); } #endif } idxIndices += nStages; Loading