Skip to content

Commit df0ac65

Browse files
authored
Merge pull request drowe67#285 from drowe67/dr-sinusoidal
Sinusoidal model scripts maintenance
2 parents 7d6ef52 + 7644be1 commit df0ac65

24 files changed

+100
-8190
lines changed

octave/plamp.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ function plamp(samname, f, samname2)
8282
clf;
8383
s = [ Sn(2*f-1,:) Sn(2*f,:) ];
8484
plot(s,'b');
85-
if (file_in_path(".",model2_name))
85+
if (nargin == 3)
8686
s2 = [ Sn2(2*f-1,:) Sn2(2*f,:) ];
8787
hold on; plot(s2,'r'); hold off;
8888
end
@@ -97,7 +97,7 @@ function plamp(samname, f, samname2)
9797
hold on;
9898
if plot_sw; plot((0:255)*4000/256, Sw(f,:),";Sw;b"); end
9999

100-
if (file_in_path(".",model2_name))
100+
if (nargin == 3)
101101
Wo2 = model2(f,1);
102102
L2 = model2(f,2);
103103
Am2 = model2(f,3:(L2+2));

src/CMakeLists.txt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ set(CODEBOOKSD
3333
)
3434

3535
# LSP VQ (1200 mode)
36-
set(CODEBOOKSJVM
37-
${D}/lspjvm1.txt
38-
${D}/lspjvm2.txt
39-
${D}/lspjvm3.txt
36+
set(CODEBOOKSJMV
37+
${D}/lspjmv1.txt
38+
${D}/lspjmv2.txt
39+
${D}/lspjmv3.txt
4040
)
4141

4242
# Joint Wo-energy VQ (1200 mode)
@@ -102,11 +102,11 @@ add_custom_command(
102102
DEPENDS generate_codebook ${CODEBOOKSD}
103103
)
104104

105-
# codebookjvm.c
105+
# codebookjmv.c
106106
add_custom_command(
107-
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/codebookjvm.c
108-
COMMAND generate_codebook lsp_cbjvm ${CODEBOOKSJVM} > ${CMAKE_CURRENT_BINARY_DIR}/codebookjvm.c
109-
DEPENDS generate_codebook ${CODEBOOKSJVM}
107+
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/codebookjmv.c
108+
COMMAND generate_codebook lsp_cbjmv ${CODEBOOKSJMV} > ${CMAKE_CURRENT_BINARY_DIR}/codebookjmv.c
109+
DEPENDS generate_codebook ${CODEBOOKSJMV}
110110
)
111111

112112
# codebookge.c
@@ -177,7 +177,7 @@ set(CODEC2_SRCS
177177
pack.c
178178
codebook.c
179179
codebookd.c
180-
codebookjvm.c
180+
codebookjmv.c
181181
codebookge.c
182182
codebooknewamp1.c
183183
codebooknewamp1_energy.c

src/c2sim.c

Lines changed: 27 additions & 15 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[]);
@@ -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);

src/ch.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
AUTHOR......: David Rowe
55
DATE CREATED: May 2015
66
7-
Channel impairment program for testing command line versions of modems.
7+
Channel simulation program for testing command line versions of modems.
88
99
\*---------------------------------------------------------------------------*/
1010

@@ -92,15 +92,17 @@ int main(int argc, char *argv[])
9292

9393
if (argc < 3) {
9494
helpmsg:
95-
fprintf(stderr, "usage: %s InputRealModemRawFile OutputRealModemRawFile [Options]\n"
95+
fprintf(stderr, "Command line channel simulation tool.\n"
96+
"\n"
97+
"usage: %s InputRealModemRawFile OutputRealModemRawFile [Options]\n"
9698
"\n"
9799
" real int16 input -> Gain -> Hilbert Transform -> clipper -> freq shift ->\n"
98100
" Multipath -> AWGN noise -> SSB filter -> real int16 output\n"
99101
"\n"
100102
"[--clip int16] Hilbert clipper (clip complex signal magnitude, default 32767)\n"
101-
"[--complexout] Optional int16 IQ complex output (default real)\n"
103+
"[--complexout] Optional int16 IQ complex output (default real int16)\n"
102104
"[--ctest] Check PAPR is around 0dB, used to support ctests\n"
103-
"[--freqq FoffHz] Frequency offset (default 0Hz)\n"
105+
"[--freq FoffHz] Frequency offset (default 0Hz)\n"
104106
"[--fading_dir Path] path to multipath fading files (default 'unittest')\n"
105107
"[--Fs SampleRateHz] Sample rate of simulation (default 8000 Hz)\n"
106108
"[--gain G] Linear gain (default 1.0)\n"
@@ -301,11 +303,11 @@ int main(int argc, char *argv[])
301303
frames++;
302304

303305
/* Hilbert Transform to produce complex signal so we can do
304-
single sided freq shifts, HF channel modemsl, and analog compression.
305-
Allows us to use real signal I/O which is handy.
306+
single sided freq shifts, HF channel models, and analog
307+
compression. Allows us to use real signal I/O.
306308
307-
As the real and imag filters both have unity gain, ch_in[] has twice
308-
the power of the real input signal buf[].
309+
As the real and imag filters both have unity gain, ch_in[]
310+
has twice the power of the real input signal buf[].
309311
*/
310312

311313
for(i=0, j=HT_N; i<BUF_N; i++,j++) {
@@ -363,7 +365,7 @@ int main(int argc, char *argv[])
363365
ch_fdm_delay[i] = ch_fdm[j];
364366

365367
/* combine direct and delayed paths, both multiplied by
366-
"spreading" (doppler) functions */
368+
"spreading" (Doppler) functions */
367369

368370
for(i=0; i<BUF_N; i++) {
369371
ret = fread(&aspread, sizeof(COMP), 1, ffading);
@@ -465,7 +467,7 @@ int main(int argc, char *argv[])
465467
if (ffading != NULL) fclose(ffading);
466468
if (ch_fdm_delay != NULL) FREE(ch_fdm_delay);
467469
if (ctest) {
468-
/* special ctest modes, check CPAPR is around 0dB */
470+
/* special ctest mode: check CPAPR is around 0dB */
469471
if (fabs(papr) < 0.7) return 0; else return 1;
470472
}
471473
else return 0;

0 commit comments

Comments
 (0)