Skip to content

Commit e181e31

Browse files
committed
SD calculation working in SD
1 parent 9528119 commit e181e31

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

src/c2sim.c

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
#include "bpfb.h"
5151
#include "newamp1.h"
5252
#include "lpcnet_freq.h"
53+
#include "sd.h"
5354

5455
void 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);
5556
void print_help(const struct option *long_options, int num_opts, char* argv[]);
@@ -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;
@@ -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++)
@@ -724,13 +727,13 @@ 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

736739
if (lspjvm) {
@@ -740,10 +743,17 @@ int main(int argc, char *argv[])
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 || lspjvm) {
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\n", sum_snr/frames);
1082+
if (lsp || lspd || lspjvm)
1083+
fprintf(stderr, "LSP quantiser SD: %5.2f dB*dB\n", sd_sum/sd_frames);
10721084
}
10731085
if (newamp1vq) {
10741086
fprintf(stderr, "var: %3.2f dB*dB\n", se/nse);

0 commit comments

Comments
 (0)