5050#include "bpfb.h"
5151#include "newamp1.h"
5252#include "lpcnet_freq.h"
53+ #include "sd.h"
5354
5455void synth_one_frame (int n_samp , codec2_fftr_cfg fftr_inv_cfg , short buf [], MODEL * model , float Sn_ [], float Pn [], int prede , float * de_mem , float gain );
5556void print_help (const struct option * long_options , int num_opts , char * argv []);
@@ -70,7 +71,7 @@ int main(int argc, char *argv[])
7071
7172 int lpc_model = 0 , order = LPC_ORD ;
7273 int lsp = 0 , lspd = 0 , lspvq = 0 ;
73- int lspjvm = 0 ;
74+ int lspjmv = 0 ;
7475 int prede = 0 ;
7576 int postfilt ;
7677 int hand_voicing = 0 , hi = 0 , simlpcpf = 0 , modelin = 0 , modelout = 0 ;
@@ -92,7 +93,7 @@ int main(int argc, char *argv[])
9293 FILE * fam = NULL , * fWo = NULL ;
9394 FILE * faw = NULL ;
9495 FILE * fhm = NULL ;
95- FILE * fjvm = NULL ;
96+ FILE * fjmv = NULL ;
9697 FILE * flspEWov = NULL ;
9798 FILE * ften_ms_centre = NULL ;
9899 FILE * fmodelout = NULL ;
@@ -133,7 +134,7 @@ int main(int argc, char *argv[])
133134 { "lsp" , no_argument , & lsp , 1 },
134135 { "lspd" , no_argument , & lspd , 1 },
135136 { "lspvq" , no_argument , & lspvq , 1 },
136- { "lspjvm " , no_argument , & lspjvm , 1 },
137+ { "lspjmv " , no_argument , & lspjmv , 1 },
137138 { "phase0" , no_argument , & phase0 , 1 },
138139 { "postfilter" , no_argument , & postfilt , 1 },
139140 { "hand_voicing" , required_argument , & hand_voicing , 1 },
@@ -282,7 +283,7 @@ int main(int argc, char *argv[])
282283 exit (1 );
283284 }
284285 } else if (strcmp (long_options [option_index ].name , "dump_pitch_e" ) == 0 ) {
285- if ((fjvm = fopen (optarg ,"wt" )) == NULL ) {
286+ if ((fjmv = fopen (optarg ,"wt" )) == NULL ) {
286287 fprintf (stderr , "Error opening pitch & energy dump file: %s: %s.\n" ,
287288 optarg , strerror (errno ));
288289 exit (1 );
@@ -399,7 +400,7 @@ int main(int argc, char *argv[])
399400 } else if (strcmp (optarg ,"1200" ) == 0 ) {
400401 lpc_model = 1 ;
401402 scalar_quant_Wo_e = 1 ;
402- lspjvm = 1 ;
403+ lspjmv = 1 ;
403404 phase0 = 1 ;
404405 postfilt = 1 ;
405406 decimate = 4 ;
@@ -497,7 +498,8 @@ int main(int argc, char *argv[])
497498 COMP Aw [FFT_ENC ];
498499 COMP H [MAX_AMP ];
499500
500-
501+ float sd_sum = 0.0 ; int sd_frames = 0 ;
502+
501503 for (i = 0 ; i < m_pitch ; i ++ ) {
502504 Sn [i ] = 1.0 ;
503505 Sn_pre [i ] = 1.0 ;
@@ -677,7 +679,7 @@ int main(int argc, char *argv[])
677679 #endif
678680
679681 if (dump_pitch_e )
680- fprintf (fjvm , "%f %f %d " , model .Wo , snr , model .voiced );
682+ fprintf (fjmv , "%f %f %d " , model .Wo , snr , model .voiced );
681683
682684 #ifdef DUMP
683685 dump_snr (snr );
@@ -701,6 +703,7 @@ int main(int argc, char *argv[])
701703 \*------------------------------------------------------------*/
702704
703705 if (lpc_model ) {
706+ float ak_ [LPC_ORD + 1 ];
704707
705708 e = speech_to_uq_lsps (lsps , ak , Sn , w , m_pitch , order );
706709 for (i = 0 ; i < order ; i ++ )
@@ -712,7 +715,7 @@ int main(int argc, char *argv[])
712715 #endif
713716
714717 if (dump_pitch_e )
715- fprintf (fjvm , "%f\n" , e );
718+ fprintf (fjmv , "%f\n" , e );
716719
717720 #ifdef DUMP
718721 dump_lsp (lsps );
@@ -724,26 +727,33 @@ int main(int argc, char *argv[])
724727 encode_lsps_scalar (lsp_indexes , lsps , LPC_ORD );
725728 decode_lsps_scalar (lsps_ , lsp_indexes , LPC_ORD );
726729 bw_expand_lsps (lsps_ , LPC_ORD , 50.0 , 100.0 );
727- lsp_to_lpc (lsps_ , ak , LPC_ORD );
730+ lsp_to_lpc (lsps_ , ak_ , LPC_ORD );
728731 }
729732
730733 if (lspd ) {
731734 encode_lspds_scalar (lsp_indexes , lsps , LPC_ORD );
732735 decode_lspds_scalar (lsps_ , lsp_indexes , LPC_ORD );
733- lsp_to_lpc (lsps_ , ak , LPC_ORD );
736+ lsp_to_lpc (lsps_ , ak_ , LPC_ORD );
734737 }
735738
736- if (lspjvm ) {
739+ if (lspjmv ) {
737740 /* Jean-Marc's multi-stage, split VQ */
738- lspjvm_quantise (lsps , lsps_ , LPC_ORD );
741+ lspjmv_quantise (lsps , lsps_ , LPC_ORD );
739742 {
740743 float lsps_bw [LPC_ORD ];
741744 memcpy (lsps_bw , lsps_ , sizeof (float )* order );
742745 bw_expand_lsps (lsps_bw , LPC_ORD , 50.0 , 100.0 );
743- lsp_to_lpc (lsps_bw , ak , LPC_ORD );
746+ lsp_to_lpc (lsps_bw , ak_ , LPC_ORD );
744747 }
745748 }
746749
750+ if (lsp || lspd || lspjmv ) {
751+ sd_sum += spectral_dist (ak , ak_ , LPC_ORD , fft_fwd_cfg , FFT_ENC );
752+ sd_frames ++ ;
753+ }
754+
755+ memcpy (ak , ak_ , (LPC_ORD + 1 )* sizeof (float ));
756+
747757 if (scalar_quant_Wo_e ) {
748758 e = decode_energy (encode_energy (e , E_BITS ), E_BITS );
749759 model .Wo = decode_Wo (& c2const , encode_Wo (& c2const , model .Wo , WO_BITS ), WO_BITS );
@@ -1068,7 +1078,9 @@ int main(int argc, char *argv[])
10681078 fclose (fout );
10691079
10701080 if (lpc_model ) {
1071- fprintf (stderr , "SNR av = %5.2f dB\n" , sum_snr /frames );
1081+ fprintf (stderr , "LPC->{Am} SNR av: %5.2f dB over %d frames\n" , sum_snr /frames , frames );
1082+ if (lsp || lspd || lspjmv )
1083+ fprintf (stderr , "LSP quantiser SD: %5.2f dB*dB over %d frames\n" , sd_sum /sd_frames , sd_frames );
10721084 }
10731085 if (newamp1vq ) {
10741086 fprintf (stderr , "var: %3.2f dB*dB\n" , se /nse );
@@ -1087,7 +1099,7 @@ int main(int argc, char *argv[])
10871099 if (fWo != NULL ) fclose (fWo );
10881100 if (faw != NULL ) fclose (faw );
10891101 if (fhm != NULL ) fclose (fhm );
1090- if (fjvm != NULL ) fclose (fjvm );
1102+ if (fjmv != NULL ) fclose (fjmv );
10911103 if (flspEWov != NULL ) fclose (flspEWov );
10921104 if (fphasenn != NULL ) fclose (fphasenn );
10931105 if (frateK != NULL ) fclose (frateK );
0 commit comments