Skip to content

Commit 8384398

Browse files
committed
support for listening to trellis decoded speech
1 parent 2acee25 commit 8384398

File tree

2 files changed

+56
-19
lines changed

2 files changed

+56
-19
lines changed

octave/trellis.m

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -397,16 +397,15 @@
397397
% Simulations ---------------------------------------------------------------------
398398

399399
% top level function to set up and run a test
400-
function results = test_trellis(nframes=100, dec=1, ntxcw=8, nstages=3, EbNodB=3, verbose=0)
400+
function [results target_] = test_trellis(target_fn, nframes=100, dec=1, ntxcw=8, nstages=3, EbNodB=3, verbose=0)
401401
K = 20; K_st=2+1; K_en=16+1;
402402
vq_fn = "../build_linux/vq_stage1_bs004.f32";
403403
vq_output_fn = "../build_linux/all_speech_8k_test.f32";
404-
target_fn = "../build_linux/all_speech_8k_lim.f32";
405404

406405
% load VQ
407406
vq = load_f32(vq_fn, K);
408407
[vq_size tmp] = size(vq);
409-
vq = vq(:,K_st:K_en);
408+
vqsub = vq(:,K_st:K_en);
410409

411410
% load file of VQ-ed vectors to train up SD PDF estimator
412411
[sd_table h_table] = vq_hist(vq_output_fn, dec);
@@ -415,16 +414,35 @@
415414
target = load_f32(target_fn, K);
416415

417416
% limit test to the first nframes vectors
418-
target = target(1:dec:dec*nframes,K_st:K_en);
417+
if nframes != -1
418+
last = nframes;
419+
else
420+
last = length(target);
421+
end
422+
target = target(1:dec:last,K_st:K_en);
419423

420424
% run a test
421425
EbNo=10^(EbNodB/10);
422-
results = run_test(target, vq, sd_table, h_table, ntxcw, nstages, EbNo, verbose);
426+
results = run_test(target, vqsub, sd_table, h_table, ntxcw, nstages, EbNo, verbose);
423427
if verbose
424428
for f=2:nframes-1
425429
printf("f: %03d tx_index: %04d rx_index: %04d\n", f, results.tx_indexes(f), results.rx_indexes(f));
426430
end
427-
end
431+
end
432+
433+
% return full band vq-ed vectors
434+
target_ = zeros(last,K);
435+
target_(1:dec:last,:) = vq(results.rx_indexes+1,:);
436+
437+
% use linear interpolation to restore original frame rate
438+
for f=1:dec:last-dec
439+
prev = f; next = f + dec;
440+
for g=prev+1:next-1
441+
cnext = (g-prev)/dec; cprev = 1 - cnext;
442+
target_(g,:) = cprev*target_(prev,:) + cnext*target_(next,:);
443+
%printf("f: %d g: %d cprev: %f cnext: %f\n", f, g, cprev, cnext);
444+
end
445+
end
428446
endfunction
429447

430448
% Plot histograms of SD at different decimations in time
@@ -514,8 +532,10 @@ function test_vq(vq_fn)
514532
function [EbNodB rms_sd] = run_curves(frames=100, dec=1, nstages=5)
515533
results_log = [];
516534
EbNodB = [0 1 2 3 4 5];
535+
target_fn = "../build_linux/all_speech_8k_lim.f32";
536+
517537
for i=1:length(EbNodB)
518-
results = test_trellis(frames, dec, ntxcw=8, nstages, EbNodB(i), verbose=0);
538+
results = test_trellis(target_fn, frames, dec, ntxcw=8, nstages, EbNodB(i), verbose=0);
519539
results_log = [results_log results];
520540
end
521541
for i=1:length(results_log)
@@ -545,6 +565,11 @@ function test_vq(vq_fn)
545565
print("-dpng", sprintf("trellis_dec_%d_rms_sd.png",dec));
546566
endfunction
547567

568+
function vq_file(vq_fn, dec, EbNodB, in_fn, out_fn)
569+
[results target_] = test_trellis(in_fn, nframes=-1, dec, ntxcw=8, nstages=3, EbNodB, verbose=0);
570+
save_f32(out_fn, target_);
571+
endfunction
572+
548573
% -------------------------------------------------------------------
549574

550575
more off;
@@ -553,16 +578,16 @@ function test_vq(vq_fn)
553578
% uncomment one of the below to run a test or simulation
554579

555580
% These two tests show where we are at:
556-
%test_trellis(nframes=600, dec=1, ntxcw=8, nstages=3, EbNodB=3, verbose=0);
557-
%test_trellis(nframes=600, dec=4, ntxcw=8, nstages=3, EbNodB=3, verbose=0);
581+
%test_trellis(target_fn, nframes=600, dec=1, ntxcw=8, nstages=3, EbNodB=3, verbose=0);
582+
%test_trellis(target_fn, nframes=600, dec=4, ntxcw=8, nstages=3, EbNodB=3, verbose=0);
558583

559584
%run_curves(600,1)
560585
%run_curves(600,2)
561586
%run_curves(600,4)
562-
[EbNodB rms_sd] = run_curves(30*100,3,3)
587+
%[EbNodB rms_sd] = run_curves(30*100,3,3)
563588

564-
%test_trellis(nframes=200, dec=1, ntxcw=1, nstages=3, EbNodB=3, verbose=0);
565-
%test_trellis(nframes=100, dec=2, ntxcw=8, nstages=3, EbNodB=3, verbose=0);
589+
%test_trellis(target_fn, nframes=200, dec=1, ntxcw=1, nstages=3, EbNodB=3, verbose=0);
590+
%test_trellis(target_fn, nframes=100, dec=2, ntxcw=8, nstages=3, EbNodB=3, verbose=0);
566591
%test_vq("../build_linux/vq_stage1.f32");
567592
%vq_hist_dec("../build_linux/all_speech_8k_test.f32");
568593
%test_single

script/subsetvq.sh

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function train() {
3030
cat ${filename}_lim.f32 | vq_mbest --st $Kst --en $Ken -k $K -q vq_stage1.f32 > ${filename}_test.f32
3131
}
3232

33-
function listen() {
33+
function listen_vq() {
3434
vq_fn=$1
3535
dec=$2
3636
EbNodB=$3
@@ -40,15 +40,21 @@ function listen() {
4040
filename="${filename%.*}"
4141

4242
fullfile_out=$5
43+
do_trellis=$6
4344
sox_options='-t raw -e signed-integer -b 16'
4445
sox $fullfile $sox_options - | c2sim - --rateK --rateKout ${filename}.f32
4546

4647
echo "ratek=load_f32('../build_linux/${filename}.f32',20); vq_700c_eq; ratek_lim=limit_vec(ratek, 0, 40); save_f32('../build_linux/${filename}_lim.f32', ratek_lim); quit" | \
4748
octave -p ${CODEC2_PATH}/octave -qf
4849

49-
echo "pkg load statistics; vq_compare(action='vq_file', '${vq_fn}', ${dec}, ${EbNodB}, '${filename}_lim.f32', '${filename}_test.f32'); quit" \ |
50-
octave -p ${CODEC2_PATH}/octave -qf
51-
50+
if [ "$do_trellis" -eq 0 ]; then
51+
echo "pkg load statistics; vq_compare(action='vq_file', '${vq_fn}', ${dec}, ${EbNodB}, '${filename}_lim.f32', '${filename}_test.f32'); quit" \ |
52+
octave -p ${CODEC2_PATH}/octave -qf
53+
else
54+
echo "pkg load statistics; trellis; vq_file('${vq_fn}', ${dec}, ${EbNodB}, '${filename}_lim.f32', '${filename}_test.f32'); quit" \ |
55+
octave -p ${CODEC2_PATH}/octave -qf
56+
fi
57+
5258
if [ "$fullfile_out" = "aplay" ]; then
5359
sox $fullfile $sox_options - | c2sim - --rateK --rateKin ${filename}_test.f32 -o - | aplay -f S16_LE
5460
else
@@ -65,10 +71,11 @@ function print_help {
6571
echo
6672
echo " -x debug mode; trace script execution"
6773
echo " -t train VQ and generate a fully quantised version of training vectors"
68-
echo " -v in.wav out.wav vq.f32 synthesise an output file out.wav from in.raw, using the VQ vq.f32"
69-
echo " -v in.wav aplay vq.f32 synthesise output, play immediately using aplay, using the VQ vq.f32"
74+
echo " -v vq.f32 in.wav out.wav synthesise an output file out.wav from in.raw, using the VQ vq.f32"
75+
echo " -v vq.f32 in.wav aplay synthesise output, play immediately using aplay, using the VQ vq.f32"
7076
echo " -e EbNodB Eb/No in dB for AWGn channel simulation (error insertion)"
7177
echo " -d dec decimation/interpolation rate"
78+
echo " -r use trellis decoder"
7279
echo
7380
exit
7481
}
@@ -81,6 +88,7 @@ fi
8188

8289
do_train=0
8390
do_vq=0
91+
do_trellis=0
8492
EbNodB=100
8593
dec=1
8694
POSITIONAL=()
@@ -106,6 +114,10 @@ case $key in
106114
shift
107115
shift
108116
;;
117+
-r)
118+
do_trellis=1
119+
shift
120+
;;
109121
-d)
110122
dec="$2"
111123
shift
@@ -132,5 +144,5 @@ if [ $do_train -eq 1 ]; then
132144
fi
133145

134146
if [ $do_vq -eq 1 ]; then
135-
listen ${vq_fn} ${dec} ${EbNodB} ${in_wav} ${out_wav}
147+
listen_vq ${vq_fn} ${dec} ${EbNodB} ${in_wav} ${out_wav} ${do_trellis}
136148
fi

0 commit comments

Comments
 (0)