summaryrefslogtreecommitdiff
path: root/vq
diff options
context:
space:
mode:
Diffstat (limited to 'vq')
-rw-r--r--vq/.cvsignore4
-rw-r--r--vq/44c0.vqs74
-rw-r--r--vq/44c1.vqs51
-rw-r--r--vq/44c2.vqs51
-rw-r--r--vq/44c3.vqs52
-rw-r--r--vq/44c4.vqs105
-rw-r--r--vq/44c5.vqs67
-rw-r--r--vq/44c6.vqs67
-rw-r--r--vq/44c7.vqs57
-rw-r--r--vq/44c8.vqs44
-rw-r--r--vq/44c9.vqs44
-rw-r--r--vq/44u0.vqs36
-rw-r--r--vq/44u4.vqs37
-rw-r--r--vq/44u7.vqs40
-rw-r--r--vq/Makefile.am51
-rwxr-xr-xvq/auxpartition.pl71
-rw-r--r--vq/bookutil.c738
-rw-r--r--vq/bookutil.h43
-rw-r--r--vq/build.c195
-rw-r--r--vq/cascade.c91
-rw-r--r--vq/distribution.c248
-rw-r--r--vq/genericdata.c61
-rw-r--r--vq/huffbuild.c222
-rw-r--r--vq/latticebuild.c177
-rw-r--r--vq/latticehint.c430
-rw-r--r--vq/latticepare.c595
-rw-r--r--vq/latticetune.c164
-rw-r--r--vq/lspdata.c157
-rwxr-xr-xvq/make_residue_books.pl168
-rw-r--r--vq/metrics.c295
-rwxr-xr-xvq/residue_entropy58
-rw-r--r--vq/residuedata.c160
-rw-r--r--vq/residuesplit.c282
-rw-r--r--vq/run.c216
-rw-r--r--vq/train.c364
-rw-r--r--vq/vqext.h34
-rw-r--r--vq/vqgen.c568
-rw-r--r--vq/vqgen.h85
-rw-r--r--vq/vqsplit.c612
-rw-r--r--vq/vqsplit.h37
40 files changed, 0 insertions, 6851 deletions
diff --git a/vq/.cvsignore b/vq/.cvsignore
deleted file mode 100644
index 02b05239..00000000
--- a/vq/.cvsignore
+++ /dev/null
@@ -1,4 +0,0 @@
-Makefile
-Makefile.in
-.deps
-.libs
diff --git a/vq/44c0.vqs b/vq/44c0.vqs
deleted file mode 100644
index 59aebe12..00000000
--- a/vq/44c0.vqs
+++ /dev/null
@@ -1,74 +0,0 @@
-cp 44c0_s0/resaux_short.vqd _44c0_short.vqd
-cp 44c0_s0/resaux_long.vqd _44c0_long.vqd
-
-
-GO
-
->_44c0s noninterleaved
-haux _44c0_short.vqd 0,12,2
-
->_44c0 noninterleaved
-haux _44c0_long.vqd 0,44,2
-
-#iter 0
-
-# 0 1 2 4 26 1 4 +
-# 0 0 0 0
-#
-# 0 1 2 3 4 5 6 7
-# 1 . .
-# 2 . .
-# 4 . . . . . .
-
-:_s0_p1_0 44c0_s0/res_part1_pass2.vqd, 4, nonseq cull, 0 +- 1 2
-:_s0_p2_0 44c0_s0/res_part2_pass2.vqd, 2, nonseq cull, 0 +- 1 2 3 4
-:_s0_p3_0 44c0_s0/res_part3_pass2.vqd, 2, nonseq cull, 0 +- 1 2 3 4 5 6 7 8
-:_s0_p4_0 44c0_s0/res_part4_pass0.vqd, 2, nonseq, 0 +- 7 14 21 28 35 42 49
-:_s0_p4_1 44c0_s0/res_part4_pass1.vqd, 2, nonseq cull, 0 +- 1 2 3
-
-:_s0_p5_0 44c0_s0/res_part5_pass2.vqd, 4, nonseq cull, 0 +- 1 2
-:_s1_p5_0 44c0_s1/res_part5_pass2.vqd, 4, nonseq cull, 0 +- 1
-
-:_s0_p6_0 44c0_s0/res_part6_pass2.vqd, 2, nonseq cull, 0 +- 1 2 3 4 5 6 7 8
-:_s1_p6_0 44c0_s1/res_part6_pass2.vqd, 2, nonseq cull, 0 +- 1 2 3 4 5 6 7 8
-:_s2_p6_0 44c0_s2/res_part6_pass2.vqd, 2, nonseq cull, 0 +- 1 2 3 4
-
-:_s0_p7_0 44c0_s0/res_part7_pass0.vqd, 2, nonseq, 0 +- 67 134 201
-:_s0_p7_1 44c0_s0/res_part7_pass1.vqd, 2, nonseq, 0 +- 3 6 9 12 15 18 21 24 27 30 33
-:_s0_p7_2 44c0_s0/res_part7_pass2.vqd, 4, nonseq, 0 +- 1
-
-:_s1_p7_0 44c0_s1/res_part7_pass0.vqd, 2, nonseq, 0 +- 67 134 201
-:_s1_p7_1 44c0_s1/res_part7_pass1.vqd, 2, nonseq, 0 +- 3 6 9 12 15 18 21 24 27 30 33
-:_s1_p7_2 44c0_s1/res_part7_pass2.vqd, 4, nonseq, 0 +- 1
-
-:_s2_p7_0 44c0_s2/res_part7_pass0.vqd, 2, nonseq, 0 +- 67 134 201
-:_s2_p7_1 44c0_s2/res_part7_pass1.vqd, 2, nonseq, 0 +- 3 6 9 12 15 18 21 24 27 30 33
-:_s2_p7_2 44c0_s2/res_part7_pass2.vqd, 4, nonseq, 0 +- 1
-
-:_s3_p7_0 44c0_s3/res_part7_pass0.vqd, 2, nonseq, 0 +- 67 134 201
-:_s3_p7_1 44c0_s3/res_part7_pass1.vqd, 2, nonseq, 0 +- 3 6 9 12 15 18 21 24 27 30 33
-:_s3_p7_2 44c0_s3/res_part7_pass2.vqd, 4, nonseq, 0 +- 1
-
-#iter 1 (stereo 3(8.)->2 2(4.)->1 1(2.)->0) shared for all 'low' modes
-
-:_s1_p5_s0 44cL_s1/res_part5_pass3.vqd, 2, nonseq, 0 +- 1 2
-:_s1_p6_s0 44cL_s1/res_part6_pass3.vqd, 2, nonseq, 0 +- 1 2 3 4
-:_s1_p7_s0 44cL_s1/res_part7_pass3.vqd, 2, nonseq, 0 +- 1 2 3 4
-
-:_s2_p6_s0 44cL_s2/res_part6_pass3.vqd, 2, nonseq, 0 +- 1 2 3 4 5 6 7 8
-:_s2_p7_s0 44cL_s2/res_part7_pass3.vqd, 2, nonseq, 0 +- 1 2 3 4 5 6 7 8
-
-:_s3_p7_s0 44cL_s3/res_part7_pass3.vqd, 2, nonseq cull, 0 +- 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
-
-#iter 2 (residue backfill) shared for all 'low' modes
-
-:_s0_p0_r0 44cL_s0/res_part0_r0.vqd, 2, nonseq, 0 +- .333333333 .666666667
-:_s0_pN_r0 44cL_s0/res_partN_r0.vqd, 2, nonseq, 0 +- .333333333 .666666667
-:_s1_pS_r0 44cL_s1/res_partS_r0.vqd, 2, nonseq, 0 +- .333333333
-
-#iter 3 (residue backfill)
-
-:_s0_p0_r1 44cL_s0/res_part0_r1.vqd, 2, nonseq, 0 +- .111111111 .222222222
-:_s0_pN_r1 44cL_s0/res_partN_r1.vqd, 2, nonseq, 0 +- .111111111 .222222222
-:_s1_pS_r1 44cL_s1/res_partS_r1.vqd, 2, nonseq, 0 +- .111111111
-
diff --git a/vq/44c1.vqs b/vq/44c1.vqs
deleted file mode 100644
index a90001ee..00000000
--- a/vq/44c1.vqs
+++ /dev/null
@@ -1,51 +0,0 @@
-cp 44c1_s0/resaux_short.vqd _44c1_short.vqd
-cp 44c1_s0/resaux_long.vqd _44c1_long.vqd
-
-
-GO
-
->_44c1s noninterleaved
-haux _44c1_short.vqd 0,12,2
-
->_44c1 noninterleaved
-haux _44c1_long.vqd 0,46,2
-
-#iter 0
-
-# 0 1 2 4 26 1 4 +
-# 0 0 0 0
-#
-# 0 1 2 3 4 5 6 7
-# 1 . .
-# 2 . .
-# 4 . . . . . .
-
-:_s0_p1_0 44c1_s0/res_part1_pass2.vqd, 4, nonseq cull, 0 +- 1 2
-:_s0_p2_0 44c1_s0/res_part2_pass2.vqd, 2, nonseq cull, 0 +- 1 2 3 4
-:_s0_p3_0 44c1_s0/res_part3_pass2.vqd, 2, nonseq cull, 0 +- 1 2 3 4 5 6 7 8
-:_s0_p4_0 44c1_s0/res_part4_pass0.vqd, 2, nonseq, 0 +- 7 14 21 28 35 42 49
-:_s0_p4_1 44c1_s0/res_part4_pass1.vqd, 2, nonseq cull, 0 +- 1 2 3
-
-:_s0_p5_0 44c1_s0/res_part5_pass2.vqd, 4, nonseq cull, 0 +- 1 2
-:_s1_p5_0 44c1_s1/res_part5_pass2.vqd, 4, nonseq cull, 0 +- 1
-
-:_s0_p6_0 44c1_s0/res_part6_pass2.vqd, 2, nonseq cull, 0 +- 1 2 3 4 5 6 7 8
-:_s1_p6_0 44c1_s1/res_part6_pass2.vqd, 2, nonseq cull, 0 +- 1 2 3 4 5 6 7 8
-:_s2_p6_0 44c1_s2/res_part6_pass2.vqd, 2, nonseq cull, 0 +- 1 2 3 4
-
-:_s0_p7_0 44c1_s0/res_part7_pass0.vqd, 2, nonseq, 0 +- 67 134 201
-:_s0_p7_1 44c1_s0/res_part7_pass1.vqd, 2, nonseq, 0 +- 3 6 9 12 15 18 21 24 27 30 33
-:_s0_p7_2 44c1_s0/res_part7_pass2.vqd, 4, nonseq, 0 +- 1
-
-:_s1_p7_0 44c1_s1/res_part7_pass0.vqd, 2, nonseq, 0 +- 67 134 201
-:_s1_p7_1 44c1_s1/res_part7_pass1.vqd, 2, nonseq, 0 +- 3 6 9 12 15 18 21 24 27 30 33
-:_s1_p7_2 44c1_s1/res_part7_pass2.vqd, 4, nonseq, 0 +- 1
-
-:_s2_p7_0 44c1_s2/res_part7_pass0.vqd, 2, nonseq, 0 +- 67 134 201
-:_s2_p7_1 44c1_s2/res_part7_pass1.vqd, 2, nonseq, 0 +- 3 6 9 12 15 18 21 24 27 30 33
-:_s2_p7_2 44c1_s2/res_part7_pass2.vqd, 4, nonseq, 0 +- 1
-
-:_s3_p7_0 44c1_s3/res_part7_pass0.vqd, 2, nonseq, 0 +- 67 134 201
-:_s3_p7_1 44c1_s3/res_part7_pass1.vqd, 2, nonseq, 0 +- 3 6 9 12 15 18 21 24 27 30 33
-:_s3_p7_2 44c1_s3/res_part7_pass2.vqd, 4, nonseq, 0 +- 1
-
diff --git a/vq/44c2.vqs b/vq/44c2.vqs
deleted file mode 100644
index edcfdcc7..00000000
--- a/vq/44c2.vqs
+++ /dev/null
@@ -1,51 +0,0 @@
-cp 44c2_s0/resaux_short.vqd _44c2_short.vqd
-cp 44c2_s0/resaux_long.vqd _44c2_long.vqd
-
-
-GO
-
->_44c2s noninterleaved
-haux _44c2_short.vqd 0,12,2
-
->_44c2 noninterleaved
-haux _44c2_long.vqd 0,48,2
-
-#iter 0
-
-# 0 1 2 4 26 1 4 +
-# 0 0 0 0
-#
-# 0 1 2 3 4 5 6 7
-# 1 . .
-# 2 . .
-# 4 . . . . . .
-
-:_s0_p1_0 44c2_s0/res_part1_pass2.vqd, 4, nonseq cull, 0 +- 1 2
-:_s0_p2_0 44c2_s0/res_part2_pass2.vqd, 2, nonseq cull, 0 +- 1 2 3 4
-:_s0_p3_0 44c2_s0/res_part3_pass2.vqd, 2, nonseq cull, 0 +- 1 2 3 4 5 6 7 8
-:_s0_p4_0 44c2_s0/res_part4_pass0.vqd, 2, nonseq, 0 +- 7 14 21 28 35 42 49
-:_s0_p4_1 44c2_s0/res_part4_pass1.vqd, 2, nonseq cull, 0 +- 1 2 3
-
-:_s0_p5_0 44c2_s0/res_part5_pass2.vqd, 4, nonseq cull, 0 +- 1 2
-:_s1_p5_0 44c2_s1/res_part5_pass2.vqd, 4, nonseq cull, 0 +- 1
-
-:_s0_p6_0 44c2_s0/res_part6_pass2.vqd, 2, nonseq cull, 0 +- 1 2 3 4 5 6 7 8
-:_s1_p6_0 44c2_s1/res_part6_pass2.vqd, 2, nonseq cull, 0 +- 1 2 3 4 5 6 7 8
-:_s2_p6_0 44c2_s2/res_part6_pass2.vqd, 2, nonseq cull, 0 +- 1 2 3 4
-
-:_s0_p7_0 44c2_s0/res_part7_pass0.vqd, 2, nonseq, 0 +- 67 134 201
-:_s0_p7_1 44c2_s0/res_part7_pass1.vqd, 2, nonseq, 0 +- 3 6 9 12 15 18 21 24 27 30 33
-:_s0_p7_2 44c2_s0/res_part7_pass2.vqd, 4, nonseq, 0 +- 1
-
-:_s1_p7_0 44c2_s1/res_part7_pass0.vqd, 2, nonseq, 0 +- 67 134 201
-:_s1_p7_1 44c2_s1/res_part7_pass1.vqd, 2, nonseq, 0 +- 3 6 9 12 15 18 21 24 27 30 33
-:_s1_p7_2 44c2_s1/res_part7_pass2.vqd, 4, nonseq, 0 +- 1
-
-:_s2_p7_0 44c2_s2/res_part7_pass0.vqd, 2, nonseq, 0 +- 67 134 201
-:_s2_p7_1 44c2_s2/res_part7_pass1.vqd, 2, nonseq, 0 +- 3 6 9 12 15 18 21 24 27 30 33
-:_s2_p7_2 44c2_s2/res_part7_pass2.vqd, 4, nonseq, 0 +- 1
-
-:_s3_p7_0 44c2_s3/res_part7_pass0.vqd, 2, nonseq, 0 +- 67 134 201
-:_s3_p7_1 44c2_s3/res_part7_pass1.vqd, 2, nonseq, 0 +- 3 6 9 12 15 18 21 24 27 30 33
-:_s3_p7_2 44c2_s3/res_part7_pass2.vqd, 4, nonseq, 0 +- 1
-
diff --git a/vq/44c3.vqs b/vq/44c3.vqs
deleted file mode 100644
index e0232c83..00000000
--- a/vq/44c3.vqs
+++ /dev/null
@@ -1,52 +0,0 @@
-cp 44c3_s0/resaux_short.vqd _44c3_short.vqd
-cp 44c3_s0/resaux_long.vqd _44c3_long.vqd
-
-
-GO
-
->_44c3s noninterleaved
-haux _44c3_short.vqd 0,14,2
-
->_44c3 noninterleaved
-haux _44c3_long.vqd 0,52,2
-
-#iter 0
-
-# 0 1 2 4 26 1 4 +
-# 0 0 0 0
-#
-# 0 1 2 3 4 5 6 7
-# 1 . .
-# 2 . .
-# 4 . . . . . .
-
-:_s0_p1_0 44c3_s0/res_part1_pass2.vqd, 4, nonseq cull, 0 +- 1 2
-:_s0_p2_0 44c3_s0/res_part2_pass2.vqd, 2, nonseq cull, 0 +- 1 2 3 4
-:_s0_p3_0 44c3_s0/res_part3_pass2.vqd, 2, nonseq cull, 0 +- 1 2 3 4 5 6 7 8
-:_s0_p4_0 44c3_s0/res_part4_pass0.vqd, 2, nonseq, 0 +- 7 14 21 28 35 42 49
-:_s0_p4_1 44c3_s0/res_part4_pass1.vqd, 2, nonseq cull, 0 +- 1 2 3
-
-:_s0_p5_0 44c3_s0/res_part5_pass2.vqd, 4, nonseq cull, 0 +- 1 2
-:_s1_p5_0 44c3_s1/res_part5_pass2.vqd, 4, nonseq cull, 0 +- 1
-
-:_s0_p6_0 44c3_s0/res_part6_pass2.vqd, 2, nonseq cull, 0 +- 1 2 3 4 5 6 7 8
-:_s1_p6_0 44c3_s1/res_part6_pass2.vqd, 2, nonseq cull, 0 +- 1 2 3 4 5 6 7 8
-:_s2_p6_0 44c3_s2/res_part6_pass2.vqd, 2, nonseq cull, 0 +- 1 2 3 4
-
-:_s0_p7_0 44c3_s0/res_part7_pass0.vqd, 2, nonseq, 0 +- 67 134 201 268 335 402
-:_s0_p7_1 44c3_s0/res_part7_pass1.vqd, 2, nonseq, 0 +- 3 6 9 12 15 18 21 24 27 30 33
-:_s0_p7_2 44c3_s0/res_part7_pass2.vqd, 4, nonseq, 0 +- 1
-
-:_s1_p7_0 44c3_s1/res_part7_pass0.vqd, 2, nonseq, 0 +- 67 134 201 268 335 402
-:_s1_p7_1 44c3_s1/res_part7_pass1.vqd, 2, nonseq, 0 +- 3 6 9 12 15 18 21 24 27 30 33
-:_s1_p7_2 44c3_s1/res_part7_pass2.vqd, 4, nonseq, 0 +- 1
-
-:_s2_p7_0 44c3_s2/res_part7_pass0.vqd, 2, nonseq, 0 +- 67 134 201 268 335 402
-:_s2_p7_1 44c3_s2/res_part7_pass1.vqd, 2, nonseq, 0 +- 3 6 9 12 15 18 21 24 27 30 33
-:_s2_p7_2 44c3_s2/res_part7_pass2.vqd, 4, nonseq, 0 +- 1
-
-:_s3_p7_0 44c3_s3/res_part7_pass0.vqd, 2, nonseq, 0 +- 67 134 201 268 335 402
-:_s3_p7_1 44c3_s3/res_part7_pass1.vqd, 2, nonseq, 0 +- 3 6 9 12 15 18 21 24 27 30 33
-:_s3_p7_2 44c3_s3/res_part7_pass2.vqd, 4, nonseq, 0 +- 1
-
-
diff --git a/vq/44c4.vqs b/vq/44c4.vqs
deleted file mode 100644
index 717700c3..00000000
--- a/vq/44c4.vqs
+++ /dev/null
@@ -1,105 +0,0 @@
-cp 44c4_s0/resaux_short.vqd _44c4_short.vqd
-cp 44c4_s0/resaux_long.vqd _44c4_long.vqd
-
-GO
-
->_44c4s noninterleaved
-haux _44c4_short.vqd 0,16,2
-
->_44c4 noninterleaved
-haux _44c4_long.vqd 0,64,2
-
-#iter 0
-
-# 0 1 1 2 2 4 4 16 42 +
-# 0 0 0
-
-# 0 1 2 3 4 5 6 7 8 9
-# 1 . . .
-# 2 . . .
-# 4 . . . . . . .
-
-:_s0_p1_0 44c4_s0/res_part1_pass2.vqd, 4, nonseq cull, 0 +- 1 2
-
-:_s0_p2_0 44c4_s0/res_part2_pass2.vqd, 4, nonseq cull, 0 +- 1 2
-:_s1_p2_0 44c4_s1/res_part2_pass2.vqd, 4, nonseq cull, 0 +- 1
-
-:_s0_p3_0 44c4_s0/res_part3_pass2.vqd, 2, nonseq cull, 0 +- 1 2 3 4
-
-:_s0_p4_0 44c4_s0/res_part4_pass2.vqd, 2, nonseq cull, 0 +- 1 2 3 4
-:_s1_p4_0 44c4_s1/res_part4_pass2.vqd, 4, nonseq cull, 0 +- 1 2
-
-:_s0_p5_0 44c4_s0/res_part5_pass2.vqd, 2, nonseq cull, 0 +- 1 2 3 4 5 6 7 8
-
-:_s0_p6_0 44c4_s0/res_part6_pass2.vqd, 2, nonseq cull, 0 +- 1 2 3 4 5 6 7 8
-:_s1_p6_0 44c4_s1/res_part6_pass2.vqd, 2, nonseq cull, 0 +- 1 2 3 4 5 6 7 8
-:_s2_p6_0 44c4_s2/res_part6_pass2.vqd, 2, nonseq cull, 0 +- 1 2 3 4
-
-:_s0_p7_0 44c4_s0/res_part7_pass0.vqd, 2, nonseq cull, 0 +- 5 10 15 20 25 30
-:_s0_p7_1 44c4_s0/res_part7_pass1.vqd, 2, nonseq cull, 0 +- 1 2
-:_s1_p7_0 44c4_s1/res_part7_pass0.vqd, 2, nonseq cull, 0 +- 5 10 15 20 25 30
-:_s1_p7_1 44c4_s1/res_part7_pass1.vqd, 2, nonseq cull, 0 +- 1 2
-:_s2_p7_0 44c4_s2/res_part7_pass0.vqd, 2, nonseq cull, 0 +- 5 10 15 20 25 30
-:_s2_p7_1 44c4_s2/res_part7_pass1.vqd, 2, nonseq cull, 0 +- 1 2
-:_s3_p7_0 44c4_s3/res_part7_pass0.vqd, 2, nonseq cull, 0 +- 5 10 15 20 25 30
-:_s3_p7_1 44c4_s3/res_part7_pass1.vqd, 2, nonseq cull, 0 +- 1 2
-
-:_s0_p8_0 44c4_s0/res_part8_pass0.vqd, 2, nonseq cull, 0 +- 13 26 39 52 65 78
-:_s0_p8_1 44c4_s0/res_part8_pass1.vqd, 2, nonseq cull, 0 +- 1 2 3 4 5 6
-:_s1_p8_0 44c4_s1/res_part8_pass0.vqd, 2, nonseq cull, 0 +- 13 26 39 52 65 78
-:_s1_p8_1 44c4_s1/res_part8_pass1.vqd, 2, nonseq cull, 0 +- 1 2 3 4 5 6
-:_s2_p8_0 44c4_s2/res_part8_pass0.vqd, 2, nonseq cull, 0 +- 13 26 39 52 65 78
-:_s2_p8_1 44c4_s2/res_part8_pass1.vqd, 2, nonseq cull, 0 +- 1 2 3 4 5 6
-:_s3_p8_0 44c4_s3/res_part8_pass0.vqd, 2, nonseq cull, 0 +- 13 26 39 52 65 78
-:_s3_p8_1 44c4_s3/res_part8_pass1.vqd, 2, nonseq cull, 0 +- 1 2 3 4 5 6
-
-:_s0_p9_0 44c4_s0/res_part9_pass0.vqd, 2, nonseq, 0 +- 169 338 507 676 845 1014
-:_s0_p9_1 44c4_s0/res_part9_pass1.vqd, 2, nonseq, 0 +- 13 26 39 52 65 78
-:_s0_p9_2 44c4_s0/res_part9_pass2.vqd, 2, nonseq, 0 +- 1 2 3 4 5 6
-:_s1_p9_0 44c4_s1/res_part9_pass0.vqd, 2, nonseq, 0 +- 169 338 507 676 845 1014
-:_s1_p9_1 44c4_s1/res_part9_pass1.vqd, 2, nonseq, 0 +- 13 26 39 52 65 78
-:_s1_p9_2 44c4_s1/res_part9_pass2.vqd, 2, nonseq, 0 +- 1 2 3 4 5 6
-:_s2_p9_0 44c4_s2/res_part9_pass0.vqd, 2, nonseq, 0 +- 169 338 507 676 845 1014
-:_s2_p9_1 44c4_s2/res_part9_pass1.vqd, 2, nonseq, 0 +- 13 26 39 52 65 78
-:_s2_p9_2 44c4_s2/res_part9_pass2.vqd, 2, nonseq, 0 +- 1 2 3 4 5 6
-:_s3_p9_0 44c4_s3/res_part9_pass0.vqd, 2, nonseq, 0 +- 169 338 507 676 845 1014
-:_s3_p9_1 44c4_s3/res_part9_pass1.vqd, 2, nonseq, 0 +- 13 26 39 52 65 78
-:_s3_p9_2 44c4_s3/res_part9_pass2.vqd, 2, nonseq, 0 +- 1 2 3 4 5 6
-
-#iter 1 (stereo 3(8.)->2 2(4.)->1 1(2.)->0) shared for all 'mid' modes
-
-# 0 1 1 2 2 4 4 16 42 +
-# 0 0 0
-
-# 0 1 2 3 4 5 6 7 8 9
-# 1 . . .
-# 2 . . .
-# 4 . . . . . . .
-
-:_s1_p2_s0 44cM_s1/res_part2_pass3.vqd, 2, nonseq, 0 +- 1 2
-:_s1_p4_s0 44cM_s1/res_part4_pass3.vqd, 2, nonseq, 0 +- 1 2 3 4
-:_s1_p6_s0 44cM_s1/res_part6_pass3.vqd, 2, nonseq, 0 +- 1 2 3 4
-:_s1_p7_s0 44cM_s1/res_part7_pass3.vqd, 2, nonseq, 0 +- 1 2 3 4
-:_s1_p8_s0 44cM_s1/res_part8_pass3.vqd, 2, nonseq, 0 +- 1 2 3 4
-:_s1_p9_s0 44cM_s1/res_part9_pass3.vqd, 2, nonseq, 0 +- 1 2 3 4
-
-:_s2_p6_s0 44cM_s2/res_part6_pass3.vqd, 2, nonseq, 0 +- 1 2 3 4 5 6 7 8
-:_s2_p7_s0 44cM_s2/res_part7_pass3.vqd, 2, nonseq, 0 +- 1 2 3 4 5 6 7 8
-:_s2_p8_s0 44cM_s2/res_part8_pass3.vqd, 2, nonseq, 0 +- 1 2 3 4 5 6 7 8
-:_s2_p9_s0 44cM_s2/res_part9_pass3.vqd, 2, nonseq, 0 +- 1 2 3 4 5 6 7 8
-
-:_s3_p9_s0 44cM_s3/res_part789_pass3.vqd, 2, nonseq, 0 +- 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
-
-#iter 2 (residue backfill) shared for all 'mid' modes
-
-:_s0_p0_r0 44cM_s0/res_part0_r0.vqd, 2, nonseq, 0 +- .333333333 .666666667
-:_s0_pN_r0 44cM_s0/res_partN_r0.vqd, 2, nonseq, 0 +- .333333333 .666666667
-:_s1_pS_r0 44cM_s1/res_partS_r0.vqd, 2, nonseq, 0 +- .333333333
-
-#iter 3 (residue backfill)
-
-:_s0_p0_r1 44cM_s0/res_part0_r1.vqd, 2, nonseq, 0 +- .111111111 .222222222
-:_s0_pN_r1 44cM_s0/res_partN_r1.vqd, 2, nonseq, 0 +- .111111111 .222222222
-:_s1_pS_r1 44cM_s1/res_partS_r1.vqd, 2, nonseq, 0 +- .111111111
-
-
diff --git a/vq/44c5.vqs b/vq/44c5.vqs
deleted file mode 100644
index 27ce7480..00000000
--- a/vq/44c5.vqs
+++ /dev/null
@@ -1,67 +0,0 @@
-cp 44c5_s0/resaux_short.vqd _44c5_short.vqd
-cp 44c5_s0/resaux_long.vqd _44c5_long.vqd
-
-GO
-
->_44c5s noninterleaved
-haux _44c5_short.vqd 0,16,2
-
->_44c5 noninterleaved
-haux _44c5_long.vqd 0,64,2
-
-#iter 0
-
-# 0 1 1 2 2 4 4 16 42 +
-# 0 0 0
-
-# 0 1 2 3 4 5 6 7 8 9
-# 1 . . .
-# 2 . . .
-# 4 . . . . . . .
-
-:_s0_p1_0 44c5_s0/res_part1_pass2.vqd, 4, nonseq cull, 0 +- 1 2
-
-:_s0_p2_0 44c5_s0/res_part2_pass2.vqd, 4, nonseq cull, 0 +- 1 2
-:_s1_p2_0 44c5_s1/res_part2_pass2.vqd, 4, nonseq cull, 0 +- 1
-
-:_s0_p3_0 44c5_s0/res_part3_pass2.vqd, 2, nonseq cull, 0 +- 1 2 3 4
-
-:_s0_p4_0 44c5_s0/res_part4_pass2.vqd, 2, nonseq cull, 0 +- 1 2 3 4
-:_s1_p4_0 44c5_s1/res_part4_pass2.vqd, 4, nonseq cull, 0 +- 1 2
-
-:_s0_p5_0 44c5_s0/res_part5_pass2.vqd, 2, nonseq cull, 0 +- 1 2 3 4 5 6 7 8
-
-:_s0_p6_0 44c5_s0/res_part6_pass2.vqd, 2, nonseq cull, 0 +- 1 2 3 4 5 6 7 8
-:_s1_p6_0 44c5_s1/res_part6_pass2.vqd, 2, nonseq cull, 0 +- 1 2 3 4 5 6 7 8
-:_s2_p6_0 44c5_s2/res_part6_pass2.vqd, 2, nonseq cull, 0 +- 1 2 3 4
-
-:_s0_p7_0 44c5_s0/res_part7_pass0.vqd, 2, nonseq cull, 0 +- 5 10 15 20 25 30
-:_s0_p7_1 44c5_s0/res_part7_pass1.vqd, 2, nonseq cull, 0 +- 1 2
-:_s1_p7_0 44c5_s1/res_part7_pass0.vqd, 2, nonseq cull, 0 +- 5 10 15 20 25 30
-:_s1_p7_1 44c5_s1/res_part7_pass1.vqd, 2, nonseq cull, 0 +- 1 2
-:_s2_p7_0 44c5_s2/res_part7_pass0.vqd, 2, nonseq cull, 0 +- 5 10 15 20 25 30
-:_s2_p7_1 44c5_s2/res_part7_pass1.vqd, 2, nonseq cull, 0 +- 1 2
-:_s3_p7_0 44c5_s3/res_part7_pass0.vqd, 2, nonseq cull, 0 +- 5 10 15 20 25 30
-:_s3_p7_1 44c5_s3/res_part7_pass1.vqd, 2, nonseq cull, 0 +- 1 2
-
-:_s0_p8_0 44c5_s0/res_part8_pass0.vqd, 2, nonseq cull, 0 +- 13 26 39 52 65 78
-:_s0_p8_1 44c5_s0/res_part8_pass1.vqd, 2, nonseq cull, 0 +- 1 2 3 4 5 6
-:_s1_p8_0 44c5_s1/res_part8_pass0.vqd, 2, nonseq cull, 0 +- 13 26 39 52 65 78
-:_s1_p8_1 44c5_s1/res_part8_pass1.vqd, 2, nonseq cull, 0 +- 1 2 3 4 5 6
-:_s2_p8_0 44c5_s2/res_part8_pass0.vqd, 2, nonseq cull, 0 +- 13 26 39 52 65 78
-:_s2_p8_1 44c5_s2/res_part8_pass1.vqd, 2, nonseq cull, 0 +- 1 2 3 4 5 6
-:_s3_p8_0 44c5_s3/res_part8_pass0.vqd, 2, nonseq cull, 0 +- 13 26 39 52 65 78
-:_s3_p8_1 44c5_s3/res_part8_pass1.vqd, 2, nonseq cull, 0 +- 1 2 3 4 5 6
-
-:_s0_p9_0 44c5_s0/res_part9_pass0.vqd, 2, nonseq, 0 +- 221 442 663 884 1105 1326 1547
-:_s0_p9_1 44c5_s0/res_part9_pass1.vqd, 2, nonseq, 0 +- 13 26 39 52 65 78 91 104
-:_s0_p9_2 44c5_s0/res_part9_pass2.vqd, 2, nonseq, 0 +- 1 2 3 4 5 6
-:_s1_p9_0 44c5_s1/res_part9_pass0.vqd, 2, nonseq, 0 +- 221 442 663 884 1105 1326 1547
-:_s1_p9_1 44c5_s1/res_part9_pass1.vqd, 2, nonseq, 0 +- 13 26 39 52 65 78 91 104
-:_s1_p9_2 44c5_s1/res_part9_pass2.vqd, 2, nonseq, 0 +- 1 2 3 4 5 6
-:_s2_p9_0 44c5_s2/res_part9_pass0.vqd, 2, nonseq, 0 +- 221 442 663 884 1105 1326 1547
-:_s2_p9_1 44c5_s2/res_part9_pass1.vqd, 2, nonseq, 0 +- 13 26 39 52 65 78 91 104
-:_s2_p9_2 44c5_s2/res_part9_pass2.vqd, 2, nonseq, 0 +- 1 2 3 4 5 6
-:_s3_p9_0 44c5_s3/res_part9_pass0.vqd, 2, nonseq, 0 +- 221 442 663 884 1105 1326 1547
-:_s3_p9_1 44c5_s3/res_part9_pass1.vqd, 2, nonseq, 0 +- 13 26 39 52 65 78 91 104
-:_s3_p9_2 44c5_s3/res_part9_pass2.vqd, 2, nonseq, 0 +- 1 2 3 4 5 6
diff --git a/vq/44c6.vqs b/vq/44c6.vqs
deleted file mode 100644
index 7c0663d1..00000000
--- a/vq/44c6.vqs
+++ /dev/null
@@ -1,67 +0,0 @@
-cp 44c6_s0/resaux_short.vqd _44c6_short.vqd
-cp 44c6_s0/resaux_long.vqd _44c6_long.vqd
-
-GO
-
->_44c6s noninterleaved
-haux _44c6_short.vqd 0,16,2
-
->_44c6 noninterleaved
-haux _44c6_long.vqd 0,64,2
-
-#iter 0
-
-# 0 1 1 2 2 4 4 16 42 +
-# 0 0 0
-
-# 0 1 2 3 4 5 6 7 8 9
-# 1 . . .
-# 2 . . .
-# 4 . . . . . . .
-
-:_s0_p1_0 44c6_s0/res_part1_pass2.vqd, 4, nonseq cull, 0 +- 1 2
-
-:_s0_p2_0 44c6_s0/res_part2_pass2.vqd, 4, nonseq cull, 0 +- 1 2
-:_s1_p2_0 44c6_s1/res_part2_pass2.vqd, 4, nonseq cull, 0 +- 1
-
-:_s0_p3_0 44c6_s0/res_part3_pass2.vqd, 2, nonseq cull, 0 +- 1 2 3 4
-
-:_s0_p4_0 44c6_s0/res_part4_pass2.vqd, 2, nonseq cull, 0 +- 1 2 3 4
-:_s1_p4_0 44c6_s1/res_part4_pass2.vqd, 4, nonseq cull, 0 +- 1 2
-
-:_s0_p5_0 44c6_s0/res_part5_pass2.vqd, 2, nonseq cull, 0 +- 1 2 3 4 5 6 7 8
-
-:_s0_p6_0 44c6_s0/res_part6_pass2.vqd, 2, nonseq cull, 0 +- 1 2 3 4 5 6 7 8
-:_s1_p6_0 44c6_s1/res_part6_pass2.vqd, 2, nonseq cull, 0 +- 1 2 3 4 5 6 7 8
-:_s2_p6_0 44c6_s2/res_part6_pass2.vqd, 2, nonseq cull, 0 +- 1 2 3 4
-
-:_s0_p7_0 44c6_s0/res_part7_pass0.vqd, 2, nonseq cull, 0 +- 5 10 15 20 25 30
-:_s0_p7_1 44c6_s0/res_part7_pass1.vqd, 2, nonseq cull, 0 +- 1 2
-:_s1_p7_0 44c6_s1/res_part7_pass0.vqd, 2, nonseq cull, 0 +- 5 10 15 20 25 30
-:_s1_p7_1 44c6_s1/res_part7_pass1.vqd, 2, nonseq cull, 0 +- 1 2
-:_s2_p7_0 44c6_s2/res_part7_pass0.vqd, 2, nonseq cull, 0 +- 5 10 15 20 25 30
-:_s2_p7_1 44c6_s2/res_part7_pass1.vqd, 2, nonseq cull, 0 +- 1 2
-:_s3_p7_0 44c6_s3/res_part7_pass0.vqd, 2, nonseq cull, 0 +- 5 10 15 20 25 30
-:_s3_p7_1 44c6_s3/res_part7_pass1.vqd, 2, nonseq cull, 0 +- 1 2
-
-:_s0_p8_0 44c6_s0/res_part8_pass0.vqd, 2, nonseq cull, 0 +- 13 26 39 52 65 78
-:_s0_p8_1 44c6_s0/res_part8_pass1.vqd, 2, nonseq cull, 0 +- 1 2 3 4 5 6
-:_s1_p8_0 44c6_s1/res_part8_pass0.vqd, 2, nonseq cull, 0 +- 13 26 39 52 65 78
-:_s1_p8_1 44c6_s1/res_part8_pass1.vqd, 2, nonseq cull, 0 +- 1 2 3 4 5 6
-:_s2_p8_0 44c6_s2/res_part8_pass0.vqd, 2, nonseq cull, 0 +- 13 26 39 52 65 78
-:_s2_p8_1 44c6_s2/res_part8_pass1.vqd, 2, nonseq cull, 0 +- 1 2 3 4 5 6
-:_s3_p8_0 44c6_s3/res_part8_pass0.vqd, 2, nonseq cull, 0 +- 13 26 39 52 65 78
-:_s3_p8_1 44c6_s3/res_part8_pass1.vqd, 2, nonseq cull, 0 +- 1 2 3 4 5 6
-
-:_s0_p9_0 44c6_s0/res_part9_pass0.vqd, 2, nonseq, 0 +- 637 1274 1911 2548
-:_s0_p9_1 44c6_s0/res_part9_pass1.vqd, 2, nonseq, 0 +- 49 98 147 196 245 294
-:_s0_p9_2 44c6_s0/res_part9_pass2.vqd, 1, nonseq, 0 +- 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
-:_s1_p9_0 44c6_s1/res_part9_pass0.vqd, 2, nonseq, 0 +- 637 1274 1911 2548
-:_s1_p9_1 44c6_s1/res_part9_pass1.vqd, 2, nonseq, 0 +- 49 98 147 196 245 294
-:_s1_p9_2 44c6_s1/res_part9_pass2.vqd, 1, nonseq, 0 +- 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
-:_s2_p9_0 44c6_s2/res_part9_pass0.vqd, 2, nonseq, 0 +- 637 1274 1911 2548
-:_s2_p9_1 44c6_s2/res_part9_pass1.vqd, 2, nonseq, 0 +- 49 98 147 196 245 294
-:_s2_p9_2 44c6_s2/res_part9_pass2.vqd, 1, nonseq, 0 +- 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
-:_s3_p9_0 44c6_s3/res_part9_pass0.vqd, 2, nonseq, 0 +- 637 1274 1911 2548
-:_s3_p9_1 44c6_s3/res_part9_pass1.vqd, 2, nonseq, 0 +- 49 98 147 196 245 294
-:_s3_p9_2 44c6_s3/res_part9_pass2.vqd, 1, nonseq, 0 +- 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
diff --git a/vq/44c7.vqs b/vq/44c7.vqs
deleted file mode 100644
index 4105a459..00000000
--- a/vq/44c7.vqs
+++ /dev/null
@@ -1,57 +0,0 @@
-cp 44c7_s0/resaux_short.vqd _44c7_short.vqd
-cp 44c7_s0/resaux_long.vqd _44c7_long.vqd
-
-GO
-
->_44c7s noninterleaved
-haux _44c7_short.vqd 0,16,2
-
->_44c7 noninterleaved
-haux _44c7_long.vqd 0,64,2
-
-#iter 0
-
-# 0 8 42 1 2 4 8 16 56 +
-# 0 0 0
-
-# 0 1 2 3 4 5 6 7 8 9
-# 1 . . . . . .
-# 2 . . . . . .
-# 4 . . . .
-
-
-:_s0_p1_0 44c7_s0/res_part1_pass0.vqd, 2, nonseq cull, 0 +- 3 6 19 12 15
-:_s0_p1_1 44c7_s0/res_part1_pass1.vqd, 2, nonseq cull, 0 +- 1
-
-:_s0_p2_0 44c7_s0/res_part2_pass0.vqd, 2, nonseq cull, 0 +- 13 26 39 52 65 78
-:_s0_p2_1 44c7_s0/res_part2_pass1.vqd, 2, nonseq cull, 0 +- 1 2 3 4 5 6
-
-:_s0_p3_0 44c7_s0/res_part3_pass2.vqd, 4, nonseq cull, 0 +- 1 2
-:_s0_p4_0 44c7_s0/res_part4_pass2.vqd, 2, nonseq cull, 0 +- 1 2 3 4
-:_s0_p5_0 44c7_s0/res_part5_pass2.vqd, 2, nonseq cull, 0 +- 1 2 3 4 5 6 7 8
-
-:_s0_p6_0 44c7_s0/res_part6_pass0.vqd, 2, nonseq cull, 0 +- 3 6 19 12 15
-:_s0_p6_1 44c7_s0/res_part6_pass1.vqd, 2, nonseq cull, 0 +- 1
-
-:_s0_p7_0 44c7_s0/res_part7_pass0.vqd, 2, nonseq cull, 0 +- 5 10 15 20 25 30
-:_s0_p7_1 44c7_s0/res_part7_pass1.vqd, 2, nonseq cull, 0 +- 1 2
-
-:_s0_p8_0 44c7_s0/res_part8_pass0.vqd, 2, nonseq cull, 0 +- 15 30 45 60 75 90 105
-:_s0_p8_1 44c7_s0/res_part8_pass1.vqd, 2, nonseq cull, 0 +- 1 2 3 4 5 6 7
-
-:_s0_p9_0 44c7_s0/res_part9_pass0.vqd, 2, nonseq, 0 +- 637 1274 1911 2548
-:_s0_p9_1 44c7_s0/res_part9_pass1.vqd, 2, nonseq, 0 +- 49 98 147 196 245 294
-:_s0_p9_2 44c7_s0/res_part9_pass2.vqd, 1, nonseq, 0 +- 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
-
-#iter 1
-
-:_s0_p0_r0 44cH_s0/res_part0_r0.vqd, 2, nonseq, 0 +- .333333333 .666666667
-:_s0_pN_r0 44cH_s0/res_partN_r0.vqd, 2, nonseq, 0 +- .333333333 .666666667
-
-#iter 2
-
-:_s0_p0_r1 44cH_s0/res_part0_r1.vqd, 2, nonseq, 0 +- .111111111 .222222222
-:_s0_pN_r1 44cH_s0/res_partN_r1.vqd, 2, nonseq, 0 +- .111111111 .222222222
-
-
-
diff --git a/vq/44c8.vqs b/vq/44c8.vqs
deleted file mode 100644
index 0d045c46..00000000
--- a/vq/44c8.vqs
+++ /dev/null
@@ -1,44 +0,0 @@
-cp 44c8_s0/resaux_short.vqd _44c8_short.vqd
-cp 44c8_s0/resaux_long.vqd _44c8_long.vqd
-
-GO
-
->_44c8s noninterleaved
-haux _44c8_short.vqd 0,16,2
-
->_44c8 noninterleaved
-haux _44c8_long.vqd 0,64,2
-
-#iter 0
-
-# 0 8 42 1 2 4 8 16 56 +
-# 0 0 0
-
-# 0 1 2 3 4 5 6 7 8 9
-# 1 . . . . . .
-# 2 . . . . . .
-# 4 . . . .
-
-
-:_s0_p1_0 44c8_s0/res_part1_pass0.vqd, 2, nonseq cull, 0 +- 3 6 19 12 15
-:_s0_p1_1 44c8_s0/res_part1_pass1.vqd, 2, nonseq cull, 0 +- 1
-
-:_s0_p2_0 44c8_s0/res_part2_pass0.vqd, 2, nonseq cull, 0 +- 13 26 39 52 65 78
-:_s0_p2_1 44c8_s0/res_part2_pass1.vqd, 2, nonseq cull, 0 +- 1 2 3 4 5 6
-
-:_s0_p3_0 44c8_s0/res_part3_pass2.vqd, 4, nonseq cull, 0 +- 1 2
-:_s0_p4_0 44c8_s0/res_part4_pass2.vqd, 2, nonseq cull, 0 +- 1 2 3 4
-:_s0_p5_0 44c8_s0/res_part5_pass2.vqd, 2, nonseq cull, 0 +- 1 2 3 4 5 6 7 8
-
-:_s0_p6_0 44c8_s0/res_part6_pass0.vqd, 2, nonseq cull, 0 +- 3 6 19 12 15
-:_s0_p6_1 44c8_s0/res_part6_pass1.vqd, 2, nonseq cull, 0 +- 1
-
-:_s0_p7_0 44c8_s0/res_part7_pass0.vqd, 2, nonseq cull, 0 +- 5 10 15 20 25 30
-:_s0_p7_1 44c8_s0/res_part7_pass1.vqd, 2, nonseq cull, 0 +- 1 2
-
-:_s0_p8_0 44c8_s0/res_part8_pass0.vqd, 2, nonseq cull, 0 +- 15 30 45 60 75 90 105
-:_s0_p8_1 44c8_s0/res_part8_pass1.vqd, 2, nonseq cull, 0 +- 1 2 3 4 5 6 7
-
-:_s0_p9_0 44c8_s0/res_part9_pass0.vqd, 2, nonseq, 0 +- 637 1274 1911 2548 3185
-:_s0_p9_1 44c8_s0/res_part9_pass1.vqd, 2, nonseq, 0 +- 49 98 147 196 245 294
-:_s0_p9_2 44c8_s0/res_part9_pass2.vqd, 1, nonseq, 0 +- 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
diff --git a/vq/44c9.vqs b/vq/44c9.vqs
deleted file mode 100644
index 4de5a928..00000000
--- a/vq/44c9.vqs
+++ /dev/null
@@ -1,44 +0,0 @@
-cp 44c9_s0/resaux_short.vqd _44c9_short.vqd
-cp 44c9_s0/resaux_long.vqd _44c9_long.vqd
-
-GO
-
->_44c9s noninterleaved
-haux _44c9_short.vqd 0,16,2
-
->_44c9 noninterleaved
-haux _44c9_long.vqd 0,64,2
-
-#iter 0
-
-# 0 8 42 1 2 4 8 16 56 +
-# 0 0 0
-
-# 0 1 2 3 4 5 6 7 8 9
-# 1 . . . . . .
-# 2 . . . . . .
-# 4 . . . .
-
-
-:_s0_p1_0 44c9_s0/res_part1_pass0.vqd, 2, nonseq cull, 0 +- 3 6 19 12 15
-:_s0_p1_1 44c9_s0/res_part1_pass1.vqd, 2, nonseq cull, 0 +- 1
-
-:_s0_p2_0 44c9_s0/res_part2_pass0.vqd, 2, nonseq cull, 0 +- 13 26 39 52 65 78
-:_s0_p2_1 44c9_s0/res_part2_pass1.vqd, 2, nonseq cull, 0 +- 1 2 3 4 5 6
-
-:_s0_p3_0 44c9_s0/res_part3_pass2.vqd, 4, nonseq cull, 0 +- 1 2
-:_s0_p4_0 44c9_s0/res_part4_pass2.vqd, 2, nonseq cull, 0 +- 1 2 3 4
-:_s0_p5_0 44c9_s0/res_part5_pass2.vqd, 2, nonseq cull, 0 +- 1 2 3 4 5 6 7 8
-
-:_s0_p6_0 44c9_s0/res_part6_pass0.vqd, 2, nonseq cull, 0 +- 3 6 19 12 15
-:_s0_p6_1 44c9_s0/res_part6_pass1.vqd, 2, nonseq cull, 0 +- 1
-
-:_s0_p7_0 44c9_s0/res_part7_pass0.vqd, 2, nonseq cull, 0 +- 5 10 15 20 25 30
-:_s0_p7_1 44c9_s0/res_part7_pass1.vqd, 2, nonseq cull, 0 +- 1 2
-
-:_s0_p8_0 44c9_s0/res_part8_pass0.vqd, 2, nonseq cull, 0 +- 15 30 45 60 75 90 105
-:_s0_p8_1 44c9_s0/res_part8_pass1.vqd, 2, nonseq cull, 0 +- 1 2 3 4 5 6 7
-
-:_s0_p9_0 44c9_s0/res_part9_pass0.vqd, 2, nonseq, 0 +- 1863 3726 5589 7452 9315 11178 13041 14904 16767 18630 20493
-:_s0_p9_1 44c9_s0/res_part9_pass1.vqd, 2, nonseq, 0 +- 81 162 243 324 405 486 567 648 729 810 891
-:_s0_p9_2 44c9_s0/res_part9_pass2.vqd, 1, nonseq, 0 +- 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
diff --git a/vq/44u0.vqs b/vq/44u0.vqs
deleted file mode 100644
index 8d4761ea..00000000
--- a/vq/44u0.vqs
+++ /dev/null
@@ -1,36 +0,0 @@
-
-GO
-
->_44u0 noninterleaved
-
-#iter 0
-
-# 0 1 2 4 26 1 4 +
-# 0 0 0 0
-#
-# 0 1 2 3 4 5 6 7
-# 1 . .
-# 2 . .
-# 4 . . . . . .
-
-:_p1_0 44u0/res_part1_pass2.vqd, 4, nonseq cull, 0 +- 1
-:_p2_0 44u0/res_part2_pass2.vqd, 4, nonseq cull, 0 +- 1 2
-:_p3_0 44u0/res_part3_pass2.vqd, 2, nonseq cull, 0 +- 1 2 3 4
-:_p4_0 44u0/res_part4_pass0.vqd, 2, nonseq , 0 +- 3 6 9 12 15 18 21 24 27
-:_p4_1 44u0/res_part4_pass1.vqd, 4, nonseq cull, 0 +- 1
-:_p5_0 44u0/res_part5_pass2.vqd, 4, nonseq cull, 0 +- 1
-:_p6_0 44u0/res_part6_pass2.vqd, 2, nonseq cull, 0 +- 1 2 3 4
-
-:_p7_0 44u0/res_part7_pass0.vqd, 2, nonseq, 0 +- 67 134
-:_p7_1 44u0/res_part7_pass1.vqd, 2, nonseq, 0 +- 3 6 9 12 15 18 21 24 27 30 33
-:_p7_2 44u0/res_part7_pass2.vqd, 4, nonseq, 0 +- 1
-
-#iter 1
-
-:_p0_r0 44u0/res_part0_pass3.vqd, 2, nonseq cull, 0 +- .33333333
-:_p1_r0 44u0/res_partN_pass3.vqd, 2, nonseq cull, 0 +- .33333333
-
-#iter 2
-
-:_p0_r1 44u0/res_part0_pass4.vqd, 2, nonseq cull, 0 +- .11111111
-:_p1_r1 44u0/res_partN_pass4.vqd, 2, nonseq cull, 0 +- .11111111
diff --git a/vq/44u4.vqs b/vq/44u4.vqs
deleted file mode 100644
index b955c004..00000000
--- a/vq/44u4.vqs
+++ /dev/null
@@ -1,37 +0,0 @@
-GO
-
->_44u4 noninterleaved
-
-
-#iter 0
-
-# 0 1 1 2 2 4 4 16 42 +
-# 0 0 0
-
-# 0 1 2 3 4 5 6 7 8 9
-# 1 . . .
-# 2 . . .
-# 4 . . . . . . .
-
-:_p1_0 44u4/res_part1_pass2.vqd, 4, nonseq cull, 0 +- 1
-:_p2_0 44u4/res_part2_pass2.vqd, 4, nonseq cull, 0 +- 1
-:_p3_0 44u4/res_part3_pass2.vqd, 4, nonseq cull, 0 +- 1 2
-:_p4_0 44u4/res_part4_pass2.vqd, 4, nonseq cull, 0 +- 1 2
-:_p5_0 44u4/res_part5_pass2.vqd, 2, nonseq cull, 0 +- 1 2 3 4
-:_p6_0 44u4/res_part6_pass2.vqd, 2, nonseq cull, 0 +- 1 2 3 4
-:_p7_0 44u4/res_part7_pass0.vqd, 2, nonseq cull, 0 +- 3 6 9 12 15
-:_p7_1 44u4/res_part7_pass1.vqd, 4, nonseq cull, 0 +- 1
-:_p8_0 44u4/res_part8_pass0.vqd, 2, nonseq cull, 0 +- 5 10 15 20 25 30 35 40
-:_p8_1 44u4/res_part8_pass1.vqd, 4, nonseq cull, 0 +- 1 2
-:_p9_0 44u4/res_part9_pass0.vqd, 2, nonseq, 0 +- 637 1274 1911
-:_p9_1 44u4/res_part9_pass1.vqd, 2, nonseq, 0 +- 49 98 147 196 245 294
-:_p9_2 44u4/res_part9_pass2.vqd, 1, nonseq, 0 +- 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
-#iter 1
-
-:_p0_r0 44u4/res_part0_pass3.vqd, 2, nonseq cull, 0 +- .33333333
-:_p1_r0 44u4/res_partN_pass3.vqd, 2, nonseq cull, 0 +- .33333333
-
-#iter 2
-
-:_p0_r1 44u4/res_part0_pass4.vqd, 2, nonseq cull, 0 +- .11111111
-:_p1_r1 44u4/res_partN_pass4.vqd, 2, nonseq cull, 0 +- .11111111
diff --git a/vq/44u7.vqs b/vq/44u7.vqs
deleted file mode 100644
index 65303ac9..00000000
--- a/vq/44u7.vqs
+++ /dev/null
@@ -1,40 +0,0 @@
-GO
-
->_44u7 noninterleaved
-
-# 0 8 42 1 2 4 8 16 59 +
-# 0 0 0
-
-# 0 1 2 3 4 5 6 7 8 9
-# 1 . . . .
-# 2 . . . .
-# 4 . . . . . .
-
-:_p1_0 44u7/res_part1_pass2.vqd, 2, nonseq cull, 0 +- 1 2 3 4 5 6 7 8
-:_p2_0 44u7/res_part2_pass0.vqd, 2, nonseq cull, 0 +- 5 10 15 20 25 30 35 40
-:_p2_1 44u7/res_part2_pass1.vqd, 4, nonseq cull, 0 +- 1 2
-
-:_p3_0 44u7/res_part3_pass2.vqd, 4, nonseq cull, 0 +- 1
-:_p4_0 44u7/res_part4_pass2.vqd, 4, nonseq cull, 0 +- 1 2
-:_p5_0 44u7/res_part5_pass2.vqd, 2, nonseq cull, 0 +- 1 2 3 4
-:_p6_0 44u7/res_part6_pass2.vqd, 2, nonseq cull, 0 +- 1 2 3 4 5 6 7 8
-:_p7_0 44u7/res_part7_pass0.vqd, 2, nonseq cull, 0 +- 3 6 9 12 15
-:_p7_1 44u7/res_part7_pass1.vqd, 4, nonseq cull, 0 +- 1
-
-:_p8_0 44u7/res_part8_pass0.vqd, 2, nonseq cull, 0 +- 7 14 21 28 35 42 49 56
-:_p8_1 44u7/res_part8_pass1.vqd, 2, nonseq cull, 0 +- 1 2 3
-
-
-:_p9_0 44u7/res_part9_pass0.vqd, 2, nonseq, 0 +- 1863 3726 5589 7452 9315 11178 13041
-:_p9_1 44u7/res_part9_pass1.vqd, 2, nonseq, 0 +- 81 162 243 324 405 486 567 648 729 810 891
-:_p9_2 44u7/res_part9_pass2.vqd, 1, nonseq, 0 +- 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
-
-#iter 1
-
-:_p0_r0 44u7/res_part0_pass3.vqd, 2, nonseq cull, 0 +- .33333333
-:_p1_r0 44u7/res_partN_pass3.vqd, 2, nonseq cull, 0 +- .33333333
-
-#iter 2
-
-:_p0_r1 44u7/res_part0_pass4.vqd, 2, nonseq cull, 0 +- .11111111
-:_p1_r1 44u7/res_partN_pass4.vqd, 2, nonseq cull, 0 +- .11111111
diff --git a/vq/Makefile.am b/vq/Makefile.am
deleted file mode 100644
index 232b64c2..00000000
--- a/vq/Makefile.am
+++ /dev/null
@@ -1,51 +0,0 @@
-## Process this file with automake to produce Makefile.in
-
-AUTOMAKE_OPTIONS = foreign
-
-INCLUDES = -I../lib -I$(top_srcdir)/include @OGG_CFLAGS@
-
-EXTRA_PROGRAMS = lspvqtrain genericvqtrain residuevqtrain vqbuild\
- vqcascade vqmetrics latticebuild latticepare latticehint\
- latticetune huffbuild residuesplit distribution
-CLEANFILES = $(EXTRA_PROGRAMS)
-
-LDFLAGS = -static
-LDADD = ../lib/libvorbis.la
-
-lspvqtrain_SOURCES = lspdata.c train.c vqgen.c bookutil.c\
- vqgen.h bookutil.h vqext.h
-genericvqtrain_SOURCES = genericdata.c train.c vqgen.c bookutil.c\
- vqgen.h bookutil.h vqext.h
-residuevqtrain_SOURCES = residuedata.c train.c vqgen.c bookutil.c\
- vqgen.h bookutil.h vqext.h
-vqbuild_SOURCES = build.c vqgen.c bookutil.c vqsplit.c\
- vqgen.h bookutil.h vqext.h
-vqcascade_SOURCES = run.c cascade.c vqgen.c bookutil.c\
- vqgen.h bookutil.h
-vqmetrics_SOURCES = run.c metrics.c vqgen.c bookutil.c\
- vqgen.h bookutil.h
-latticebuild_SOURCES = latticebuild.c vqgen.c bookutil.c\
- vqgen.h bookutil.h
-latticepare_SOURCES = latticepare.c vqgen.c bookutil.c vqsplit.c\
- vqgen.h bookutil.h
-latticehint_SOURCES = latticehint.c bookutil.c\
- bookutil.h
-latticetune_SOURCES = latticetune.c vqgen.c bookutil.c\
- vqgen.h bookutil.h
-huffbuild_SOURCES = huffbuild.c vqgen.c bookutil.c\
- vqgen.h bookutil.h
-residuesplit_SOURCES = residuesplit.c vqgen.c bookutil.c\
- vqgen.h bookutil.h
-distribution_SOURCES = distribution.c bookutil.c\
- bookutil.h
-
-EXTRA_DIST = residue_entropy auxpartition.pl
-
-debugvq:
- $(MAKE) vq CFLAGS="@DEBUG@"
-
-profilevq:
- $(MAKE) vq CFLAGS="@PROFILE@"
-
-vq:
- $(MAKE) $(EXTRA_PROGRAMS)
diff --git a/vq/auxpartition.pl b/vq/auxpartition.pl
deleted file mode 100755
index 05c5ed94..00000000
--- a/vq/auxpartition.pl
+++ /dev/null
@@ -1,71 +0,0 @@
-#!/usr/bin/perl
-
-if($#ARGV<0){
- &usage;
-}
-
-$|=1;
-
-$bands=0;
-
-foreach $arg (@ARGV){
- ($entries[$bands],$file[$bands])=split(/,/,$arg);
- $bands++;
-}
-
-# no time to deal with globs right now
-if($bands>0){
- die unless open(ONE,"<".$file[0]);
-}
-if($bands>1){
- die unless open(TWO,"<".$file[1]);
-}
-if($bands>2){
- die unless open(THREE,"<".$file[2]);
-}
-
-
-while (<ONE>) {
- my@nums = ();
- @nums = split(/,/);
- my$cols=$#nums;
- for($i=0;$i<$cols;$i++){
- print 0+$nums[$i].", ";
- }
- if($bands>1){
- $_=<TWO>;
- @nums = ();
- @nums = split(/,/);
- $cols=$#nums;
- for($i=0;$i<$cols;$i++){
- print $nums[$i]+$entries[0].", ";
- }
- if($bands>2){
- $_=<THREE>;
- @nums = ();
- @nums = split(/,/);
- $cols=$#nums;
- for($i=0;$i<$cols;$i++){
- print $nums[$i]+$entries[0]+$entries[1].", ";
- }
- }
- }
- print "\n";
-
-}
-
-if($bands>0){
- close ONE;
-}
-if($bands>1){
- close TWO;
-}
-if($bands>2){
- close THREE;
-}
-
-sub usage{
- print "\nOggVorbis auxbook spectral partitioner\n\n";
- print "auxpartition.pl <part_entries>,file [<part_entries>,file...]\n\n";
- exit(1);
-}
diff --git a/vq/bookutil.c b/vq/bookutil.c
deleted file mode 100644
index 9503e3cf..00000000
--- a/vq/bookutil.c
+++ /dev/null
@@ -1,738 +0,0 @@
-/********************************************************************
- * *
- * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *
- * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
- * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
- * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
- * *
- * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2001 *
- * by the XIPHOPHORUS Company http://www.xiph.org/ *
- * *
- ********************************************************************
-
- function: utility functions for loading .vqh and .vqd files
- last mod: $Id: bookutil.c,v 1.26 2001/12/20 01:00:39 segher Exp $
-
- ********************************************************************/
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <math.h>
-#include <string.h>
-#include <errno.h>
-#include "bookutil.h"
-
-/* A few little utils for reading files */
-/* read a line. Use global, persistent buffering */
-static char *linebuffer=NULL;
-static int lbufsize=0;
-char *get_line(FILE *in){
- long sofar=0;
- if(feof(in))return NULL;
-
- while(1){
- int gotline=0;
-
- while(!gotline){
- if(sofar+1>=lbufsize){
- if(!lbufsize){
- lbufsize=1024;
- linebuffer=_ogg_malloc(lbufsize);
- }else{
- lbufsize*=2;
- linebuffer=_ogg_realloc(linebuffer,lbufsize);
- }
- }
- {
- long c=fgetc(in);
- switch(c){
- case EOF:
- if(sofar==0)return(NULL);
- /* fallthrough correct */
- case '\n':
- linebuffer[sofar]='\0';
- gotline=1;
- break;
- default:
- linebuffer[sofar++]=c;
- linebuffer[sofar]='\0';
- break;
- }
- }
- }
-
- if(linebuffer[0]=='#'){
- sofar=0;
- }else{
- return(linebuffer);
- }
- }
-}
-
-/* read the next numerical value from the given file */
-static char *value_line_buff=NULL;
-
-int get_line_value(FILE *in,float *value){
- char *next;
-
- if(!value_line_buff)return(-1);
-
- *value=strtod(value_line_buff, &next);
- if(next==value_line_buff){
- value_line_buff=NULL;
- return(-1);
- }else{
- value_line_buff=next;
- while(*value_line_buff>44)value_line_buff++;
- if(*value_line_buff==44)value_line_buff++;
- return(0);
- }
-}
-
-int get_next_value(FILE *in,float *value){
- while(1){
- if(get_line_value(in,value)){
- value_line_buff=get_line(in);
- if(!value_line_buff)return(-1);
- }else{
- return(0);
- }
- }
-}
-
-int get_next_ivalue(FILE *in,long *ivalue){
- float value;
- int ret=get_next_value(in,&value);
- *ivalue=value;
- return(ret);
-}
-
-static float sequence_base=0.f;
-static int v_sofar=0;
-void reset_next_value(void){
- value_line_buff=NULL;
- sequence_base=0.f;
- v_sofar=0;
-}
-
-char *setup_line(FILE *in){
- reset_next_value();
- value_line_buff=get_line(in);
- return(value_line_buff);
-}
-
-
-int get_vector(codebook *b,FILE *in,int start, int n,float *a){
- int i;
- const static_codebook *c=b->c;
-
- while(1){
-
- if(v_sofar==n || get_line_value(in,a)){
- reset_next_value();
- if(get_next_value(in,a))
- break;
- for(i=0;i<start;i++){
- sequence_base=*a;
- get_line_value(in,a);
- }
- }
-
- for(i=1;i<c->dim;i++)
- if(get_line_value(in,a+i))
- break;
-
- if(i==c->dim){
- float temp=a[c->dim-1];
- for(i=0;i<c->dim;i++)a[i]-=sequence_base;
- if(c->q_sequencep)sequence_base=temp;
- v_sofar++;
- return(0);
- }
- sequence_base=0.f;
- }
-
- return(-1);
-}
-
-/* read lines fromt he beginning until we find one containing the
- specified string */
-char *find_seek_to(FILE *in,char *s){
- rewind(in);
- while(1){
- char *line=get_line(in);
- if(line){
- if(strstr(line,s))
- return(line);
- }else
- return(NULL);
- }
-}
-
-
-/* this reads the format as written by vqbuild/latticebuild; innocent
- (legal) tweaking of the file that would not affect its valid
- header-ness will break this routine */
-
-codebook *codebook_load(char *filename){
- codebook *b=_ogg_calloc(1,sizeof(codebook));
- static_codebook *c=(static_codebook *)(b->c=_ogg_calloc(1,sizeof(static_codebook)));
- encode_aux_nearestmatch *a=NULL;
- encode_aux_threshmatch *t=NULL;
- encode_aux_pigeonhole *p=NULL;
- int quant_to_read=0;
- FILE *in=fopen(filename,"r");
- char *line;
- long i;
-
- if(in==NULL){
- fprintf(stderr,"Couldn't open codebook %s\n",filename);
- exit(1);
- }
-
- /* find the codebook struct */
- find_seek_to(in,"static static_codebook ");
-
- /* get the major important values */
- line=get_line(in);
- if(sscanf(line,"%ld, %ld,",
- &(c->dim),&(c->entries))!=2){
- fprintf(stderr,"1: syntax in %s in line:\t %s",filename,line);
- exit(1);
- }
- line=get_line(in);
- line=get_line(in);
- if(sscanf(line,"%d, %ld, %ld, %d, %d,",
- &(c->maptype),&(c->q_min),&(c->q_delta),&(c->q_quant),
- &(c->q_sequencep))!=5){
- fprintf(stderr,"1: syntax in %s in line:\t %s",filename,line);
- exit(1);
- }
-
- /* find the auxiliary encode struct[s] (if any) */
- if(find_seek_to(in,"static encode_aux_nearestmatch _vq_aux")){
- /* how big? */
- c->nearest_tree=a=_ogg_calloc(1,sizeof(encode_aux_nearestmatch));
- line=get_line(in);
- line=get_line(in);
- line=get_line(in);
- line=get_line(in);
- line=get_line(in);
- if(sscanf(line,"%ld, %ld",&(a->aux),&(a->alloc))!=2){
- fprintf(stderr,"2: syntax in %s in line:\t %s",filename,line);
- exit(1);
- }
-
- /* load ptr0 */
- find_seek_to(in,"static long _vq_ptr0");
- reset_next_value();
- a->ptr0=_ogg_malloc(sizeof(long)*a->aux);
- for(i=0;i<a->aux;i++)
- if(get_next_ivalue(in,a->ptr0+i)){
- fprintf(stderr,"out of data while reading codebook %s\n",filename);
- exit(1);
- }
-
- /* load ptr1 */
- find_seek_to(in,"static long _vq_ptr1");
- reset_next_value();
- a->ptr1=_ogg_malloc(sizeof(long)*a->aux);
- for(i=0;i<a->aux;i++)
- if(get_next_ivalue(in,a->ptr1+i)){
- fprintf(stderr,"out of data while reading codebook %s\n",filename);
- exit(1);
- }
-
-
- /* load p */
- find_seek_to(in,"static long _vq_p_");
- reset_next_value();
- a->p=_ogg_malloc(sizeof(long)*a->aux);
- for(i=0;i<a->aux;i++)
- if(get_next_ivalue(in,a->p+i)){
- fprintf(stderr,"out of data while reading codebook %s\n",filename);
- exit(1);
- }
-
- /* load q */
- find_seek_to(in,"static long _vq_q_");
- reset_next_value();
- a->q=_ogg_malloc(sizeof(long)*a->aux);
- for(i=0;i<a->aux;i++)
- if(get_next_ivalue(in,a->q+i)){
- fprintf(stderr,"out of data while reading codebook %s\n",filename);
- exit(1);
- }
- }
-
- if(find_seek_to(in,"static encode_aux_threshmatch _vq_aux")){
- /* how big? */
- c->thresh_tree=t=_ogg_calloc(1,sizeof(encode_aux_threshmatch));
- line=get_line(in);
- line=get_line(in);
- line=get_line(in);
- if(sscanf(line,"%d",&(t->quantvals))!=1){
- fprintf(stderr,"3: syntax in %s in line:\t %s",filename,line);
- exit(1);
- }
- line=get_line(in);
- if(sscanf(line,"%d",&(t->threshvals))!=1){
- fprintf(stderr,"4: syntax in %s in line:\t %s",filename,line);
- exit(1);
- }
- /* load quantthresh */
- find_seek_to(in,"static float _vq_quantthresh_");
- reset_next_value();
- t->quantthresh=_ogg_malloc(sizeof(float)*t->threshvals);
- for(i=0;i<t->threshvals-1;i++)
- if(get_next_value(in,t->quantthresh+i)){
- fprintf(stderr,"out of data 1 while reading codebook %s\n",filename);
- exit(1);
- }
- /* load quantmap */
- find_seek_to(in,"static long _vq_quantmap_");
- reset_next_value();
- t->quantmap=_ogg_malloc(sizeof(long)*t->threshvals);
- for(i=0;i<t->threshvals;i++)
- if(get_next_ivalue(in,t->quantmap+i)){
- fprintf(stderr,"out of data 2 while reading codebook %s\n",filename);
- exit(1);
- }
- }
-
- if(find_seek_to(in,"static encode_aux_pigeonhole _vq_aux")){
- int pigeons=1,i;
- /* how big? */
- c->pigeon_tree=p=_ogg_calloc(1,sizeof(encode_aux_pigeonhole));
- line=get_line(in);
- if(sscanf(line,"%f, %f, %d, %d",&(p->min),&(p->del),
- &(p->mapentries),&(p->quantvals))!=4){
- fprintf(stderr,"5: syntax in %s in line:\t %s",filename,line);
- exit(1);
- }
- line=get_line(in);
- line=get_line(in);
- if(sscanf(line,"%ld",&(p->fittotal))!=1){
- fprintf(stderr,"6: syntax in %s in line:\t %s",filename,line);
- exit(1);
- }
- /* load pigeonmap */
- find_seek_to(in,"static long _vq_pigeonmap_");
- reset_next_value();
- p->pigeonmap=_ogg_malloc(sizeof(long)*p->mapentries);
- for(i=0;i<p->mapentries;i++)
- if(get_next_ivalue(in,p->pigeonmap+i)){
- fprintf(stderr,"out of data (pigeonmap) while reading codebook %s\n",filename);
- exit(1);
- }
- /* load fitlist */
- find_seek_to(in,"static long _vq_fitlist_");
- reset_next_value();
- p->fitlist=_ogg_malloc(sizeof(long)*p->fittotal);
- for(i=0;i<p->fittotal;i++)
- if(get_next_ivalue(in,p->fitlist+i)){
- fprintf(stderr,"out of data (fitlist) while reading codebook %s\n",filename);
- exit(1);
- }
- /* load fitmap */
- find_seek_to(in,"static long _vq_fitmap_");
- reset_next_value();
- for(i=0;i<c->dim;i++)pigeons*=p->quantvals;
- p->fitmap=_ogg_malloc(sizeof(long)*pigeons);
- for(i=0;i<pigeons;i++)
- if(get_next_ivalue(in,p->fitmap+i)){
- fprintf(stderr,"out of data (fitmap) while reading codebook %s\n",filename);
- exit(1);
- }
-
- /* load fitlength */
- find_seek_to(in,"static long _vq_fitlength_");
- reset_next_value();
- p->fitlength=_ogg_malloc(sizeof(long)*pigeons);
- for(i=0;i<pigeons;i++)
- if(get_next_ivalue(in,p->fitlength+i)){
- fprintf(stderr,"out of data (fitlength) while reading codebook %s\n",filename);
- exit(1);
- }
- }
-
- switch(c->maptype){
- case 0:
- quant_to_read=0;
- break;
- case 1:
- quant_to_read=_book_maptype1_quantvals(c);
- break;
- case 2:
- quant_to_read=c->entries*c->dim;
- break;
- }
-
- /* load the quantized entries */
- find_seek_to(in,"static long _vq_quantlist_");
- reset_next_value();
- c->quantlist=_ogg_malloc(sizeof(long)*quant_to_read);
- for(i=0;i<quant_to_read;i++)
- if(get_next_ivalue(in,c->quantlist+i)){
- fprintf(stderr,"out of data while reading codebook %s\n",filename);
- exit(1);
- }
-
- /* load the lengthlist */
- find_seek_to(in,"_lengthlist");
- reset_next_value();
- c->lengthlist=_ogg_malloc(sizeof(long)*c->entries);
- for(i=0;i<c->entries;i++)
- if(get_next_ivalue(in,c->lengthlist+i)){
- fprintf(stderr,"out of data while reading codebook %s\n",filename);
- exit(1);
- }
-
- /* got it all */
- fclose(in);
-
- vorbis_book_init_encode(b,c);
-
- return(b);
-}
-
-void spinnit(char *s,int n){
- static int p=0;
- static long lasttime=0;
- long test;
- struct timeval thistime;
-
- gettimeofday(&thistime,NULL);
- test=thistime.tv_sec*10+thistime.tv_usec/100000;
- if(lasttime!=test){
- lasttime=test;
-
- fprintf(stderr,"%s%d ",s,n);
-
- p++;if(p>3)p=0;
- switch(p){
- case 0:
- fprintf(stderr,"| \r");
- break;
- case 1:
- fprintf(stderr,"/ \r");
- break;
- case 2:
- fprintf(stderr,"- \r");
- break;
- case 3:
- fprintf(stderr,"\\ \r");
- break;
- }
- fflush(stderr);
- }
-}
-
-void build_tree_from_lengths(int vals, long *hist, long *lengths){
- int i,j;
- long *membership=_ogg_malloc(vals*sizeof(long));
- long *histsave=alloca(vals*sizeof(long));
- memcpy(histsave,hist,vals*sizeof(long));
-
- for(i=0;i<vals;i++)membership[i]=i;
-
- /* find codeword lengths */
- /* much more elegant means exist. Brute force n^2, minimum thought */
- for(i=vals;i>1;i--){
- int first=-1,second=-1;
- long least=-1;
-
- spinnit("building... ",i);
-
- /* find the two nodes to join */
- for(j=0;j<vals;j++)
- if(least==-1 || hist[j]<least){
- least=hist[j];
- first=membership[j];
- }
- least=-1;
- for(j=0;j<vals;j++)
- if((least==-1 || hist[j]<least) && membership[j]!=first){
- least=hist[j];
- second=membership[j];
- }
- if(first==-1 || second==-1){
- fprintf(stderr,"huffman fault; no free branch\n");
- exit(1);
- }
-
- /* join them */
- least=hist[first]+hist[second];
- for(j=0;j<vals;j++)
- if(membership[j]==first || membership[j]==second){
- membership[j]=first;
- hist[j]=least;
- lengths[j]++;
- }
- }
- for(i=0;i<vals-1;i++)
- if(membership[i]!=membership[i+1]){
- fprintf(stderr,"huffman fault; failed to build single tree\n");
- exit(1);
- }
-
- /* for sanity check purposes: how many bits would it have taken to
- encode the training set? */
- {
- long bitsum=0;
- long samples=0;
- for(i=0;i<vals;i++){
- bitsum+=(histsave[i]-1)*lengths[i];
- samples+=histsave[i]-1;
- }
-
- if(samples){
- fprintf(stderr,"\rTotal samples in training set: %ld \n",samples);
- fprintf(stderr,"\rTotal bits used to represent training set: %ld\n",
- bitsum);
- }
- }
-
- free(membership);
-}
-
-/* wrap build_tree_from_lengths to allow zero entries in the histogram */
-void build_tree_from_lengths0(int vals, long *hist, long *lengths){
-
- /* pack the 'sparse' hit list into a dense list, then unpack
- the lengths after the build */
-
- int upper=0,i;
- long *lengthlist=_ogg_calloc(vals,sizeof(long));
- long *newhist=alloca(vals*sizeof(long));
-
- for(i=0;i<vals;i++)
- if(hist[i]>0)
- newhist[upper++]=hist[i];
-
- if(upper != vals){
- fprintf(stderr,"\rEliminating %d unused entries; %d entries remain\n",
- vals-upper,upper);
- }
-
- build_tree_from_lengths(upper,newhist,lengthlist);
-
- upper=0;
- for(i=0;i<vals;i++)
- if(hist[i]>0)
- lengths[i]=lengthlist[upper++];
- else
- lengths[i]=0;
-
- free(lengthlist);
-}
-
-void write_codebook(FILE *out,char *name,const static_codebook *c){
- encode_aux_pigeonhole *p=c->pigeon_tree;
- encode_aux_threshmatch *t=c->thresh_tree;
- encode_aux_nearestmatch *n=c->nearest_tree;
- int i,j,k;
-
- /* save the book in C header form */
- fprintf(out,
- "/********************************************************************\n"
- " * *\n"
- " * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *\n"
- " * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *\n"
- " * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *\n"
- " * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *\n"
- " * *\n"
- " * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2001 *\n"
- " * by the XIPHOPHORUS Company http://www.xiph.org/ *\n"
- " * *\n"
- " ********************************************************************\n"
- "\n"
- " function: static codebook autogenerated by vq/somethingorother\n"
- "\n"
- " ********************************************************************/\n\n");
-
- fprintf(out,"#ifndef _V_%s_VQH_\n#define _V_%s_VQH_\n",name,name);
- fprintf(out,"#include \"codebook.h\"\n\n");
-
- /* first, the static vectors, then the book structure to tie it together. */
- /* quantlist */
- if(c->quantlist){
- long vals=(c->maptype==1?_book_maptype1_quantvals(c):c->entries*c->dim);
- fprintf(out,"static long _vq_quantlist_%s[] = {\n",name);
- for(j=0;j<vals;j++){
- fprintf(out,"\t%ld,\n",c->quantlist[j]);
- }
- fprintf(out,"};\n\n");
- }
-
- /* lengthlist */
- fprintf(out,"static long _vq_lengthlist_%s[] = {\n",name);
- for(j=0;j<c->entries;){
- fprintf(out,"\t");
- for(k=0;k<16 && j<c->entries;k++,j++)
- fprintf(out,"%2ld,",c->lengthlist[j]);
- fprintf(out,"\n");
- }
- fprintf(out,"};\n\n");
-
- if(t){
- /* quantthresh */
- fprintf(out,"static float _vq_quantthresh_%s[] = {\n",name);
- for(j=0;j<t->threshvals-1;){
- fprintf(out,"\t");
- for(k=0;k<8 && j<t->threshvals-1;k++,j++)
- fprintf(out,"%.5g, ",t->quantthresh[j]);
- fprintf(out,"\n");
- }
- fprintf(out,"};\n\n");
-
- /* quantmap */
- fprintf(out,"static long _vq_quantmap_%s[] = {\n",name);
- for(j=0;j<t->threshvals;){
- fprintf(out,"\t");
- for(k=0;k<8 && j<t->threshvals;k++,j++)
- fprintf(out,"%5ld,",t->quantmap[j]);
- fprintf(out,"\n");
- }
- fprintf(out,"};\n\n");
-
- fprintf(out,"static encode_aux_threshmatch _vq_auxt_%s = {\n",name);
- fprintf(out,"\t_vq_quantthresh_%s,\n",name);
- fprintf(out,"\t_vq_quantmap_%s,\n",name);
- fprintf(out,"\t%d,\n",t->quantvals);
- fprintf(out,"\t%d\n};\n\n",t->threshvals);
- }
-
- if(p){
- int pigeons=1;
- for(i=0;i<c->dim;i++)pigeons*=p->quantvals;
-
- /* pigeonmap */
- fprintf(out,"static long _vq_pigeonmap_%s[] = {\n",name);
- for(j=0;j<p->mapentries;){
- fprintf(out,"\t");
- for(k=0;k<8 && j<p->mapentries;k++,j++)
- fprintf(out,"%5ld, ",p->pigeonmap[j]);
- fprintf(out,"\n");
- }
- fprintf(out,"};\n\n");
- /* fitlist */
- fprintf(out,"static long _vq_fitlist_%s[] = {\n",name);
- for(j=0;j<p->fittotal;){
- fprintf(out,"\t");
- for(k=0;k<8 && j<p->fittotal;k++,j++)
- fprintf(out,"%5ld, ",p->fitlist[j]);
- fprintf(out,"\n");
- }
- fprintf(out,"};\n\n");
- /* fitmap */
- fprintf(out,"static long _vq_fitmap_%s[] = {\n",name);
- for(j=0;j<pigeons;){
- fprintf(out,"\t");
- for(k=0;k<8 && j<pigeons;k++,j++)
- fprintf(out,"%5ld, ",p->fitmap[j]);
- fprintf(out,"\n");
- }
- fprintf(out,"};\n\n");
- /* fitlength */
- fprintf(out,"static long _vq_fitlength_%s[] = {\n",name);
- for(j=0;j<pigeons;){
- fprintf(out,"\t");
- for(k=0;k<8 && j<pigeons;k++,j++)
- fprintf(out,"%5ld, ",p->fitlength[j]);
- fprintf(out,"\n");
- }
- fprintf(out,"};\n\n");
-
- fprintf(out,"static encode_aux_pigeonhole _vq_auxp_%s = {\n",name);
- fprintf(out,"\t%g, %g, %d, %d,\n",
- p->min,p->del,p->mapentries,p->quantvals);
-
- fprintf(out,"\t_vq_pigeonmap_%s,\n",name);
-
- fprintf(out,"\t%ld,\n",p->fittotal);
- fprintf(out,"\t_vq_fitlist_%s,\n",name);
- fprintf(out,"\t_vq_fitmap_%s,\n",name);
- fprintf(out,"\t_vq_fitlength_%s\n};\n\n",name);
- }
-
- if(n){
-
- /* ptr0 */
- fprintf(out,"static long _vq_ptr0_%s[] = {\n",name);
- for(j=0;j<n->aux;){
- fprintf(out,"\t");
- for(k=0;k<8 && j<n->aux;k++,j++)
- fprintf(out,"%6ld,",n->ptr0[j]);
- fprintf(out,"\n");
- }
- fprintf(out,"};\n\n");
-
- /* ptr1 */
- fprintf(out,"static long _vq_ptr1_%s[] = {\n",name);
- for(j=0;j<n->aux;){
- fprintf(out,"\t");
- for(k=0;k<8 && j<n->aux;k++,j++)
- fprintf(out,"%6ld,",n->ptr1[j]);
- fprintf(out,"\n");
- }
- fprintf(out,"};\n\n");
-
- /* p */
- fprintf(out,"static long _vq_p_%s[] = {\n",name);
- for(j=0;j<n->aux;){
- fprintf(out,"\t");
- for(k=0;k<8 && j<n->aux;k++,j++)
- fprintf(out,"%6ld,",n->p[j]*c->dim);
- fprintf(out,"\n");
- }
- fprintf(out,"};\n\n");
-
- /* q */
- fprintf(out,"static long _vq_q_%s[] = {\n",name);
- for(j=0;j<n->aux;){
- fprintf(out,"\t");
- for(k=0;k<8 && j<n->aux;k++,j++)
- fprintf(out,"%6ld,",n->q[j]*c->dim);
- fprintf(out,"\n");
- }
- fprintf(out,"};\n\n");
-
- fprintf(out,"static encode_aux_nearestmatch _vq_auxn_%s = {\n",name);
- fprintf(out,"\t_vq_ptr0_%s,\n",name);
- fprintf(out,"\t_vq_ptr1_%s,\n",name);
- fprintf(out,"\t_vq_p_%s,\n",name);
- fprintf(out,"\t_vq_q_%s,\n",name);
- fprintf(out,"\t%ld, %ld\n};\n\n",n->aux,n->aux);
- }
-
- /* tie it all together */
-
- fprintf(out,"static static_codebook %s = {\n",name);
-
- fprintf(out,"\t%ld, %ld,\n",c->dim,c->entries);
- fprintf(out,"\t_vq_lengthlist_%s,\n",name);
- fprintf(out,"\t%d, %ld, %ld, %d, %d,\n",
- c->maptype,c->q_min,c->q_delta,c->q_quant,c->q_sequencep);
- if(c->quantlist)
- fprintf(out,"\t_vq_quantlist_%s,\n",name);
- else
- fprintf(out,"\tNULL,\n");
-
- if(n)
- fprintf(out,"\t&_vq_auxn_%s,\n",name);
- else
- fprintf(out,"\tNULL,\n");
- if(t)
- fprintf(out,"\t&_vq_auxt_%s,\n",name);
- else
- fprintf(out,"\tNULL,\n");
- if(p)
- fprintf(out,"\t&_vq_auxp_%s,\n",name);
- else
- fprintf(out,"\tNULL,\n");
-
- fprintf(out,"\t0\n};\n\n");
-
- fprintf(out,"\n#endif\n");
-}
diff --git a/vq/bookutil.h b/vq/bookutil.h
deleted file mode 100644
index 957df1d9..00000000
--- a/vq/bookutil.h
+++ /dev/null
@@ -1,43 +0,0 @@
-/********************************************************************
- * *
- * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *
- * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
- * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
- * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
- * *
- * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2001 *
- * by the XIPHOPHORUS Company http://www.xiph.org/ *
- * *
- ********************************************************************
-
- function: utility functions for loading .vqh and .vqd files
- last mod: $Id: bookutil.h,v 1.12 2001/12/20 01:00:39 segher Exp $
-
- ********************************************************************/
-
-#ifndef _V_BOOKUTIL_H_
-#define _V_BOOKUTIL_H_
-
-#include <stdio.h>
-#include <sys/time.h>
-
-#include "codebook.h"
-
-extern char *get_line(FILE *in);
-extern char *setup_line(FILE *in);
-extern int get_line_value(FILE *in,float *value);
-extern int get_next_value(FILE *in,float *value);
-extern int get_next_ivalue(FILE *in,long *ivalue);
-extern void reset_next_value(void);
-extern int get_vector(codebook *b,FILE *in,int start,int num,float *a);
-extern char *find_seek_to(FILE *in,char *s);
-
-extern codebook *codebook_load(char *filename);
-extern void write_codebook(FILE *out,char *name,const static_codebook *c);
-
-extern void spinnit(char *s,int n);
-extern void build_tree_from_lengths(int vals, long *hist, long *lengths);
-extern void build_tree_from_lengths0(int vals, long *hist, long *lengths);
-
-#endif
-
diff --git a/vq/build.c b/vq/build.c
deleted file mode 100644
index 0ff1f790..00000000
--- a/vq/build.c
+++ /dev/null
@@ -1,195 +0,0 @@
-/********************************************************************
- * *
- * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *
- * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
- * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
- * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
- * *
- * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2001 *
- * by the XIPHOPHORUS Company http://www.xiph.org/ *
- * *
- ********************************************************************
-
- function: utility main for building codebooks from training sets
- last mod: $Id: build.c,v 1.21 2001/12/20 01:00:39 segher Exp $
-
- ********************************************************************/
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <math.h>
-#include <string.h>
-#include <errno.h>
-#include "bookutil.h"
-
-#include "vqgen.h"
-#include "vqsplit.h"
-
-static char *linebuffer=NULL;
-static int lbufsize=0;
-static char *rline(FILE *in,FILE *out){
- long sofar=0;
- if(feof(in))return NULL;
-
- while(1){
- int gotline=0;
-
- while(!gotline){
- if(sofar>=lbufsize){
- if(!lbufsize){
- lbufsize=1024;
- linebuffer=_ogg_malloc(lbufsize);
- }else{
- lbufsize*=2;
- linebuffer=_ogg_realloc(linebuffer,lbufsize);
- }
- }
- {
- long c=fgetc(in);
- switch(c){
- case '\n':
- case EOF:
- gotline=1;
- break;
- default:
- linebuffer[sofar++]=c;
- linebuffer[sofar]='\0';
- break;
- }
- }
- }
-
- if(linebuffer[0]=='#'){
- sofar=0;
- }else{
- return(linebuffer);
- }
- }
-}
-
-/* command line:
- buildvq file
-*/
-
-int main(int argc,char *argv[]){
- vqgen v;
- static_codebook c;
- codebook b;
- quant_meta q;
-
- long *quantlist=NULL;
- int entries=-1,dim=-1,aux=-1;
- FILE *out=NULL;
- FILE *in=NULL;
- char *line,*name;
- long i,j,k;
-
- b.c=&c;
-
- if(argv[1]==NULL){
- fprintf(stderr,"Need a trained data set on the command line.\n");
- exit(1);
- }
-
- {
- char *ptr;
- char *filename=strdup(argv[1]);
-
- in=fopen(filename,"r");
- if(!in){
- fprintf(stderr,"Could not open input file %s\n",filename);
- exit(1);
- }
-
- ptr=strrchr(filename,'-');
- if(ptr){
- *ptr='\0';
- name=strdup(filename);
- sprintf(ptr,".vqh");
- }else{
- name=strdup(filename);
- strcat(filename,".vqh");
- }
-
- out=fopen(filename,"w");
- if(out==NULL){
- fprintf(stderr,"Unable to open %s for writing\n",filename);
- exit(1);
- }
- }
-
- /* suck in the trained book */
-
- /* read book type, but it doesn't matter */
- line=rline(in,out);
-
- line=rline(in,out);
- if(sscanf(line,"%d %d %d",&entries,&dim,&aux)!=3){
- fprintf(stderr,"Syntax error reading book file\n");
- exit(1);
- }
-
- /* just use it to allocate mem */
- vqgen_init(&v,dim,0,entries,0.f,NULL,NULL,0);
-
- /* quant */
- line=rline(in,out);
- if(sscanf(line,"%ld %ld %d %d",&q.min,&q.delta,
- &q.quant,&q.sequencep)!=4){
- fprintf(stderr,"Syntax error reading book file\n");
- exit(1);
- }
-
- /* quantized entries */
- /* save quant data; we don't want to requantize later as our method
- is currently imperfect wrt repeated application */
- i=0;
- quantlist=_ogg_malloc(sizeof(long)*v.elements*v.entries);
- for(j=0;j<entries;j++){
- float a;
- for(k=0;k<dim;k++){
- line=rline(in,out);
- sscanf(line,"%f",&a);
- v.entrylist[i]=a;
- quantlist[i++]=rint(a);
- }
- }
-
- /* ignore bias */
- for(j=0;j<entries;j++)line=rline(in,out);
- free(v.bias);
- v.bias=NULL;
-
- /* training points */
- {
- float *b=alloca(sizeof(float)*(dim+aux));
- i=0;
- v.entries=0; /* hack to avoid reseeding */
- while(1){
- for(k=0;k<dim+aux;k++){
- line=rline(in,out);
- if(!line)break;
- sscanf(line,"%f",b+k);
- }
- if(feof(in))break;
- vqgen_addpoint(&v,b,NULL);
- }
- v.entries=entries;
- }
-
- fclose(in);
- vqgen_unquantize(&v,&q);
-
- /* build the book */
- vqsp_book(&v,&b,quantlist);
- c.q_min=q.min;
- c.q_delta=q.delta;
- c.q_quant=q.quant;
- c.q_sequencep=q.sequencep;
-
- /* save the book in C header form */
- write_codebook(out,name,b.c);
-
- fclose(out);
- exit(0);
-}
diff --git a/vq/cascade.c b/vq/cascade.c
deleted file mode 100644
index 7993f7a1..00000000
--- a/vq/cascade.c
+++ /dev/null
@@ -1,91 +0,0 @@
-/********************************************************************
- * *
- * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *
- * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
- * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
- * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
- * *
- * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2001 *
- * by the XIPHOPHORUS Company http://www.xiph.org/ *
- * *
- ********************************************************************
-
- function: function call to do simple data cascading
- last mod: $Id: cascade.c,v 1.13 2001/12/20 01:00:39 segher Exp $
-
- ********************************************************************/
-
-/* this one outputs residue to stdout. */
-
-#include <stdlib.h>
-#include <unistd.h>
-#include <math.h>
-#include "bookutil.h"
-
-/* set up metrics */
-
-float count=0.f;
-
-
-void process_preprocess(codebook **bs,char *basename){
-}
-
-void process_postprocess(codebook **b,char *basename){
- fprintf(stderr,"Done. \n");
-}
-
-float process_one(codebook *b,float *a,int dim,int step,int addmul,
- float base){
- int j;
-
- if(b->c->q_sequencep){
- float temp;
- for(j=0;j<dim;j++){
- temp=a[j*step];
- a[j*step]-=base;
- }
- base=temp;
- }
-
- vorbis_book_besterror(b,a,step,addmul);
-
- return base;
-}
-
-void process_vector(codebook **bs,int *addmul,int inter,float *a,int n){
- int i,bi=0;
- int booknum=0;
-
- while(*bs){
- float base=0.f;
- codebook *b=*bs;
- int dim=b->dim;
-
- if(inter){
- for(i=0;i<n/dim;i++)
- base=process_one(b,a+i,dim,n/dim,addmul[bi],base);
- }else{
- for(i=0;i<=n-dim;i+=dim)
- base=process_one(b,a+i,dim,1,addmul[bi],base);
- }
-
- bs++;
- booknum++;
- bi++;
- }
-
- for(i=0;i<n;i++)
- fprintf(stdout,"%f, ",a[i]);
- fprintf(stdout,"\n");
-
- if((long)(count++)%100)spinnit("working.... lines: ",count);
-}
-
-void process_usage(void){
- fprintf(stderr,
- "usage: vqcascade [-i] +|*<codebook>.vqh [ +|*<codebook.vqh> ]... \n"
- " datafile.vqd [datafile.vqd]...\n\n"
- " data can be taken on stdin. residual error data sent to\n"
- " stdout.\n\n");
-
-}
diff --git a/vq/distribution.c b/vq/distribution.c
deleted file mode 100644
index c65b36a4..00000000
--- a/vq/distribution.c
+++ /dev/null
@@ -1,248 +0,0 @@
-/********************************************************************
- * *
- * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *
- * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
- * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
- * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
- * *
- * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2001 *
- * by the XIPHOPHORUS Company http://www.xiph.org/ *
- * *
- ********************************************************************
-
- function: utility for finding the distribution in a data set
- last mod: $Id: distribution.c,v 1.9 2001/12/20 01:00:39 segher Exp $
-
- ********************************************************************/
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <math.h>
-#include <string.h>
-#include <errno.h>
-#include "bookutil.h"
-
-/* command line:
- distribution file.vqd
-*/
-
-int ascend(const void *a,const void *b){
- return(**((long **)a)-**((long **)b));
-}
-
-int main(int argc,char *argv[]){
- FILE *in;
- long lines=0;
- float min;
- float max;
- long bins=-1;
- int flag=0;
- long *countarray;
- long total=0;
- char *line;
-
- if(argv[1]==NULL){
- fprintf(stderr,"Usage: distribution {data.vqd [bins]| book.vqh} \n\n");
- exit(1);
- }
- if(argv[2]!=NULL)
- bins=atoi(argv[2])-1;
-
- in=fopen(argv[1],"r");
- if(!in){
- fprintf(stderr,"Could not open input file %s\n",argv[1]);
- exit(1);
- }
-
- if(strrchr(argv[1],'.') && strcmp(strrchr(argv[1],'.'),".vqh")==0){
- /* load/decode a book */
-
- codebook *b=codebook_load(argv[1]);
- static_codebook *c=(static_codebook *)(b->c);
- float delta;
- int i;
- fclose(in);
-
- switch(c->maptype){
- case 0:
- printf("entropy codebook only; no mappings\n");
- exit(0);
- break;
- case 1:
- bins=_book_maptype1_quantvals(c);
- break;
- case 2:
- bins=c->entries*c->dim;
- break;
- }
-
- max=min=_float32_unpack(c->q_min);
- delta=_float32_unpack(c->q_delta);
-
- for(i=0;i<bins;i++){
- float val=c->quantlist[i]*delta+min;
- if(val>max)max=val;
- }
-
- printf("Minimum scalar value: %f\n",min);
- printf("Maximum scalar value: %f\n",max);
-
- switch(c->maptype){
- case 1:
- {
- /* lattice codebook. dump it. */
- int j,k;
- long maxcount=0;
- long **sort=calloc(bins,sizeof(long *));
- long base=c->lengthlist[0];
- countarray=calloc(bins,sizeof(long));
-
- for(i=0;i<bins;i++)sort[i]=c->quantlist+i;
- qsort(sort,bins,sizeof(long *),ascend);
-
- for(i=0;i<b->entries;i++)
- if(c->lengthlist[i]>base)base=c->lengthlist[i];
-
- /* dump a full, correlated count */
- for(j=0;j<b->entries;j++){
- if(c->lengthlist[j]){
- int indexdiv=1;
- printf("%4d: ",j);
- for(k=0;k<b->dim;k++){
- int index= (j/indexdiv)%bins;
- printf("%+3.1f,", c->quantlist[index]*_float32_unpack(c->q_delta)+
- _float32_unpack(c->q_min));
- indexdiv*=bins;
- }
- printf("\t|");
- for(k=0;k<base-c->lengthlist[j];k++)printf("*");
- printf("\n");
- }
- }
-
- /* do a rough count */
- for(j=0;j<b->entries;j++){
- int indexdiv=1;
- for(k=0;k<b->dim;k++){
- if(c->lengthlist[j]){
- int index= (j/indexdiv)%bins;
- countarray[index]+=(1<<(base-c->lengthlist[j]));
- indexdiv*=bins;
- }
- }
- }
-
- /* dump the count */
-
- {
- long maxcount=0,i,j;
- for(i=0;i<bins;i++)
- if(countarray[i]>maxcount)maxcount=countarray[i];
-
- for(i=0;i<bins;i++){
- int ptr=sort[i]-c->quantlist;
- int stars=rint(50./maxcount*countarray[ptr]);
- printf("%+08f (%8ld) |",c->quantlist[ptr]*delta+min,countarray[ptr]);
- for(j=0;j<stars;j++)printf("*");
- printf("\n");
- }
- }
- }
- break;
- case 2:
- {
- /* trained, full mapping codebook. */
- printf("Can't do probability dump of a trained [type 2] codebook (yet)\n");
- }
- break;
- }
- }else{
- /* load/count a data file */
-
- /* do it the simple way; two pass. */
- line=setup_line(in);
- while(line){
- float code;
- char buf[80];
- lines++;
-
- sprintf(buf,"getting min/max (%.2f::%.2f). lines...",min,max);
- if(!(lines&0xff))spinnit(buf,lines);
-
- while(!flag && sscanf(line,"%f",&code)==1){
- line=strchr(line,',');
- min=max=code;
- flag=1;
- }
-
- while(line && sscanf(line,"%f",&code)==1){
- line=strchr(line,',');
- if(line)line++;
- if(code<min)min=code;
- if(code>max)max=code;
- }
-
- line=setup_line(in);
- }
-
- if(bins<1){
- if((int)(max-min)==min-max){
- bins=max-min;
- }else{
- bins=25;
- }
- }
-
- printf("\r \r");
- printf("Minimum scalar value: %f\n",min);
- printf("Maximum scalar value: %f\n",max);
-
- if(argv[2]){
-
- printf("\n counting hits into %ld bins...\n",bins+1);
- countarray=calloc(bins+1,sizeof(long));
-
- rewind(in);
- line=setup_line(in);
- while(line){
- float code;
- lines--;
- if(!(lines&0xff))spinnit("counting distribution. lines so far...",lines);
-
- while(line && sscanf(line,"%f",&code)==1){
- line=strchr(line,',');
- if(line)line++;
-
- code-=min;
- code/=(max-min);
- code*=bins;
- countarray[(int)rint(code)]++;
- total++;
- }
-
- line=setup_line(in);
- }
-
- /* make a pretty graph */
- {
- long maxcount=0,i,j;
- for(i=0;i<bins+1;i++)
- if(countarray[i]>maxcount)maxcount=countarray[i];
-
- printf("\r \r");
- printf("Total scalars: %ld\n",total);
- for(i=0;i<bins+1;i++){
- int stars=rint(50./maxcount*countarray[i]);
- printf("%08f (%8ld) |",(max-min)/bins*i+min,countarray[i]);
- for(j=0;j<stars;j++)printf("*");
- printf("\n");
- }
- }
- }
-
- fclose(in);
-
- }
- printf("\nDone.\n");
- exit(0);
-}
diff --git a/vq/genericdata.c b/vq/genericdata.c
deleted file mode 100644
index 01b372ee..00000000
--- a/vq/genericdata.c
+++ /dev/null
@@ -1,61 +0,0 @@
-/********************************************************************
- * *
- * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *
- * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
- * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
- * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
- * *
- * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2001 *
- * by the XIPHOPHORUS Company http://www.xiph.org/ *
- * *
- ********************************************************************
-
- function: generic euclidian distance metric for VQ codebooks
- last mod: $Id: genericdata.c,v 1.11 2001/12/20 01:00:39 segher Exp $
-
- ********************************************************************/
-
-#include <stdlib.h>
-#include <math.h>
-#include <stdio.h>
-#include "vqgen.h"
-#include "vqext.h"
-
-char *vqext_booktype="GENERICdata";
-int vqext_aux=0;
-quant_meta q={0,0,0,0}; /* non sequence data; each scalar
- independent */
-
-void vqext_quantize(vqgen *v,quant_meta *q){
- vqgen_quantize(v,q);
-}
-
-float *vqext_weight(vqgen *v,float *p){
- /*noop*/
- return(p);
-}
-
- /* candidate,actual */
-float vqext_metric(vqgen *v,float *e, float *p){
- int i;
- float acc=0.f;
- for(i=0;i<v->elements;i++){
- float val=p[i]-e[i];
- acc+=val*val;
- }
- return sqrt(acc/v->elements);
-}
-
-void vqext_addpoint_adj(vqgen *v,float *b,int start,int dim,int cols,int num){
- vqgen_addpoint(v,b+start,NULL);
-}
-
-void vqext_preprocess(vqgen *v){
- /* noop */
-}
-
-
-
-
-
-
diff --git a/vq/huffbuild.c b/vq/huffbuild.c
deleted file mode 100644
index ad1c295e..00000000
--- a/vq/huffbuild.c
+++ /dev/null
@@ -1,222 +0,0 @@
-/********************************************************************
- * *
- * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *
- * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
- * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
- * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
- * *
- * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2001 *
- * by the XIPHOPHORUS Company http://www.xiph.org/ *
- * *
- ********************************************************************
-
- function: hufftree builder
- last mod: $Id: huffbuild.c,v 1.12 2001/12/20 01:00:39 segher Exp $
-
- ********************************************************************/
-
-#include <stdlib.h>
-#include <string.h>
-#include <math.h>
-#include <stdio.h>
-#include "bookutil.h"
-
-static int nsofar=0;
-static int getval(FILE *in,int begin,int n,int group,int max){
- float v;
- int i;
- long val=0;
-
- if(nsofar>=n || get_line_value(in,&v)){
- reset_next_value();
- nsofar=0;
- if(get_next_value(in,&v))
- return(-1);
- for(i=1;i<=begin;i++)
- get_line_value(in,&v);
- }
-
- val=(int)v;
- nsofar++;
-
- for(i=1;i<group;i++,nsofar++)
- if(nsofar>=n || get_line_value(in,&v))
- return(getval(in,begin,n,group,max));
- else
- val = val*max+(int)v;
- return(val);
-}
-
-static void usage(){
- fprintf(stderr,
- "usage:\n"
- "huffbuild <input>.vqd <begin,n,group>|<lorange-hirange> [noguard]\n"
- " where begin,n,group is first scalar, \n"
- " number of scalars of each in line,\n"
- " number of scalars in a group\n"
- "eg: huffbuild reslongaux.vqd 0,1024,4\n"
- "produces reslongaux.vqh\n\n");
- exit(1);
-}
-
-int main(int argc, char *argv[]){
- char *base;
- char *infile;
- int i,j,k,begin,n,subn,guard=1;
- FILE *file;
- int maxval=0;
- int loval=0;
-
- if(argc<3)usage();
- if(argc==4)guard=0;
-
- infile=strdup(argv[1]);
- base=strdup(infile);
- if(strrchr(base,'.'))
- strrchr(base,'.')[0]='\0';
-
- {
- char *pos=strchr(argv[2],',');
- char *dpos=strchr(argv[2],'-');
- if(dpos){
- loval=atoi(argv[2]);
- maxval=atoi(dpos+1);
- subn=1;
- begin=0;
- }else{
- begin=atoi(argv[2]);
- if(!pos)
- usage();
- else
- n=atoi(pos+1);
- pos=strchr(pos+1,',');
- if(!pos)
- usage();
- else
- subn=atoi(pos+1);
- if(n/subn*subn != n){
- fprintf(stderr,"n must be divisible by group\n");
- exit(1);
- }
- }
- }
-
- /* scan the file for maximum value */
- file=fopen(infile,"r");
- if(!file){
- fprintf(stderr,"Could not open file %s\n",infile);
- if(!maxval)
- exit(1);
- else
- fprintf(stderr," making untrained books.\n");
-
- }
-
- if(!maxval){
- i=0;
- while(1){
- long v;
- if(get_next_ivalue(file,&v))break;
- if(v>maxval)maxval=v;
-
- if(!(i++&0xff))spinnit("loading... ",i);
- }
- rewind(file);
- maxval++;
- }
-
- {
- long vals=pow(maxval,subn);
- long *hist=_ogg_malloc(vals*sizeof(long));
- long *lengths=_ogg_malloc(vals*sizeof(long));
-
- for(j=loval;j<vals;j++)hist[j]=guard;
-
- if(file){
- reset_next_value();
- i/=subn;
- while(!feof(file)){
- long val=getval(file,begin,n,subn,maxval);
- if(val==-1 || val>=vals)break;
- hist[val]++;
- if(!(i--&0xff))spinnit("loading... ",i*subn);
- }
- fclose(file);
- }
-
- /* we have the probabilities, build the tree */
- fprintf(stderr,"Building tree for %ld entries\n",vals);
- build_tree_from_lengths0(vals,hist,lengths);
-
- /* save the book */
- {
- char *buffer=alloca(strlen(base)+5);
- strcpy(buffer,base);
- strcat(buffer,".vqh");
- file=fopen(buffer,"w");
- if(!file){
- fprintf(stderr,"Could not open file %s\n",buffer);
- exit(1);
- }
- }
-
- fprintf(file,
- "/********************************************************************\n"
- " * *\n"
- " * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *\n"
- " * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *\n"
- " * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *\n"
- " * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *\n"
- " * *\n"
- " * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2001 *\n"
- " * by the XIPHOPHORUS Company http://www.xiph.org/ *\n"
- " * *\n"
- " ********************************************************************\n"
- "\n"
- " function: static codebook autogenerated by huff/huffbuld\n"
- "\n"
- " ********************************************************************/\n\n");
-
- fprintf(file,"#ifndef _V_%s_VQH_\n#define _V_%s_VQH_\n",base,base);
- fprintf(file,"#include \"codebook.h\"\n\n");
-
- /* first, the static vectors, then the book structure to tie it together. */
- /* lengthlist */
- fprintf(file,"static long _huff_lengthlist_%s[] = {\n",base);
- for(j=0;j<vals;){
- fprintf(file,"\t");
- for(k=0;k<16 && j<vals;k++,j++)
- fprintf(file,"%2ld,",lengths[j]);
- fprintf(file,"\n");
- }
- fprintf(file,"};\n\n");
-
- /* the toplevel book */
- fprintf(file,"static static_codebook _huff_book_%s = {\n",base);
- fprintf(file,"\t%d, %ld,\n",subn,vals);
- fprintf(file,"\t_huff_lengthlist_%s,\n",base);
- fprintf(file,"\t0, 0, 0, 0, 0,\n");
- fprintf(file,"\tNULL,\n");
-
- fprintf(file,"\tNULL,\n");
- fprintf(file,"\tNULL,\n");
- fprintf(file,"\tNULL,\n");
- fprintf(file,"\t0\n};\n\n");
-
- fprintf(file,"\n#endif\n");
- fclose(file);
- fprintf(stderr,"Done. \n\n");
- }
- exit(0);
-}
-
-
-
-
-
-
-
-
-
-
-
diff --git a/vq/latticebuild.c b/vq/latticebuild.c
deleted file mode 100644
index 5efbf119..00000000
--- a/vq/latticebuild.c
+++ /dev/null
@@ -1,177 +0,0 @@
-/********************************************************************
- * *
- * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *
- * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
- * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
- * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
- * *
- * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2001 *
- * by the XIPHOPHORUS Company http://www.xiph.org/ *
- * *
- ********************************************************************
-
- function: utility main for building codebooks from lattice descriptions
- last mod: $Id: latticebuild.c,v 1.12 2001/12/20 01:00:39 segher Exp $
-
- ********************************************************************/
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <math.h>
-#include <string.h>
-#include <errno.h>
-#include "bookutil.h"
-
-/* The purpose of this util is just to finish packaging the
- description into a static codebook. It used to count hits for a
- histogram, but I've divorced that out to add some flexibility (it
- currently generates an equal probability codebook)
-
- command line:
- latticebuild description.vql
-
- the lattice description file contains two lines:
-
- <n> <dim> <multiplicitavep> <sequentialp>
- <value_0> <value_1> <value_2> ... <value_n-1>
-
- a threshmap (or pigeonmap) struct is generated by latticehint;
- there are fun tricks one can do with the threshmap and cascades,
- but the utils don't know them...
-
- entropy encoding is done by feeding an entry list collected from a
- training set and feeding it to latticetune along with the book.
-
- latticebuild produces a codebook on stdout */
-
-static int ilog(unsigned int v){
- int ret=0;
- while(v){
- ret++;
- v>>=1;
- }
- return(ret);
-}
-
-int main(int argc,char *argv[]){
- codebook b;
- static_codebook c;
- double *quantlist;
- long *hits;
-
- int entries=-1,dim=-1,quantvals=-1,addmul=-1,sequencep=0;
- FILE *in=NULL;
- char *line,*name;
- long i,j;
-
- memset(&b,0,sizeof(b));
- memset(&c,0,sizeof(c));
-
- if(argv[1]==NULL){
- fprintf(stderr,"Need a lattice description file on the command line.\n");
- exit(1);
- }
-
- {
- char *ptr;
- char *filename=_ogg_calloc(strlen(argv[1])+4,1);
-
- strcpy(filename,argv[1]);
- in=fopen(filename,"r");
- if(!in){
- fprintf(stderr,"Could not open input file %s\n",filename);
- exit(1);
- }
-
- ptr=strrchr(filename,'.');
- if(ptr){
- *ptr='\0';
- name=strdup(filename);
- }else{
- name=strdup(filename);
- }
-
- }
-
- /* read the description */
- line=get_line(in);
- if(sscanf(line,"%d %d %d %d",&quantvals,&dim,&addmul,&sequencep)!=4){
- if(sscanf(line,"%d %d %d",&quantvals,&dim,&addmul)!=3){
- fprintf(stderr,"Syntax error reading description file (line 1)\n");
- exit(1);
- }
- }
- entries=pow(quantvals,dim);
- c.dim=dim;
- c.entries=entries;
- c.lengthlist=_ogg_malloc(entries*sizeof(long));
- c.maptype=1;
- c.q_sequencep=sequencep;
- c.quantlist=_ogg_calloc(quantvals,sizeof(long));
-
- quantlist=_ogg_malloc(sizeof(double)*c.dim*c.entries);
- hits=_ogg_malloc(c.entries*sizeof(long));
- for(j=0;j<entries;j++)hits[j]=1;
- for(j=0;j<entries;j++)c.lengthlist[j]=1;
-
- reset_next_value();
- line=setup_line(in);
- for(j=0;j<quantvals;j++){
- char *temp;
- if(!line || sscanf(line,"%lf",quantlist+j)!=1){
- fprintf(stderr,"Ran out of data on line 2 of description file\n");
- exit(1);
- }
- temp=strchr(line,',');
- if(!temp)temp=strchr(line,' ');
- if(temp)temp++;
- line=temp;
- }
-
- /* gen a real quant list from the more easily human-grokked input */
- {
- double min=quantlist[0];
- double mindel=-1;
- int fac=1;
- for(j=1;j<quantvals;j++)if(quantlist[j]<min)min=quantlist[j];
- for(j=0;j<quantvals;j++)
- for(i=j+1;i<quantvals;i++)
- if(mindel==-1 || fabs(quantlist[j]-quantlist[i])<mindel)
- mindel=fabs(quantlist[j]-quantlist[i]);
-
- j=0;
- while(j<quantvals){
- for(j=0;j<quantvals;j++){
- double test=fac*(quantlist[j]-min)/mindel;
- if( fabs(rint(test)-test)>.00001f) break;
- }
- if(fac>100)break;
- if(j<quantvals)fac++;
- }
-
- mindel/=fac;
- fprintf(stderr,"min=%g mindel=%g\n",min,mindel);
-
- c.q_min=_float32_pack(min);
- c.q_delta=_float32_pack(mindel);
- c.q_quant=0;
-
- min=_float32_unpack(c.q_min);
- mindel=_float32_unpack(c.q_delta);
- for(j=0;j<quantvals;j++){
- c.quantlist[j]=rint((quantlist[j]-min)/mindel);
- if(ilog(c.quantlist[j])>c.q_quant)c.q_quant=ilog(c.quantlist[j]);
- }
- }
-
- /* build the [default] codeword lengths */
- memset(c.lengthlist,0,sizeof(long)*entries);
- for(i=0;i<entries;i++)hits[i]=1;
- build_tree_from_lengths(entries,hits,c.lengthlist);
-
- /* save the book in C header form */
- write_codebook(stdout,name,&c);
- fprintf(stderr,"\r "
- "\nDone.\n");
- exit(0);
-}
diff --git a/vq/latticehint.c b/vq/latticehint.c
deleted file mode 100644
index d6ef8fe0..00000000
--- a/vq/latticehint.c
+++ /dev/null
@@ -1,430 +0,0 @@
-/********************************************************************
- * *
- * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *
- * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
- * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
- * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
- * *
- * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2001 *
- * by the XIPHOPHORUS Company http://www.xiph.org/ *
- * *
- ********************************************************************
-
- function: utility main for building thresh/pigeonhole encode hints
- last mod: $Id: latticehint.c,v 1.12 2001/12/20 01:00:39 segher Exp $
-
- ********************************************************************/
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <math.h>
-#include <string.h>
-#include <errno.h>
-#include "../lib/scales.h"
-#include "bookutil.h"
-#include "vqgen.h"
-#include "vqsplit.h"
-
-/* The purpose of this util is to build encode hints for lattice
- codebooks so that brute forcing each codebook entry isn't needed.
- Threshhold hints are for books in which each scalar in the vector
- is independant (eg, residue) and pigeonhole lookups provide a
- minimum error fit for words where the scalars are interdependant
- (each affecting the fit of the next in sequence) as in an LSP
- sequential book (or can be used along with a sparse threshhold map,
- like a splitting tree that need not be trained)
-
- If the input book is non-sequential, a threshhold hint is built.
- If the input book is sequential, a pigeonholing hist is built.
- If the book is sparse, a pigeonholing hint is built, possibly in addition
- to the threshhold hint
-
- command line:
- latticehint book.vqh [threshlist]
-
- latticehint produces book.vqh on stdout */
-
-static int longsort(const void *a, const void *b){
- return(**((long **)a)-**((long **)b));
-}
-
-static int addtosearch(int entry,long **tempstack,long *tempcount,int add){
- long *ptr=tempstack[entry];
- long i=tempcount[entry];
-
- if(ptr){
- while(i--)
- if(*ptr++==add)return(0);
- tempstack[entry]=_ogg_realloc(tempstack[entry],
- (tempcount[entry]+1)*sizeof(long));
- }else{
- tempstack[entry]=_ogg_malloc(sizeof(long));
- }
-
- tempstack[entry][tempcount[entry]++]=add;
- return(1);
-}
-
-static void setvals(int dim,encode_aux_pigeonhole *p,
- long *temptrack,float *tempmin,float *tempmax,
- int seqp){
- int i;
- float last=0.f;
- for(i=0;i<dim;i++){
- tempmin[i]=(temptrack[i])*p->del+p->min+last;
- tempmax[i]=tempmin[i]+p->del;
- if(seqp)last=tempmin[i];
- }
-}
-
-/* note that things are currently set up such that input fits that
- quantize outside the pigeonmap are dropped and brute-forced. So we
- can ignore the <0 and >=n boundary cases in min/max error */
-
-static float minerror(int dim,float *a,encode_aux_pigeonhole *p,
- long *temptrack,float *tempmin,float *tempmax){
- int i;
- float err=0.f;
- for(i=0;i<dim;i++){
- float eval=0.f;
- if(a[i]<tempmin[i]){
- eval=tempmin[i]-a[i];
- }else if(a[i]>tempmax[i]){
- eval=a[i]-tempmax[i];
- }
- err+=eval*eval;
- }
- return(err);
-}
-
-static float maxerror(int dim,float *a,encode_aux_pigeonhole *p,
- long *temptrack,float *tempmin,float *tempmax){
- int i;
- float err=0.f,eval;
- for(i=0;i<dim;i++){
- if(a[i]<tempmin[i]){
- eval=tempmax[i]-a[i];
- }else if(a[i]>tempmax[i]){
- eval=a[i]-tempmin[i];
- }else{
- float t1=a[i]-tempmin[i];
- eval=tempmax[i]-a[i];
- if(t1>eval)eval=t1;
- }
- err+=eval*eval;
- }
- return(err);
-}
-
-int main(int argc,char *argv[]){
- codebook *b;
- static_codebook *c;
- int entries=-1,dim=-1;
- float min,del;
- char *name;
- long i,j;
- float *suggestions;
- int suggcount=0;
-
- if(argv[1]==NULL){
- fprintf(stderr,"Need a lattice book on the command line.\n");
- exit(1);
- }
-
- {
- char *ptr;
- char *filename=strdup(argv[1]);
-
- b=codebook_load(filename);
- c=(static_codebook *)(b->c);
-
- ptr=strrchr(filename,'.');
- if(ptr){
- *ptr='\0';
- name=strdup(filename);
- }else{
- name=strdup(filename);
- }
- }
-
- if(c->maptype!=1){
- fprintf(stderr,"Provided book is not a latticebook.\n");
- exit(1);
- }
-
- entries=b->entries;
- dim=b->dim;
- min=_float32_unpack(c->q_min);
- del=_float32_unpack(c->q_delta);
-
- /* Do we want to gen a threshold hint? */
- if(c->q_sequencep==0){
- /* yes. Discard any preexisting threshhold hint */
- long quantvals=_book_maptype1_quantvals(c);
- long **quantsort=alloca(quantvals*sizeof(long *));
- encode_aux_threshmatch *t=_ogg_calloc(1,sizeof(encode_aux_threshmatch));
- c->thresh_tree=t;
-
- fprintf(stderr,"Adding threshold hint to %s...\n",name);
-
- /* partial/complete suggestions */
- if(argv[2]){
- char *ptr=strdup(argv[2]);
- suggestions=alloca(sizeof(float)*quantvals);
-
- for(suggcount=0;ptr && suggcount<quantvals;suggcount++){
- char *ptr2=strchr(ptr,',');
- if(ptr2)*ptr2++='\0';
- suggestions[suggcount]=atof(ptr);
- ptr=ptr2;
- }
- }
-
- /* simplest possible threshold hint only */
- t->quantthresh=_ogg_calloc(quantvals-1,sizeof(float));
- t->quantmap=_ogg_calloc(quantvals,sizeof(int));
- t->threshvals=quantvals;
- t->quantvals=quantvals;
-
- /* the quantvals may not be in order; sort em first */
- for(i=0;i<quantvals;i++)quantsort[i]=c->quantlist+i;
- qsort(quantsort,quantvals,sizeof(long *),longsort);
-
- /* ok, gen the map and thresholds */
- for(i=0;i<quantvals;i++)t->quantmap[i]=quantsort[i]-c->quantlist;
- for(i=0;i<quantvals-1;i++){
- float v1=*(quantsort[i])*del+min;
- float v2=*(quantsort[i+1])*del+min;
-
- for(j=0;j<suggcount;j++)
- if(v1<suggestions[j] && suggestions[j]<v2){
- t->quantthresh[i]=suggestions[j];
- break;
- }
-
- if(j==suggcount){
- t->quantthresh[i]=(v1+v2)*.5;
- }
- }
- }
-
- /* Do we want to gen a pigeonhole hint? */
-#if 0
- for(i=0;i<entries;i++)if(c->lengthlist[i]==0)break;
- if(c->q_sequencep || i<entries){
- long **tempstack;
- long *tempcount;
- long *temptrack;
- float *tempmin;
- float *tempmax;
- long totalstack=0;
- long pigeons;
- long subpigeons;
- long quantvals=_book_maptype1_quantvals(c);
- int changep=1,factor;
-
- encode_aux_pigeonhole *p=_ogg_calloc(1,sizeof(encode_aux_pigeonhole));
- c->pigeon_tree=p;
-
- fprintf(stderr,"Adding pigeonhole hint to %s...\n",name);
-
- /* the idea is that we quantize uniformly, even in a nonuniform
- lattice, so that quantization of one scalar has a predictable
- result on the next sequential scalar in a greedy matching
- algorithm. We generate a lookup based on the quantization of
- the vector (pigeonmap groups quantized entries together) and
- list the entries that could possible be the best fit for any
- given member of that pigeonhole. The encode process then has a
- much smaller list to brute force */
-
- /* find our pigeonhole-specific quantization values, fill in the
- quant value->pigeonhole map */
- factor=3;
- p->del=del;
- p->min=min;
- p->quantvals=quantvals;
- {
- int max=0;
- for(i=0;i<quantvals;i++)if(max<c->quantlist[i])max=c->quantlist[i];
- p->mapentries=max;
- }
- p->pigeonmap=_ogg_malloc(p->mapentries*sizeof(long));
- p->quantvals=(quantvals+factor-1)/factor;
-
- /* pigeonhole roughly on the boundaries of the quantvals; the
- exact pigeonhole grouping is an optimization issue, not a
- correctness issue */
- for(i=0;i<p->mapentries;i++){
- float thisval=del*i+min; /* middle of the quant zone */
- int quant=0;
- float err=fabs(c->quantlist[0]*del+min-thisval);
- for(j=1;j<quantvals;j++){
- float thiserr=fabs(c->quantlist[j]*del+min-thisval);
- if(thiserr<err){
- quant=j/factor;
- err=thiserr;
- }
- }
- p->pigeonmap[i]=quant;
- }
-
- /* pigeonmap complete. Now do the grungy business of finding the
- entries that could possibly be the best fit for a value appearing
- in the pigeonhole. The trick that allows the below to work is the
- uniform quantization; even though the scalars may be 'sequential'
- (each a delta from the last), the uniform quantization means that
- the error variance is *not* dependant. Given a pigeonhole and an
- entry, we can find the minimum and maximum possible errors
- (relative to the entry) for any point that could appear in the
- pigeonhole */
-
- /* must iterate over both pigeonholes and entries */
- /* temporarily (in order to avoid thinking hard), we grow each
- pigeonhole seperately, the build a stack of 'em later */
- pigeons=1;
- subpigeons=1;
- for(i=0;i<dim;i++)subpigeons*=p->mapentries;
- for(i=0;i<dim;i++)pigeons*=p->quantvals;
- temptrack=_ogg_calloc(dim,sizeof(long));
- tempmin=_ogg_calloc(dim,sizeof(float));
- tempmax=_ogg_calloc(dim,sizeof(float));
- tempstack=_ogg_calloc(pigeons,sizeof(long *));
- tempcount=_ogg_calloc(pigeons,sizeof(long));
-
- while(1){
- float errorpost=-1;
- char buffer[80];
-
- /* map our current pigeonhole to a 'big pigeonhole' so we know
- what list we're after */
- int entry=0;
- for(i=dim-1;i>=0;i--)entry=entry*p->quantvals+p->pigeonmap[temptrack[i]];
- setvals(dim,p,temptrack,tempmin,tempmax,c->q_sequencep);
- sprintf(buffer,"Building pigeonhole search list [%ld]...",totalstack);
-
-
- /* Search all entries to find the one with the minimum possible
- maximum error. Record that error */
- for(i=0;i<entries;i++){
- if(c->lengthlist[i]>0){
- float this=maxerror(dim,b->valuelist+i*dim,p,
- temptrack,tempmin,tempmax);
- if(errorpost==-1 || this<errorpost)errorpost=this;
- spinnit(buffer,subpigeons);
- }
- }
-
- /* Our search list will contain all entries with a minimum
- possible error <= our errorpost */
- for(i=0;i<entries;i++)
- if(c->lengthlist[i]>0){
- spinnit(buffer,subpigeons);
- if(minerror(dim,b->valuelist+i*dim,p,
- temptrack,tempmin,tempmax)<errorpost)
- totalstack+=addtosearch(entry,tempstack,tempcount,i);
- }
-
- for(i=0;i<dim;i++){
- temptrack[i]++;
- if(temptrack[i]<p->mapentries)break;
- temptrack[i]=0;
- }
- if(i==dim)break;
- subpigeons--;
- }
-
- fprintf(stderr,"\r "
- "\rTotal search list size (all entries): %ld\n",totalstack);
-
- /* pare the index of lists for improbable quantizations (where
- improbable is determined by c->lengthlist; we assume that
- pigeonholing is in sync with the codeword cells, which it is */
- /*for(i=0;i<entries;i++){
- float probability= 1.f/(1<<c->lengthlist[i]);
- if(c->lengthlist[i]==0 || probability*entries<cutoff){
- totalstack-=tempcount[i];
- tempcount[i]=0;
- }
- }*/
-
- /* pare the list of shortlists; merge contained and similar lists
- together */
- p->fitmap=_ogg_malloc(pigeons*sizeof(long));
- for(i=0;i<pigeons;i++)p->fitmap[i]=-1;
- while(changep){
- char buffer[80];
- changep=0;
-
- for(i=0;i<pigeons;i++){
- if(p->fitmap[i]<0 && tempcount[i]){
- for(j=i+1;j<pigeons;j++){
- if(p->fitmap[j]<0 && tempcount[j]){
- /* is one list a superset, or are they sufficiently similar? */
- int amiss=0,bmiss=0,ii,jj;
- for(ii=0;ii<tempcount[i];ii++){
- for(jj=0;jj<tempcount[j];jj++)
- if(tempstack[i][ii]==tempstack[j][jj])break;
- if(jj==tempcount[j])amiss++;
- }
- for(jj=0;jj<tempcount[j];jj++){
- for(ii=0;ii<tempcount[i];ii++)
- if(tempstack[i][ii]==tempstack[j][jj])break;
- if(ii==tempcount[i])bmiss++;
- }
- if(amiss==0 ||
- bmiss==0 ||
- (amiss*2<tempcount[i] && bmiss*2<tempcount[j] &&
- tempcount[i]+bmiss<entries/30)){
-
- /*superset/similar Add all of one to the other. */
- for(jj=0;jj<tempcount[j];jj++)
- totalstack+=addtosearch(i,tempstack,tempcount,
- tempstack[j][jj]);
- totalstack-=tempcount[j];
- p->fitmap[j]=i;
- changep=1;
- }
- }
- }
- sprintf(buffer,"Consolidating [%ld total, %s]... ",totalstack,
- changep?"reit":"nochange");
- spinnit(buffer,pigeons-i);
- }
- }
- }
-
- /* repack the temp stack in final form */
- fprintf(stderr,"\r "
- "\rFinal total list size: %ld\n",totalstack);
-
-
- p->fittotal=totalstack;
- p->fitlist=_ogg_malloc((totalstack+1)*sizeof(long));
- p->fitlength=_ogg_malloc(pigeons*sizeof(long));
- {
- long usage=0;
- for(i=0;i<pigeons;i++){
- if(p->fitmap[i]==-1){
- if(tempcount[i])
- memcpy(p->fitlist+usage,tempstack[i],tempcount[i]*sizeof(long));
- p->fitmap[i]=usage;
- p->fitlength[i]=tempcount[i];
- usage+=tempcount[i];
- if(usage>totalstack){
- fprintf(stderr,"Internal error; usage>totalstack\n");
- exit(1);
- }
- }else{
- p->fitlength[i]=p->fitlength[p->fitmap[i]];
- p->fitmap[i]=p->fitmap[p->fitmap[i]];
- }
- }
- }
- }
-#endif
-
- write_codebook(stdout,name,c);
- fprintf(stderr,"\r "
- "\nDone.\n");
- exit(0);
-}
diff --git a/vq/latticepare.c b/vq/latticepare.c
deleted file mode 100644
index 222b7e05..00000000
--- a/vq/latticepare.c
+++ /dev/null
@@ -1,595 +0,0 @@
-/********************************************************************
- * *
- * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *
- * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
- * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
- * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
- * *
- * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2001 *
- * by the XIPHOPHORUS Company http://www.xiph.org/ *
- * *
- ********************************************************************
-
- function: utility for paring low hit count cells from lattice codebook
- last mod: $Id: latticepare.c,v 1.11 2001/12/20 01:00:39 segher Exp $
-
- ********************************************************************/
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <math.h>
-#include <string.h>
-#include <errno.h>
-#include "../lib/scales.h"
-#include "bookutil.h"
-#include "vqgen.h"
-#include "vqsplit.h"
-#include "../lib/os.h"
-
-/* Lattice codebooks have two strengths: important fetaures that are
- poorly modelled by global error minimization training (eg, strong
- peaks) are not neglected 2) compact quantized representation.
-
- A fully populated lattice codebook, however, swings point 1 too far
- in the opposite direction; rare features need not be modelled quite
- so religiously and as such, we waste bits unless we eliminate the
- least common cells. The codebook rep supports unused cells, so we
- need to tag such cells and build an auxiliary (non-thresh) search
- mechanism to find the proper match quickly */
-
-/* two basic steps; first is pare the cell for which dispersal creates
- the least additional error. This will naturally choose
- low-population cells and cells that have not taken on points from
- neighboring paring (but does not result in the lattice collapsing
- inward and leaving low population ares totally unmodelled). After
- paring has removed the desired number of cells, we need to build an
- auxiliary search for each culled point */
-
-/* Although lattice books (due to threshhold-based matching) do not
- actually use error to make cell selections (in fact, it need not
- bear any relation), the 'secondbest' entry finder here is in fact
- error/distance based, so latticepare is only useful on such books */
-
-/* command line:
- latticepare latticebook.vqh input_data.vqd <target_cells>
-
- produces a new output book on stdout
-*/
-
-static float _dist(int el,float *a, float *b){
- int i;
- float acc=0.f;
- for(i=0;i<el;i++){
- float val=(a[i]-b[i]);
- acc+=val*val;
- }
- return(acc);
-}
-
-static float *pointlist;
-static long points=0;
-
-void add_vector(codebook *b,float *vec,long n){
- int dim=b->dim,i,j;
- int step=n/dim;
- for(i=0;i<step;i++){
- for(j=i;j<n;j+=step){
- pointlist[points++]=vec[j];
- }
- }
-}
-
-static int bestm(codebook *b,float *vec){
- encode_aux_threshmatch *tt=b->c->thresh_tree;
- int dim=b->dim;
- int i,k,o;
- int best=0;
-
- /* what would be the closest match if the codebook was fully
- populated? */
-
- for(k=0,o=dim-1;k<dim;k++,o--){
- int i;
- for(i=0;i<tt->threshvals-1;i++)
- if(vec[o]<tt->quantthresh[i])break;
- best=(best*tt->quantvals)+tt->quantmap[i];
- }
- return(best);
-}
-
-static int closest(codebook *b,float *vec,int current){
- encode_aux_threshmatch *tt=b->c->thresh_tree;
- int dim=b->dim;
- int i,k,o;
-
- float bestmetric=0;
- int bestentry=-1;
- int best=bestm(b,vec);
-
- if(current<0 && b->c->lengthlist[best]>0)return best;
-
- for(i=0;i<b->entries;i++){
- if(b->c->lengthlist[i]>0 && i!=best && i!=current){
- float thismetric=_dist(dim, vec, b->valuelist+i*dim);
- if(bestentry==-1 || thismetric<bestmetric){
- bestentry=i;
- bestmetric=thismetric;
- }
- }
- }
-
- return(bestentry);
-}
-
-static float _heuristic(codebook *b,float *ppt,int secondbest){
- float *secondcell=b->valuelist+secondbest*b->dim;
- int best=bestm(b,ppt);
- float *firstcell=b->valuelist+best*b->dim;
- float error=_dist(b->dim,firstcell,secondcell);
- float *zero=alloca(b->dim*sizeof(float));
- float fromzero;
-
- memset(zero,0,b->dim*sizeof(float));
- fromzero=sqrt(_dist(b->dim,firstcell,zero));
-
- return(error/fromzero);
-}
-
-static int longsort(const void *a, const void *b){
- return **(long **)b-**(long **)a;
-}
-
-void usage(void){
- fprintf(stderr,"Ogg/Vorbis lattice codebook paring utility\n\n"
- "usage: latticepare book.vqh data.vqd <target_cells> <protected_cells> base\n"
- "where <target_cells> is the desired number of final cells (or -1\n"
- " for no change)\n"
- " <protected_cells> is the number of highest-hit count cells\n"
- " to protect from dispersal\n"
- " base is the base name (not including .vqh) of the new\n"
- " book\n\n");
- exit(1);
-}
-
-int main(int argc,char *argv[]){
- char *basename;
- codebook *b=NULL;
- int entries=0;
- int dim=0;
- long i,j,target=-1,protect=-1;
- FILE *out=NULL;
-
- int argnum=0;
-
- argv++;
- if(*argv==NULL){
- usage();
- exit(1);
- }
-
- while(*argv){
- if(*argv[0]=='-'){
-
- argv++;
-
- }else{
- switch (argnum++){
- case 0:case 1:
- {
- /* yes, this is evil. However, it's very convenient to parse file
- extentions */
-
- /* input file. What kind? */
- char *dot;
- char *ext=NULL;
- char *name=strdup(*argv++);
- dot=strrchr(name,'.');
- if(dot)
- ext=dot+1;
- else{
- ext="";
-
- }
-
-
- /* codebook */
- if(!strcmp(ext,"vqh")){
-
- basename=strrchr(name,'/');
- if(basename)
- basename=strdup(basename)+1;
- else
- basename=strdup(name);
- dot=strrchr(basename,'.');
- if(dot)*dot='\0';
-
- b=codebook_load(name);
- dim=b->dim;
- entries=b->entries;
- }
-
- /* data file; we do actually need to suck it into memory */
- /* we're dealing with just one book, so we can de-interleave */
- if(!strcmp(ext,"vqd") && !points){
- int cols;
- long lines=0;
- char *line;
- float *vec;
- FILE *in=fopen(name,"r");
- if(!in){
- fprintf(stderr,"Could not open input file %s\n",name);
- exit(1);
- }
-
- reset_next_value();
- line=setup_line(in);
- /* count cols before we start reading */
- {
- char *temp=line;
- while(*temp==' ')temp++;
- for(cols=0;*temp;cols++){
- while(*temp>32)temp++;
- while(*temp==' ')temp++;
- }
- }
- vec=alloca(cols*sizeof(float));
- /* count, then load, to avoid fragmenting the hell out of
- memory */
- while(line){
- lines++;
- for(j=0;j<cols;j++)
- if(get_line_value(in,vec+j)){
- fprintf(stderr,"Too few columns on line %ld in data file\n",lines);
- exit(1);
- }
- if((lines&0xff)==0)spinnit("counting samples...",lines*cols);
- line=setup_line(in);
- }
- pointlist=_ogg_malloc((cols*lines+entries*dim)*sizeof(float));
-
- rewind(in);
- line=setup_line(in);
- while(line){
- lines--;
- for(j=0;j<cols;j++)
- if(get_line_value(in,vec+j)){
- fprintf(stderr,"Too few columns on line %ld in data file\n",lines);
- exit(1);
- }
- /* deinterleave, add to heap */
- add_vector(b,vec,cols);
- if((lines&0xff)==0)spinnit("loading samples...",lines*cols);
-
- line=setup_line(in);
- }
- fclose(in);
- }
- }
- break;
- case 2:
- target=atol(*argv++);
- if(target==0)target=entries;
- break;
- case 3:
- protect=atol(*argv++);
- break;
- case 4:
- {
- char *buff=alloca(strlen(*argv)+5);
- sprintf(buff,"%s.vqh",*argv);
- basename=*argv++;
-
- out=fopen(buff,"w");
- if(!out){
- fprintf(stderr,"unable ot open %s for output",buff);
- exit(1);
- }
- }
- break;
- default:
- usage();
- }
- }
- }
- if(!entries || !points || !out)usage();
- if(target==-1)usage();
-
- /* add guard points */
- for(i=0;i<entries;i++)
- for(j=0;j<dim;j++)
- pointlist[points++]=b->valuelist[i*dim+j];
-
- points/=dim;
-
- /* set up auxiliary vectors for error tracking */
- {
- encode_aux_nearestmatch *nt=NULL;
- long pointssofar=0;
- long *pointindex;
- long indexedpoints=0;
- long *entryindex;
- long *reventry;
- long *membership=_ogg_malloc(points*sizeof(long));
- long *firsthead=_ogg_malloc(entries*sizeof(long));
- long *secondary=_ogg_malloc(points*sizeof(long));
- long *secondhead=_ogg_malloc(entries*sizeof(long));
-
- long *cellcount=_ogg_calloc(entries,sizeof(long));
- long *cellcount2=_ogg_calloc(entries,sizeof(long));
- float *cellerror=_ogg_calloc(entries,sizeof(float));
- float *cellerrormax=_ogg_calloc(entries,sizeof(float));
- long cellsleft=entries;
- for(i=0;i<points;i++)membership[i]=-1;
- for(i=0;i<entries;i++)firsthead[i]=-1;
- for(i=0;i<points;i++)secondary[i]=-1;
- for(i=0;i<entries;i++)secondhead[i]=-1;
-
- for(i=0;i<points;i++){
- /* assign vectors to the nearest cell. Also keep track of second
- nearest for error statistics */
- float *ppt=pointlist+i*dim;
- int firstentry=closest(b,ppt,-1);
- int secondentry=closest(b,ppt,firstentry);
- float firstmetric=_dist(dim,b->valuelist+dim*firstentry,ppt);
- float secondmetric=_dist(dim,b->valuelist+dim*secondentry,ppt);
-
- if(!(i&0xff))spinnit("initializing... ",points-i);
-
- membership[i]=firsthead[firstentry];
- firsthead[firstentry]=i;
- secondary[i]=secondhead[secondentry];
- secondhead[secondentry]=i;
-
- if(i<points-entries){
- cellerror[firstentry]+=secondmetric-firstmetric;
- cellerrormax[firstentry]=max(cellerrormax[firstentry],
- _heuristic(b,ppt,secondentry));
- cellcount[firstentry]++;
- cellcount2[secondentry]++;
- }
- }
-
- /* which cells are most heavily populated? Protect as many from
- dispersal as the user has requested */
- {
- long **countindex=_ogg_calloc(entries,sizeof(long *));
- for(i=0;i<entries;i++)countindex[i]=cellcount+i;
- qsort(countindex,entries,sizeof(long *),longsort);
- for(i=0;i<protect;i++){
- int ptr=countindex[i]-cellcount;
- cellerrormax[ptr]=9e50f;
- }
- }
-
- {
- fprintf(stderr,"\r");
- for(i=0;i<entries;i++){
- /* decompose index */
- int entry=i;
- for(j=0;j<dim;j++){
- fprintf(stderr,"%d:",entry%b->c->thresh_tree->quantvals);
- entry/=b->c->thresh_tree->quantvals;
- }
-
- fprintf(stderr,":%ld/%ld, ",cellcount[i],cellcount2[i]);
- }
- fprintf(stderr,"\n");
- }
-
- /* do the automatic cull request */
- while(cellsleft>target){
- int bestcell=-1;
- float besterror=0;
- float besterror2=0;
- long head=-1;
- char spinbuf[80];
- sprintf(spinbuf,"cells left to eliminate: %ld : ",cellsleft-target);
-
- /* find the cell with lowest removal impact */
- for(i=0;i<entries;i++){
- if(b->c->lengthlist[i]>0){
- if(bestcell==-1 || cellerrormax[i]<=besterror2){
- if(bestcell==-1 || cellerrormax[i]<besterror2 ||
- besterror>cellerror[i]){
- besterror=cellerror[i];
- besterror2=cellerrormax[i];
- bestcell=i;
- }
- }
- }
- }
-
- fprintf(stderr,"\reliminating cell %d \n"
- " dispersal error of %g max/%g total (%ld hits)\n",
- bestcell,besterror2,besterror,cellcount[bestcell]);
-
- /* disperse it. move each point out, adding it (properly) to
- the second best */
- b->c->lengthlist[bestcell]=0;
- head=firsthead[bestcell];
- firsthead[bestcell]=-1;
- while(head!=-1){
- /* head is a point number */
- float *ppt=pointlist+head*dim;
- int firstentry=closest(b,ppt,-1);
- int secondentry=closest(b,ppt,firstentry);
- float firstmetric=_dist(dim,b->valuelist+dim*firstentry,ppt);
- float secondmetric=_dist(dim,b->valuelist+dim*secondentry,ppt);
- long next=membership[head];
-
- if(head<points-entries){
- cellcount[firstentry]++;
- cellcount[bestcell]--;
- cellerror[firstentry]+=secondmetric-firstmetric;
- cellerrormax[firstentry]=max(cellerrormax[firstentry],
- _heuristic(b,ppt,secondentry));
- }
-
- membership[head]=firsthead[firstentry];
- firsthead[firstentry]=head;
- head=next;
- if(cellcount[bestcell]%128==0)
- spinnit(spinbuf,cellcount[bestcell]+cellcount2[bestcell]);
-
- }
-
- /* now see that all points that had the dispersed cell as second
- choice have second choice reassigned */
- head=secondhead[bestcell];
- secondhead[bestcell]=-1;
- while(head!=-1){
- float *ppt=pointlist+head*dim;
- /* who are we assigned to now? */
- int firstentry=closest(b,ppt,-1);
- /* what is the new second closest match? */
- int secondentry=closest(b,ppt,firstentry);
- /* old second closest is the cell being disbanded */
- float oldsecondmetric=_dist(dim,b->valuelist+dim*bestcell,ppt);
- /* new second closest error */
- float secondmetric=_dist(dim,b->valuelist+dim*secondentry,ppt);
- long next=secondary[head];
-
- if(head<points-entries){
- cellcount2[secondentry]++;
- cellcount2[bestcell]--;
- cellerror[firstentry]+=secondmetric-oldsecondmetric;
- cellerrormax[firstentry]=max(cellerrormax[firstentry],
- _heuristic(b,ppt,secondentry));
- }
-
- secondary[head]=secondhead[secondentry];
- secondhead[secondentry]=head;
- head=next;
-
- if(cellcount2[bestcell]%128==0)
- spinnit(spinbuf,cellcount2[bestcell]);
- }
-
- cellsleft--;
- }
-
- /* paring is over. Build decision trees using points that now fall
- through the thresh matcher. */
- /* we don't free membership; we flatten it in order to use in lp_split */
-
- for(i=0;i<entries;i++){
- long head=firsthead[i];
- spinnit("rearranging membership cache... ",entries-i);
- while(head!=-1){
- long next=membership[head];
- membership[head]=i;
- head=next;
- }
- }
-
- free(secondhead);
- free(firsthead);
- free(cellerror);
- free(cellerrormax);
- free(secondary);
-
- pointindex=_ogg_malloc(points*sizeof(long));
- /* make a point index of fall-through points */
- for(i=0;i<points;i++){
- int best=_best(b,pointlist+i*dim,1);
- if(best==-1)
- pointindex[indexedpoints++]=i;
- spinnit("finding orphaned points... ",points-i);
- }
-
- /* make an entry index */
- entryindex=_ogg_malloc(entries*sizeof(long));
- target=0;
- for(i=0;i<entries;i++){
- if(b->c->lengthlist[i]>0)
- entryindex[target++]=i;
- }
-
- /* make working space for a reverse entry index */
- reventry=_ogg_malloc(entries*sizeof(long));
-
- /* do the split */
- nt=b->c->nearest_tree=
- _ogg_calloc(1,sizeof(encode_aux_nearestmatch));
-
- nt->alloc=4096;
- nt->ptr0=_ogg_malloc(sizeof(long)*nt->alloc);
- nt->ptr1=_ogg_malloc(sizeof(long)*nt->alloc);
- nt->p=_ogg_malloc(sizeof(long)*nt->alloc);
- nt->q=_ogg_malloc(sizeof(long)*nt->alloc);
- nt->aux=0;
-
- fprintf(stderr,"Leaves added: %d \n",
- lp_split(pointlist,points,
- b,entryindex,target,
- pointindex,indexedpoints,
- membership,reventry,
- 0,&pointssofar));
- free(membership);
- free(reventry);
- free(pointindex);
-
- /* hack alert. I should just change the damned splitter and
- codebook writer */
- for(i=0;i<nt->aux;i++)nt->p[i]*=dim;
- for(i=0;i<nt->aux;i++)nt->q[i]*=dim;
-
- /* recount hits. Build new lengthlist. reuse entryindex storage */
- for(i=0;i<entries;i++)entryindex[i]=1;
- for(i=0;i<points-entries;i++){
- int best=_best(b,pointlist+i*dim,1);
- float *a=pointlist+i*dim;
- if(!(i&0xff))spinnit("counting hits...",i);
- if(best==-1){
- fprintf(stderr,"\nINTERNAL ERROR; a point count not be matched to a\n"
- "codebook entry. The new decision tree is broken.\n");
- exit(1);
- }
- entryindex[best]++;
- }
- for(i=0;i<nt->aux;i++)nt->p[i]/=dim;
- for(i=0;i<nt->aux;i++)nt->q[i]/=dim;
-
- /* the lengthlist builder doesn't actually deal with 0 hit entries.
- So, we pack the 'sparse' hit list into a dense list, then unpack
- the lengths after the build */
- {
- int upper=0;
- long *lengthlist=_ogg_calloc(entries,sizeof(long));
- for(i=0;i<entries;i++){
- if(b->c->lengthlist[i]>0)
- entryindex[upper++]=entryindex[i];
- else{
- if(entryindex[i]>1){
- fprintf(stderr,"\nINTERNAL ERROR; _best matched to unused entry\n");
- exit(1);
- }
- }
- }
-
- /* sanity check */
- if(upper != target){
- fprintf(stderr,"\nINTERNAL ERROR; packed the wrong number of entries\n");
- exit(1);
- }
-
- build_tree_from_lengths(upper,entryindex,lengthlist);
-
- upper=0;
- for(i=0;i<entries;i++){
- if(b->c->lengthlist[i]>0)
- b->c->lengthlist[i]=lengthlist[upper++];
- }
-
- }
- }
- /* we're done. write it out. */
- write_codebook(out,basename,b->c);
-
- fprintf(stderr,"\r \nDone.\n");
- return(0);
-}
-
-
-
-
diff --git a/vq/latticetune.c b/vq/latticetune.c
deleted file mode 100644
index b1d760e5..00000000
--- a/vq/latticetune.c
+++ /dev/null
@@ -1,164 +0,0 @@
-/********************************************************************
- * *
- * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *
- * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
- * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
- * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
- * *
- * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2001 *
- * by the XIPHOPHORUS Company http://www.xiph.org/ *
- * *
- ********************************************************************
-
- function: utility main for setting entropy encoding parameters
- for lattice codebooks
- last mod: $Id: latticetune.c,v 1.11 2001/12/20 01:00:39 segher Exp $
-
- ********************************************************************/
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <math.h>
-#include <string.h>
-#include <errno.h>
-#include "bookutil.h"
-
-static int strrcmp_i(char *s,char *cmp){
- return(strncmp(s+strlen(s)-strlen(cmp),cmp,strlen(cmp)));
-}
-
-/* This util takes a training-collected file listing codewords used in
- LSP fitting, then generates new codeword lengths for maximally
- efficient integer-bits entropy encoding.
-
- command line:
- latticetune book.vqh input.vqd [unused_entriesp]
-
- latticetune produces book.vqh on stdout */
-
-int main(int argc,char *argv[]){
- codebook *b;
- static_codebook *c;
- long *lengths;
- long *hits;
-
- int entries=-1,dim=-1,guard=1;
- FILE *in=NULL;
- char *line,*name;
- long j;
-
- if(argv[1]==NULL){
- fprintf(stderr,"Need a lattice codebook on the command line.\n");
- exit(1);
- }
- if(argv[2]==NULL){
- fprintf(stderr,"Need a codeword data file on the command line.\n");
- exit(1);
- }
- if(argv[3]!=NULL)guard=0;
-
- {
- char *ptr;
- char *filename=strdup(argv[1]);
-
- b=codebook_load(filename);
- c=(static_codebook *)(b->c);
-
- ptr=strrchr(filename,'.');
- if(ptr){
- *ptr='\0';
- name=strdup(filename);
- }else{
- name=strdup(filename);
- }
- }
-
- if(c->maptype!=1){
- fprintf(stderr,"Provided book is not a latticebook.\n");
- exit(1);
- }
-
- entries=b->entries;
- dim=b->dim;
-
- hits=_ogg_malloc(entries*sizeof(long));
- lengths=_ogg_calloc(entries,sizeof(long));
- for(j=0;j<entries;j++)hits[j]=guard;
-
- in=fopen(argv[2],"r");
- if(!in){
- fprintf(stderr,"Could not open input file %s\n",argv[2]);
- exit(1);
- }
-
- if(!strrcmp_i(argv[0],"latticetune")){
- long lines=0;
- line=setup_line(in);
- while(line){
- long code;
- lines++;
- if(!(lines&0xfff))spinnit("codewords so far...",lines);
-
- if(sscanf(line,"%ld",&code)==1)
- hits[code]++;
-
- line=setup_line(in);
- }
- }
-
- /* now we simply count already collated by-entry data */
- if(!strrcmp_i(argv[0],"res0tune") || !strrcmp_i(argv[0],"res1tune")){
-
- line=setup_line(in);
- while(line){
-
- /* code:hits\n */
- /* likely to have multiple listing for each code entry; must
- accumulate */
-
- char *pos=strchr(line,':');
- if(pos){
- long code=atol(line);
- long val=atol(pos+1);
- hits[code]+=val;
- }
-
- line=setup_line(in);
- }
- }
-
- fclose(in);
-
- /* build the codeword lengths */
- build_tree_from_lengths0(entries,hits,lengths);
-
- c->lengthlist=lengths;
- write_codebook(stdout,name,c);
-
- {
- long bins=_book_maptype1_quantvals(c);
- long i,k,base=c->lengthlist[0];
- for(i=0;i<entries;i++)
- if(c->lengthlist[i]>base)base=c->lengthlist[i];
-
- for(j=0;j<entries;j++){
- if(c->lengthlist[j]){
- int indexdiv=1;
- fprintf(stderr,"%4ld: ",j);
- for(k=0;k<c->dim;k++){
- int index= (j/indexdiv)%bins;
- fprintf(stderr,"%+3.1f,", c->quantlist[index]*_float32_unpack(c->q_delta)+
- _float32_unpack(c->q_min));
- indexdiv*=bins;
- }
- fprintf(stderr,"\t|");
- for(k=0;k<base-c->lengthlist[j];k++)fprintf(stderr,"*");
- fprintf(stderr,"\n");
- }
- }
- }
-
- fprintf(stderr,"\r "
- "\nDone.\n");
- exit(0);
-}
diff --git a/vq/lspdata.c b/vq/lspdata.c
deleted file mode 100644
index c7b2d2e9..00000000
--- a/vq/lspdata.c
+++ /dev/null
@@ -1,157 +0,0 @@
-/********************************************************************
- * *
- * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *
- * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
- * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
- * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
- * *
- * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2001 *
- * by the XIPHOPHORUS Company http://www.xiph.org/ *
- * *
- ********************************************************************
-
- function: metrics and quantization code for LSP VQ codebooks
- last mod: $Id: lspdata.c,v 1.19 2001/12/20 01:00:39 segher Exp $
-
- ********************************************************************/
-
-#include <stdlib.h>
-#include <math.h>
-#include <stdio.h>
-#include "vqgen.h"
-#include "vqext.h"
-#include "codebook.h"
-
-char *vqext_booktype="LSPdata";
-quant_meta q={0,0,0,1}; /* set sequence data */
-int vqext_aux=1;
-
-float global_maxdel=M_PI;
-float global_mindel=M_PI;
-#if 0
-void vqext_quantize(vqgen *v,quant_meta *q){
- float delta,mindel;
- float maxquant=((1<<q->quant)-1);
- int j,k;
-
- /* first find the basic delta amount from the maximum span to be
- encoded. Loosen the delta slightly to allow for additional error
- during sequence quantization */
-
- delta=(global_maxdel-global_mindel)/((1<<q->quant)-1.5f);
-
- q->min=_float32_pack(global_mindel);
- q->delta=_float32_pack(delta);
-
- mindel=_float32_unpack(q->min);
- delta=_float32_unpack(q->delta);
-
- for(j=0;j<v->entries;j++){
- float last=0;
- for(k=0;k<v->elements;k++){
- float val=_now(v,j)[k];
- float now=rint((val-last-mindel)/delta);
-
- _now(v,j)[k]=now;
- if(now<0){
- /* be paranoid; this should be impossible */
- fprintf(stderr,"fault; quantized value<0\n");
- exit(1);
- }
-
- if(now>maxquant){
- /* be paranoid; this should be impossible */
- fprintf(stderr,"fault; quantized value>max\n");
- exit(1);
- }
- last=(now*delta)+mindel+last;
- }
- }
-
-}
-#else
-void vqext_quantize(vqgen *v,quant_meta *q){
- vqgen_quantize(v,q);
-}
-#endif
-
-float *weight=NULL;
-#if 0
-/* LSP training metric. We weight error proportional to distance
- *between* LSP vector values. The idea of this metric is not to set
- final cells, but get the midpoint spacing into a form conducive to
- what we want, which is weighting toward preserving narrower
- features. */
-
-#define FUDGE (global_maxdel-weight[i])
-
-float *vqext_weight(vqgen *v,float *p){
- int i;
- int el=v->elements;
- float lastp=0.f;
- for(i=0;i<el;i++){
- float predist=(p[i]-lastp);
- float postdist=(p[i+1]-p[i]);
- weight[i]=(predist<postdist?predist:postdist);
- lastp=p[i];
- }
- return p;
-}
-#else
-#define FUDGE 1.f
-float *vqext_weight(vqgen *v,float *p){
- return p;
-}
-#endif
-
- /* candidate,actual */
-float vqext_metric(vqgen *v,float *e, float *p){
- int i;
- int el=v->elements;
- float acc=0.f;
- for(i=0;i<el;i++){
- float val=(p[i]-e[i])*FUDGE;
- acc+=val*val;
- }
- return sqrt(acc/v->elements);
-}
-
-/* Data files are line-vectors, now just deltas. The codebook entries
- want to be monotonically increasing, so we adjust */
-
-/* assume vqext_aux==1 */
-void vqext_addpoint_adj(vqgen *v,float *b,int start,int dim,int cols,int num){
- float *a=alloca(sizeof(float)*(dim+1)); /* +aux */
- float base=0;
- int i;
-
- for(i=0;i<dim;i++)
- base=a[i]=b[i+start]+base;
-
- if(start+dim+1>cols) /* +aux */
- a[i]=M_PI;
- else
- a[i]=b[i+start]+base;
-
- vqgen_addpoint(v,a,a+dim);
-}
-
-/* we just need to calc the global_maxdel from the training set */
-void vqext_preprocess(vqgen *v){
- long j,k;
-
- global_maxdel=0.f;
- global_mindel=M_PI;
- for(j=0;j<v->points;j++){
- float last=0.;
- for(k=0;k<v->elements+v->aux;k++){
- float p=_point(v,j)[k];
- if(p-last>global_maxdel)global_maxdel=p-last;
- if(p-last<global_mindel)global_mindel=p-last;
- last=p;
- }
- }
-
- weight=_ogg_malloc(sizeof(float)*v->elements);
-}
-
diff --git a/vq/make_residue_books.pl b/vq/make_residue_books.pl
deleted file mode 100755
index 5411f5a2..00000000
--- a/vq/make_residue_books.pl
+++ /dev/null
@@ -1,168 +0,0 @@
-#!/usr/bin/perl
-
-# quick, very dirty little script so that we can put all the
-# information for building a residue book set (except the original
-# partitioning) in one spec file.
-
-#eg:
-
-# >res0_128_128 interleaved
-# haux res0_96_128aux.vqd 0,4,2
-# :1 res0_128_128_1.vqd, 4, nonseq cull, 0 +- 1
-# :2 res0_128_128_2.vqd, 4, nonseq, 0 +- 1(.7) 2
-# :3 res0_128_128_3.vqd, 4, nonseq, 0 +- 1(.7) 3 5
-# :4 res0_128_128_4.vqd, 2, nonseq, 0 +- 1(.7) 3 5 8 11
-# :5 res0_128_128_5.vqd, 1, nonseq, 0 +- 1 3 5 8 11 14 17 20 24 28 31 35 39
-
-
-die "Could not open $ARGV[0]: $!" unless open (F,$ARGV[0]);
-
-$goflag=0;
-while($line=<F>){
-
- print "#### $line";
- if($line=~m/^GO/){
- $goflag=1;
- next;
- }
-
- if($goflag==0){
- if($line=~m/\S+/ && !($line=~m/^\#/) ){
- my $command=$line;
- print ">>> $command";
- die "Couldn't shell command.\n\tcommand:$command\n"
- if syst($command);
- }
- next;
- }
-
- # >res0_128_128
- if($line=~m/^>(\S+)\s+(\S*)/){
- # set the output name
- $globalname=$1;
- $interleave=$2;
- next;
- }
-
- # haux res0_96_128aux.vqd 0,4,2
- if($line=~m/^h(.*)/){
- # build a huffman book (no mapping)
- my($name,$datafile,$arg)=split(' ',$1);
-
- my $command="huffbuild $datafile $arg";
- print ">>> $command\n";
- die "Couldn't build huffbook.\n\tcommand:$command\n"
- if syst($command);
- next;
- }
-
- # :1 res0_128_128_1.vqd, 4, nonseq, 0 +- 1
- if($line=~m/^:(.*)/){
- my($namedata,$dim,$seqp,$vals)=split(',',$1);
- my($name,$datafile)=split(' ',$namedata);
- # build value list
- my$plusminus="+";
- my$list;
- my$thlist;
- my$count=0;
- foreach my$val (split(' ',$vals)){
- if($val=~/\-?\+?\d+/){
- my$th;
-
- # got an explicit threshhint?
- if($val=~/([0-9\.]+)\(([^\)]+)/){
- $val=$1;
- $th=$2;
- }
-
- if($plusminus=~/-/){
- $list.="-$val ";
- if(defined($th)){
- $thlist.="," if(defined($thlist));
- $thlist.="-$th";
- }
- $count++;
- }
- if($plusminus=~/\+/){
- $list.="$val ";
- if(defined($th)){
- $thlist.="," if(defined($thlist));
- $thlist.="$th";
- }
- $count++;
- }
- }else{
- $plusminus=$val;
- }
- }
- die "Couldn't open temp file temp$$.vql: $!" unless
- open(G,">temp$$.vql");
- print G "$count $dim 0 ";
- if($seqp=~/non/){
- print G "0\n$list\n";
- }else{
- print G "1\n$list\n";
- }
- close(G);
-
- my $command="latticebuild temp$$.vql > $globalname$name.vqh";
- print ">>> $command\n";
- die "Couldn't build latticebook.\n\tcommand:$command\n"
- if syst($command);
-
- my $command="latticehint $globalname$name.vqh $thlist > temp$$.vqh";
- print ">>> $command\n";
- die "Couldn't pre-hint latticebook.\n\tcommand:$command\n"
- if syst($command);
-
- if(-e $datafile){
-
- if($interleave=~/non/){
- $restune="res1tune";
- }else{
- $restune="res0tune";
- }
-
- if($seqp=~/cull/){
- my $command="$restune temp$$.vqh $datafile 1 > $globalname$name.vqh";
- print ">>> $command\n";
- die "Couldn't tune latticebook.\n\tcommand:$command\n"
- if syst($command);
- }else{
- my $command="$restune temp$$.vqh $datafile > $globalname$name.vqh";
- print ">>> $command\n";
- die "Couldn't tune latticebook.\n\tcommand:$command\n"
- if syst($command);
- }
-
- my $command="latticehint $globalname$name.vqh $thlist > temp$$.vqh";
- print ">>> $command\n";
- die "Couldn't post-hint latticebook.\n\tcommand:$command\n"
- if syst($command);
-
- }else{
- print "No matching training file; leaving this codebook untrained.\n";
- }
-
- my $command="mv temp$$.vqh $globalname$name.vqh";
- print ">>> $command\n";
- die "Couldn't rename latticebook.\n\tcommand:$command\n"
- if syst($command);
-
- my $command="rm temp$$.vql";
- print ">>> $command\n";
- die "Couldn't remove temp files.\n\tcommand:$command\n"
- if syst($command);
-
- next;
- }
-}
-
-$command="rm -f temp$$.vqd";
-print ">>> $command\n";
-die "Couldn't remove temp files.\n\tcommand:$command\n"
- if syst($command);
-
-sub syst{
- system(@_)/256;
-}
diff --git a/vq/metrics.c b/vq/metrics.c
deleted file mode 100644
index 237a9565..00000000
--- a/vq/metrics.c
+++ /dev/null
@@ -1,295 +0,0 @@
-/********************************************************************
- * *
- * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *
- * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
- * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
- * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
- * *
- * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2001 *
- * by the XIPHOPHORUS Company http://www.xiph.org/ *
- * *
- ********************************************************************
-
- function: function calls to collect codebook metrics
- last mod: $Id: metrics.c,v 1.15 2001/12/20 01:00:39 segher Exp $
-
- ********************************************************************/
-
-
-#include <stdlib.h>
-#include <unistd.h>
-#include <math.h>
-#include "bookutil.h"
-
-/* collect the following metrics:
-
- mean and mean squared amplitude
- mean and mean squared error
- mean and mean squared error (per sample) by entry
- worst case fit by entry
- entry cell size
- hits by entry
- total bits
- total samples
- (average bits per sample)*/
-
-
-/* set up metrics */
-
-float meanamplitude_acc=0.f;
-float meanamplitudesq_acc=0.f;
-float meanerror_acc=0.f;
-float meanerrorsq_acc=0.f;
-
-float **histogram=NULL;
-float **histogram_error=NULL;
-float **histogram_errorsq=NULL;
-float **histogram_hi=NULL;
-float **histogram_lo=NULL;
-float bits=0.f;
-float count=0.f;
-
-static float *_now(codebook *c, int i){
- return c->valuelist+i*c->c->dim;
-}
-
-int books=0;
-
-void process_preprocess(codebook **bs,char *basename){
- int i;
- while(bs[books])books++;
-
- if(books){
- histogram=_ogg_calloc(books,sizeof(float *));
- histogram_error=_ogg_calloc(books,sizeof(float *));
- histogram_errorsq=_ogg_calloc(books,sizeof(float *));
- histogram_hi=_ogg_calloc(books,sizeof(float *));
- histogram_lo=_ogg_calloc(books,sizeof(float *));
- }else{
- fprintf(stderr,"Specify at least one codebook\n");
- exit(1);
- }
-
- for(i=0;i<books;i++){
- codebook *b=bs[i];
- histogram[i]=_ogg_calloc(b->entries,sizeof(float));
- histogram_error[i]=_ogg_calloc(b->entries*b->dim,sizeof(float));
- histogram_errorsq[i]=_ogg_calloc(b->entries*b->dim,sizeof(float));
- histogram_hi[i]=_ogg_calloc(b->entries*b->dim,sizeof(float));
- histogram_lo[i]=_ogg_calloc(b->entries*b->dim,sizeof(float));
- }
-}
-
-static float _dist(int el,float *a, float *b){
- int i;
- float acc=0.f;
- for(i=0;i<el;i++){
- float val=(a[i]-b[i]);
- acc+=val*val;
- }
- return acc;
-}
-
-void cell_spacing(codebook *c){
- int j,k;
- float min=-1.f,max=-1.f,mean=0.f,meansq=0.f;
- long total=0;
-
- /* minimum, maximum, mean, ms cell spacing */
- for(j=0;j<c->c->entries;j++){
- if(c->c->lengthlist[j]>0){
- float localmin=-1.;
- for(k=0;k<c->c->entries;k++){
- if(c->c->lengthlist[k]>0){
- float this=_dist(c->c->dim,_now(c,j),_now(c,k));
- if(j!=k &&
- (localmin==-1 || this<localmin))
- localmin=this;
- }
- }
-
- if(min==-1 || localmin<min)min=localmin;
- if(max==-1 || localmin>max)max=localmin;
- mean+=sqrt(localmin);
- meansq+=localmin;
- total++;
- }
- }
-
- fprintf(stderr,"\tminimum cell spacing (closest side): %g\n",sqrt(min));
- fprintf(stderr,"\tmaximum cell spacing (closest side): %g\n",sqrt(max));
- fprintf(stderr,"\tmean closest side spacing: %g\n",mean/total);
- fprintf(stderr,"\tmean sq closest side spacing: %g\n",sqrt(meansq/total));
-}
-
-void process_postprocess(codebook **bs,char *basename){
- int i,k,book;
- char *buffer=alloca(strlen(basename)+80);
-
- fprintf(stderr,"Done. Processed %ld data points:\n\n",
- (long)count);
-
- fprintf(stderr,"Global statistics:******************\n\n");
-
- fprintf(stderr,"\ttotal samples: %ld\n",(long)count);
- fprintf(stderr,"\ttotal bits required to code: %ld\n",(long)bits);
- fprintf(stderr,"\taverage bits per sample: %g\n\n",bits/count);
-
- fprintf(stderr,"\tmean sample amplitude: %g\n",
- meanamplitude_acc/count);
- fprintf(stderr,"\tmean squared sample amplitude: %g\n\n",
- sqrt(meanamplitudesq_acc/count));
-
- fprintf(stderr,"\tmean code error: %g\n",
- meanerror_acc/count);
- fprintf(stderr,"\tmean squared code error: %g\n\n",
- sqrt(meanerrorsq_acc/count));
-
- for(book=0;book<books;book++){
- FILE *out;
- codebook *b=bs[book];
- int n=b->c->entries;
- int dim=b->c->dim;
-
- fprintf(stderr,"Book %d statistics:------------------\n",book);
-
- cell_spacing(b);
-
- sprintf(buffer,"%s-%d-mse.m",basename,book);
- out=fopen(buffer,"w");
- if(!out){
- fprintf(stderr,"Could not open file %s for writing\n",buffer);
- exit(1);
- }
-
- for(i=0;i<n;i++){
- for(k=0;k<dim;k++){
- fprintf(out,"%d, %g, %g\n",
- i*dim+k,(b->valuelist+i*dim)[k],
- sqrt((histogram_errorsq[book]+i*dim)[k]/histogram[book][i]));
- }
- }
- fclose(out);
-
- sprintf(buffer,"%s-%d-me.m",basename,book);
- out=fopen(buffer,"w");
- if(!out){
- fprintf(stderr,"Could not open file %s for writing\n",buffer);
- exit(1);
- }
-
- for(i=0;i<n;i++){
- for(k=0;k<dim;k++){
- fprintf(out,"%d, %g, %g\n",
- i*dim+k,(b->valuelist+i*dim)[k],
- (histogram_error[book]+i*dim)[k]/histogram[book][i]);
- }
- }
- fclose(out);
-
- sprintf(buffer,"%s-%d-worst.m",basename,book);
- out=fopen(buffer,"w");
- if(!out){
- fprintf(stderr,"Could not open file %s for writing\n",buffer);
- exit(1);
- }
-
- for(i=0;i<n;i++){
- for(k=0;k<dim;k++){
- fprintf(out,"%d, %g, %g, %g\n",
- i*dim+k,(b->valuelist+i*dim)[k],
- (b->valuelist+i*dim)[k]+(histogram_lo[book]+i*dim)[k],
- (b->valuelist+i*dim)[k]+(histogram_hi[book]+i*dim)[k]);
- }
- }
- fclose(out);
- }
-}
-
-float process_one(codebook *b,int book,float *a,int dim,int step,int addmul,
- float base){
- int j,entry;
- float amplitude=0.f;
-
- if(book==0){
- float last=base;
- for(j=0;j<dim;j++){
- amplitude=a[j*step]-(b->c->q_sequencep?last:0);
- meanamplitude_acc+=fabs(amplitude);
- meanamplitudesq_acc+=amplitude*amplitude;
- count++;
- last=a[j*step];
- }
- }
-
- if(b->c->q_sequencep){
- float temp;
- for(j=0;j<dim;j++){
- temp=a[j*step];
- a[j*step]-=base;
- }
- base=temp;
- }
-
- entry=vorbis_book_besterror(b,a,step,addmul);
-
- if(entry==-1){
- fprintf(stderr,"Internal error: _best returned -1.\n");
- exit(1);
- }
-
- histogram[book][entry]++;
- bits+=vorbis_book_codelen(b,entry);
-
- for(j=0;j<dim;j++){
- float error=a[j*step];
-
- if(book==books-1){
- meanerror_acc+=fabs(error);
- meanerrorsq_acc+=error*error;
- }
- histogram_errorsq[book][entry*dim+j]+=error*error;
- histogram_error[book][entry*dim+j]+=fabs(error);
- if(histogram[book][entry]==0 || histogram_hi[book][entry*dim+j]<error)
- histogram_hi[book][entry*dim+j]=error;
- if(histogram[book][entry]==0 || histogram_lo[book][entry*dim+j]>error)
- histogram_lo[book][entry*dim+j]=error;
- }
- return base;
-}
-
-
-void process_vector(codebook **bs,int *addmul,int inter,float *a,int n){
- int bi;
- int i;
-
- for(bi=0;bi<books;bi++){
- codebook *b=bs[bi];
- int dim=b->dim;
- float base=0.f;
-
- if(inter){
- for(i=0;i<n/dim;i++)
- base=process_one(b,bi,a+i,dim,n/dim,addmul[bi],base);
- }else{
- for(i=0;i<=n-dim;i+=dim)
- base=process_one(b,bi,a+i,dim,1,addmul[bi],base);
- }
- }
-
- if((long)(count)%100)spinnit("working.... samples: ",count);
-}
-
-void process_usage(void){
- fprintf(stderr,
- "usage: vqmetrics [-i] +|*<codebook>.vqh [ +|*<codebook.vqh> ]... \n"
- " datafile.vqd [datafile.vqd]...\n\n"
- " data can be taken on stdin. -i indicates interleaved coding.\n"
- " Output goes to output files:\n"
- " basename-me.m: gnuplot: mean error by entry value\n"
- " basename-mse.m: gnuplot: mean square error by entry value\n"
- " basename-worst.m: gnuplot: worst error by entry value\n"
- " basename-distance.m: gnuplot file showing distance probability\n"
- "\n");
-
-}
diff --git a/vq/residue_entropy b/vq/residue_entropy
deleted file mode 100755
index 49c55a53..00000000
--- a/vq/residue_entropy
+++ /dev/null
@@ -1,58 +0,0 @@
-#!/usr/bin/perl
-
-@quant=(
- 0, 1, 1, 2, 2, 3, 3, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6,
- 6, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
- 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11,
- 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
- 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12
-);
-
-
-use POSIX;
-my($groupn)=@ARGV;
-my%hash;
-my$count=0;
-my$lines=0;
-
-if(!defined($groupn)){
- print "Usage: residue_entropy <groupsize> \n";
- exit(1);
-}
-$|=1;
-
-while (<STDIN>) {
- chop;
- my@nums = ();
- @nums = split(/,/);
- $lines++;
-
- my$step=$#nums/$groupn;
- for(my$i=0;$i<$step;$i++){
- my$key="";
- for(my$j=$i;$j<$#nums;$j+=$step){
- if($nums[$j]<0){
- $num=-$quant[int(-$nums[$j]*2)];
- }else{
- $num=$quant[int($nums[$j]*2)];
- }
- $key.=":$num";
- }
-
- if(!defined($hash{$key})){
- $count++;
- $hash{$key}=1;
- }
- }
-
- if(($lines % 1000)==0){
- print "\rworking... $lines lines, found $count values so far";
- }
-}
-
-foreach $key (keys %hash){
- print "\t$key\n";
-}
-
-print "\r$count values total \n";
-print "Done.\n\n";
diff --git a/vq/residuedata.c b/vq/residuedata.c
deleted file mode 100644
index ed0fa788..00000000
--- a/vq/residuedata.c
+++ /dev/null
@@ -1,160 +0,0 @@
-/********************************************************************
- * *
- * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *
- * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
- * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
- * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
- * *
- * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2001 *
- * by the XIPHOPHORUS Company http://www.xiph.org/ *
- * *
- ********************************************************************
-
- function: metrics and quantization code for residue VQ codebooks
- last mod: $Id: residuedata.c,v 1.10 2001/12/20 01:00:39 segher Exp $
-
- ********************************************************************/
-
-#include <stdlib.h>
-#include <math.h>
-#include <stdio.h>
-#include <string.h>
-#include "vqgen.h"
-#include "bookutil.h"
-#include "../lib/scales.h"
-#include "vqext.h"
-
-float scalequant=3.f;
-char *vqext_booktype="RESdata";
-quant_meta q={0,0,0,0}; /* set sequence data */
-int vqext_aux=0;
-
-static float *quant_save=NULL;
-
-float *vqext_weight(vqgen *v,float *p){
- return p;
-}
-
-/* quantize aligned on unit boundaries. Because our grid is likely
- very coarse, play 'shuffle the blocks'; don't allow multiple
- entries to fill the same spot as is nearly certain to happen. */
-
-void vqext_quantize(vqgen *v,quant_meta *q){
- int j,k;
- long dim=v->elements;
- long n=v->entries;
- float max=-1;
- float *test=alloca(sizeof(float)*dim);
- int moved=0;
-
-
- /* allow movement only to unoccupied coordinates on the coarse grid */
- for(j=0;j<n;j++){
- for(k=0;k<dim;k++){
- float val=_now(v,j)[k];
- float norm=rint(fabs(val)/scalequant);
- if(norm>max)max=norm;
- test[k]=norm;
- }
-
- /* allow move only if unoccupied */
- if(quant_save){
- for(k=0;k<n;k++)
- if(j!=k && memcmp(test,quant_save+dim*k,dim*sizeof(float))==0)
- break;
- if(k==n){
- if(memcmp(test,quant_save+dim*j,dim*sizeof(float)))
- moved++;
- memcpy(quant_save+dim*j,test,sizeof(float)*dim);
- }
- }else{
- memcpy(_now(v,j),test,sizeof(float)*dim);
- }
- }
-
- /* unlike the other trainers, we fill in our quantization
- information (as we know granularity beforehand and don't need to
- maximize it) */
-
- q->min=_float32_pack(0.f);
- q->delta=_float32_pack(scalequant);
- q->quant=_ilog(max);
-
- if(quant_save){
- memcpy(_now(v,0),quant_save,sizeof(float)*dim*n);
- fprintf(stderr,"cells shifted this iteration: %d\n",moved);
- }
-}
-
- /* candidate,actual */
-float vqext_metric(vqgen *v,float *e, float *p){
- int i;
- float acc=0.f;
- for(i=0;i<v->elements;i++){
- float val=p[i]-e[i];
- acc+=val*val;
- }
- return sqrt(acc);
-}
-
-/* We don't interleave here; we assume that the interleave is provided
- for us by residuesplit in vorbis/huff/ */
-void vqext_addpoint_adj(vqgen *v,float *b,int start,int dim,int cols,int num){
- vqgen_addpoint(v,b+start,NULL);
-}
-
-/* need to reseed because of the coarse quantization we tend to use on
- residuals (which causes lots & lots of dupes) */
-void vqext_preprocess(vqgen *v){
- long i,j,k,l;
- float *test=alloca(sizeof(float)*v->elements);
- scalequant=q.quant;
-
- vqext_quantize(v,&q);
- vqgen_unquantize(v,&q);
-
- /* if there are any dupes, reseed */
- for(k=0;k<v->entries;k++){
- for(l=0;l<k;l++){
- if(memcmp(_now(v,k),_now(v,l),sizeof(float)*v->elements)==0)
- break;
- }
- if(l<k)break;
- }
-
- if(k<v->entries){
- fprintf(stderr,"reseeding with quantization....\n");
-
- /* seed the inputs to input points, but points on unit boundaries,
- ignoring quantbits for now, making sure each seed is unique */
-
- for(i=0,j=0;i<v->points && j<v->entries;i++){
- for(k=0;k<v->elements;k++){
- float val=_point(v,i)[k];
- test[k]=rint(val/scalequant)*scalequant;
- }
-
- for(l=0;l<j;l++){
- for(k=0;k<v->elements;k++)
- if(test[k]!=_now(v,l)[k])
- break;
- if(k==v->elements)break;
- }
- if(l==j){
- memcpy(_now(v,j),test,v->elements*sizeof(float));
- j++;
- }
- }
-
- if(j<v->elements){
- fprintf(stderr,"Not enough unique entries after prequantization\n");
- exit(1);
- }
- }
- vqext_quantize(v,&q);
- quant_save=_ogg_malloc(sizeof(float)*v->elements*v->entries);
- memcpy(quant_save,_now(v,0),sizeof(float)*v->elements*v->entries);
- vqgen_unquantize(v,&q);
-
-}
-
diff --git a/vq/residuesplit.c b/vq/residuesplit.c
deleted file mode 100644
index 0a136f52..00000000
--- a/vq/residuesplit.c
+++ /dev/null
@@ -1,282 +0,0 @@
-/********************************************************************
- * *
- * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *
- * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
- * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
- * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
- * *
- * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2001 *
- * by the XIPHOPHORUS Company http://www.xiph.org/ *
- * *
- ********************************************************************
-
- function: residue backend 0 partitioner/classifier
- last mod: $Id: residuesplit.c,v 1.13 2001/12/20 01:00:40 segher Exp $
-
- ********************************************************************/
-
-#include <stdlib.h>
-#include <string.h>
-#include <math.h>
-#include <stdio.h>
-#include "bookutil.h"
-
-/* does not guard against invalid settings; eg, a subn of 16 and a
- subgroup request of 32. Max subn of 128 */
-static float _testhack(float *vec,int n){
- int i,j=0;
- float max=0.f;
- float temp[128];
- float entropy=0.;
-
- /* setup */
- for(i=0;i<n;i++)temp[i]=fabs(vec[i]);
-
- /* handle case subgrp==1 outside */
- for(i=0;i<n;i++)
- if(temp[i]>max)max=temp[i];
-
- for(i=0;i<n;i++)temp[i]=rint(temp[i]);
-
- for(i=0;i<n;i++)
- entropy+=temp[i];
- return entropy;
-
- /*while(1){
- entropy[j]=max;
- n>>=1;
- j++;
-
- if(n<=0)break;
- for(i=0;i<n;i++){
- temp[i]+=temp[i+n];
- }
- max=0.f;
- for(i=0;i<n;i++)
- if(temp[i]>max)max=temp[i];
- }*/
-}
-
-static FILE *of;
-static FILE **or;
-
-/* we evaluate the the entropy measure for each interleaved subgroup */
-/* This is currently a bit specific to/hardwired for mapping 0; things
- will need to change in the future when we get real multichannel
- mappings */
-int quantaux(float *res,int n,float *ebound,float *mbound,int *subgrp,int parts, int subn,
- int *class){
- long i,j,part=0;
- int aux;
-
- for(i=0;i<=n-subn;i+=subn,part++){
- float max=0.f;
- float lentropy=0.f;
-
- lentropy=_testhack(res+i,subn);
-
- for(j=0;j<subn;j++)
- if(fabs(res[i+j])>max)max=fabs(res[i+j]);
-
- for(j=0;j<parts-1;j++)
- if(lentropy<=ebound[j] &&
- max<=mbound[j] &&
- part<subgrp[j])
- break;
- class[part]=aux=j;
-
- fprintf(of,"%d, ",aux);
- }
- fprintf(of,"\n");
-
- return(0);
-}
-
-int quantwrite(float *res,int n,int subn, int *class,int offset){
- long i,j,part=0;
- int aux;
-
- for(i=0;i<=n-subn;i+=subn,part++){
- aux=class[part];
-
- for(j=0;j<subn;j++)
- fprintf(or[aux+offset],"%g, ",res[j+i]);
-
- fprintf(or[aux+offset],"\n");
- }
-
- return(0);
-}
-
-static int getline(FILE *in,float *vec,int begin,int n){
- int i,next=0;
-
- reset_next_value();
- if(get_next_value(in,vec))return(0);
- if(begin){
- for(i=1;i<begin;i++)
- get_line_value(in,vec);
- next=0;
- }else{
- next=1;
- }
-
- for(i=next;i<n;i++)
- if(get_line_value(in,vec+i)){
- fprintf(stderr,"ran out of columns in input data\n");
- exit(1);
- }
-
- return(1);
-}
-
-static void usage(){
- fprintf(stderr,
- "usage:\n"
- "residuesplit <res> [<res>] <begin,n,group> <baseout> <ent,peak,sub> [<ent,peak,sub>]...\n"
- " where begin,n,group is first scalar, \n"
- " number of scalars of each in line,\n"
- " number of scalars in a group\n"
- " ent is the maximum entropy value allowed for membership in a group\n"
- " peak is the maximum amplitude value allowed for membership in a group\n"
- " subn is the maximum subpartiton number allowed in the group\n\n");
- exit(1);
-}
-
-int main(int argc, char *argv[]){
- char *buffer;
- char *base;
- int i,j,parts,begin,n,subn,*subgrp,*class;
- FILE **res;
- int resfiles=0;
- float *ebound,*mbound,*vec;
- long c=0;
- if(argc<5)usage();
-
- /* count the res file names, open the files */
- while(!strcmp(argv[resfiles+1]+strlen(argv[resfiles+1])-4,".vqd"))
- resfiles++;
- if(resfiles<1)usage();
-
- res=alloca(sizeof(*res)*resfiles);
- for(i=0;i<resfiles;i++){
- res[i]=fopen(argv[i+1],"r");
- if(!(res+i)){
- fprintf(stderr,"Could not open file %s\n",argv[1+i]);
- exit(1);
- }
- }
-
- base=strdup(argv[2+resfiles]);
- buffer=alloca(strlen(base)+20);
- {
- char *pos=strchr(argv[1+resfiles],',');
- begin=atoi(argv[1+resfiles]);
- if(!pos)
- usage();
- else
- n=atoi(pos+1);
- pos=strchr(pos+1,',');
- if(!pos)
- usage();
- else
- subn=atoi(pos+1);
- if(n/subn*subn != n){
- fprintf(stderr,"n must be divisible by group\n");
- exit(1);
- }
- }
-
- /* how many parts?... */
- parts=argc-resfiles-2;
-
- ebound=_ogg_malloc(sizeof(float)*parts);
- mbound=_ogg_malloc(sizeof(float)*parts);
- subgrp=_ogg_malloc(sizeof(int)*parts);
-
- for(i=0;i<parts-1;i++){
- char *pos=strchr(argv[3+i+resfiles],',');
- subgrp[i]=0;
- if(*argv[3+i+resfiles]==',')
- ebound[i]=1e50f;
- else
- ebound[i]=atof(argv[3+i+resfiles]);
-
- if(!pos){
- mbound[i]=1e50f;
- }else{
- if(*(pos+1)==',')
- mbound[i]=1e50f;
- else
- mbound[i]=atof(pos+1);
- pos=strchr(pos+1,',');
-
- if(pos)
- subgrp[i]=atoi(pos+1);
-
- }
- if(subgrp[i]<=0)subgrp[i]=99999;
- }
-
- ebound[i]=1e50f;
- mbound[i]=1e50f;
- subgrp[i]=9999999;
-
- or=alloca(parts*resfiles*sizeof(FILE*));
- sprintf(buffer,"%saux.vqd",base);
- of=fopen(buffer,"w");
- if(!of){
- fprintf(stderr,"Could not open file %s for writing\n",buffer);
- exit(1);
- }
-
- for(j=0;j<resfiles;j++){
- for(i=0;i<parts;i++){
- sprintf(buffer,"%s_%d%c.vqd",base,i,j+65);
- or[i+j*parts]=fopen(buffer,"w");
- if(!or[i+j*parts]){
- fprintf(stderr,"Could not open file %s for writing\n",buffer);
- exit(1);
- }
- }
- }
-
- vec=_ogg_malloc(sizeof(float)*n);
- class=_ogg_malloc(sizeof(float)*n);
- /* get the input line by line and process it */
- while(1){
- if(getline(res[0],vec,begin,n)){
- quantaux(vec,n,ebound,mbound,subgrp,parts,subn,class);
- quantwrite(vec,n,subn,class,0);
-
- for(i=1;i<resfiles;i++){
- if(getline(res[i],vec,begin,n)){
- quantwrite(vec,n,subn,class,parts*i);
- }else{
- fprintf(stderr,"Getline loss of sync (%d).\n\n",i);
- exit(1);
- }
- }
- }else{
- if(feof(res[0]))break;
- fprintf(stderr,"Getline loss of sync (0).\n\n");
- exit(1);
- }
-
- c++;
- if(!(c&0xf)){
- spinnit("kB so far...",(int)(ftell(res[0])/1024));
- }
- }
- for(i=0;i<resfiles;i++)
- fclose(res[i]);
- fclose(of);
- for(i=0;i<parts*resfiles;i++)
- fclose(or[i]);
- fprintf(stderr,"\rDone \n");
- return(0);
-}
-
-
-
-
diff --git a/vq/run.c b/vq/run.c
deleted file mode 100644
index 40df4a24..00000000
--- a/vq/run.c
+++ /dev/null
@@ -1,216 +0,0 @@
-/********************************************************************
- * *
- * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *
- * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
- * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
- * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
- * *
- * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2001 *
- * by the XIPHOPHORUS Company http://www.xiph.org/ *
- * *
- ********************************************************************
-
- function: utility main for loading and operating on codebooks
- last mod: $Id: run.c,v 1.15 2001/12/20 01:00:40 segher Exp $
-
- ********************************************************************/
-
-#include <unistd.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <math.h>
-#include <string.h>
-#include <errno.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <fcntl.h>
-
-#include "bookutil.h"
-
-/* command line:
- utilname [-i] +|* input_book.vqh [+|* input_book.vqh]
- input_data.vqd [input_data.vqd]
-
- produces output data on stdout
- (may also take input data from stdin)
-
- */
-
-extern void process_preprocess(codebook **b,char *basename);
-extern void process_postprocess(codebook **b,char *basename);
-extern void process_vector(codebook **b,int *addmul, int inter,float *a,int n);
-extern void process_usage(void);
-
-int main(int argc,char *argv[]){
- char *basename;
- codebook **b=_ogg_calloc(1,sizeof(codebook *));
- int *addmul=_ogg_calloc(1,sizeof(int));
- int books=0;
- int input=0;
- int interleave=0;
- int j;
- int start=0;
- int num=-1;
- argv++;
-
- if(*argv==NULL){
- process_usage();
- exit(1);
- }
-
- /* yes, this is evil. However, it's very convenient to parse file
- extentions */
-
- while(*argv){
- if(*argv[0]=='-'){
- /* option */
- if(argv[0][1]=='s'){
- /* subvector */
- if(sscanf(argv[1],"%d,%d",&start,&num)!=2){
- num= -1;
- if(sscanf(argv[1],"%d",&start)!=1){
- fprintf(stderr,"Syntax error using -s\n");
- exit(1);
- }
- }
- argv+=2;
- }
- if(argv[0][1]=='i'){
- /* interleave */
- interleave=1;
- argv+=1;
- }
- }else{
- /* input file. What kind? */
- char *dot;
- char *ext=NULL;
- char *name=strdup(*argv++);
- dot=strrchr(name,'.');
- if(dot)
- ext=dot+1;
- else
- ext="";
-
- /* codebook */
- if(!strcmp(ext,"vqh")){
- int multp=0;
- if(input){
- fprintf(stderr,"specify all input data (.vqd) files following\n"
- "codebook header (.vqh) files\n");
- exit(1);
- }
- /* is it additive or multiplicative? */
- if(name[0]=='*'){
- multp=1;
- name++;
- }
- if(name[0]=='+')name++;
-
- basename=strrchr(name,'/');
- if(basename)
- basename=strdup(basename)+1;
- else
- basename=strdup(name);
- dot=strrchr(basename,'.');
- if(dot)*dot='\0';
-
- b=_ogg_realloc(b,sizeof(codebook *)*(books+2));
- b[books]=codebook_load(name);
- addmul=_ogg_realloc(addmul,sizeof(int)*(books+1));
- addmul[books++]=multp;
- b[books]=NULL;
- }
-
- /* data file */
- if(!strcmp(ext,"vqd")){
- int cols;
- long lines=0;
- char *line;
- float *vec;
- FILE *in=fopen(name,"r");
- if(!in){
- fprintf(stderr,"Could not open input file %s\n",name);
- exit(1);
- }
-
- if(!input){
- process_preprocess(b,basename);
- input++;
- }
-
- reset_next_value();
- line=setup_line(in);
- /* count cols before we start reading */
- {
- char *temp=line;
- while(*temp==' ')temp++;
- for(cols=0;*temp;cols++){
- while(*temp>32)temp++;
- while(*temp==' ')temp++;
- }
- }
- vec=alloca(cols*sizeof(float));
- while(line){
- lines++;
- for(j=0;j<cols;j++)
- if(get_line_value(in,vec+j)){
- fprintf(stderr,"Too few columns on line %ld in data file\n",lines);
- exit(1);
- }
- /* ignores -s for now */
- process_vector(b,addmul,interleave,vec,cols);
-
- line=setup_line(in);
- }
- fclose(in);
- }
- }
- }
-
- /* take any data from stdin */
- {
- struct stat st;
- if(fstat(STDIN_FILENO,&st)==-1){
- fprintf(stderr,"Could not stat STDIN\n");
- exit(1);
- }
- if((S_IFIFO|S_IFREG|S_IFSOCK)&st.st_mode){
- int cols;
- char *line;
- long lines=0;
- float *vec;
- if(!input){
- process_preprocess(b,basename);
- input++;
- }
-
- line=setup_line(stdin);
- /* count cols before we start reading */
- {
- char *temp=line;
- while(*temp==' ')temp++;
- for(cols=0;*temp;cols++){
- while(*temp>32)temp++;
- while(*temp==' ')temp++;
- }
- }
- vec=alloca(cols*sizeof(float));
- while(line){
- lines++;
- for(j=0;j<cols;j++)
- if(get_line_value(stdin,vec+j)){
- fprintf(stderr,"Too few columns on line %ld in data file\n",lines);
- exit(1);
- }
- /* ignores -s for now */
- process_vector(b,addmul,interleave,vec,cols);
-
- line=setup_line(stdin);
- }
- }
- }
-
- process_postprocess(b,basename);
-
- return 0;
-}
diff --git a/vq/train.c b/vq/train.c
deleted file mode 100644
index 474d2661..00000000
--- a/vq/train.c
+++ /dev/null
@@ -1,364 +0,0 @@
-/********************************************************************
- * *
- * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *
- * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
- * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
- * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
- * *
- * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2001 *
- * by the XIPHOPHORUS Company http://www.xiph.org/ *
- * *
- ********************************************************************
-
- function: utility main for training codebooks
- last mod: $Id: train.c,v 1.24 2001/12/20 01:00:40 segher Exp $
-
- ********************************************************************/
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <math.h>
-#include <string.h>
-#include <errno.h>
-#include <signal.h>
-#include "vqgen.h"
-#include "vqext.h"
-#include "bookutil.h"
-
-static char *rline(FILE *in,FILE *out,int pass){
- while(1){
- char *line=get_line(in);
- if(line && line[0]=='#'){
- if(pass)fprintf(out,"%s\n",line);
- }else{
- return(line);
- }
- }
-}
-
-/* command line:
- trainvq vqfile [options] trainfile [trainfile]
-
- options: -params entries,dim,quant
- -subvector start[,num]
- -error desired_error
- -iterations iterations
-*/
-
-static void usage(void){
- fprintf(stderr, "\nOggVorbis %s VQ codebook trainer\n\n"
- "<foo>vqtrain vqfile [options] [datasetfile] [datasetfile]\n"
- "options: -p[arams] <entries,dim,quant>\n"
- " -s[ubvector] <start[,num]>\n"
- " -e[rror] <desired_error>\n"
- " -i[terations] <maxiterations>\n"
- " -d[istance] quantization mesh spacing for density limitation\n"
- " -b <dummy> eliminate cell size biasing; use normal LBG\n\n"
- " -c <dummy> Use centroid (not median) midpoints\n"
-
- "examples:\n"
- " train a new codebook to 1%% tolerance on datafile 'foo':\n"
- " xxxvqtrain book -p 256,6,8 -e .01 foo\n"
- " (produces a trained set in book-0.vqi)\n\n"
- " continue training 'book-0.vqi' (produces book-1.vqi):\n"
- " xxxvqtrain book-0.vqi\n\n"
- " add subvector from element 1 to <dimension> from files\n"
- " data*.m to the training in progress, prodicing book-1.vqi:\n"
- " xxxvqtrain book-0.vqi -s 1,1 data*.m\n\n",vqext_booktype);
-}
-
-int exiting=0;
-void setexit(int dummy){
- fprintf(stderr,"\nexiting... please wait to finish this iteration\n");
- exiting=1;
-}
-
-int main(int argc,char *argv[]){
- vqgen v;
-
- int entries=-1,dim=-1;
- int start=0,num=-1;
- float desired=.05f,mindist=0.f;
- int iter=1000;
- int biasp=1;
- int centroid=0;
-
- FILE *out=NULL;
- char *line;
- long i,j,k;
- int init=0;
- q.quant=-1;
-
- argv++;
- if(!*argv){
- usage();
- exit(0);
- }
-
- /* get the book name, a preexisting book to continue training */
- {
- FILE *in=NULL;
- char *filename=alloca(strlen(*argv)+30),*ptr;
-
- strcpy(filename,*argv);
- in=fopen(filename,"r");
- ptr=strrchr(filename,'-');
- if(ptr){
- int num;
- ptr++;
- num=atoi(ptr);
- sprintf(ptr,"%d.vqi",num+1);
- }else
- strcat(filename,"-0.vqi");
-
- out=fopen(filename,"w");
- if(out==NULL){
- fprintf(stderr,"Unable to open %s for writing\n",filename);
- exit(1);
- }
-
- if(in){
- /* we wish to suck in a preexisting book and continue to train it */
- float a;
-
- line=rline(in,out,1);
- if(strcmp(line,vqext_booktype)){
- fprintf(stderr,"wrong book type; %s!=%s\n",line,vqext_booktype);
- exit(1);
- }
-
- line=rline(in,out,1);
- if(sscanf(line,"%d %d %d",&entries,&dim,&vqext_aux)!=3){
- fprintf(stderr,"Syntax error reading book file\n");
- exit(1);
- }
-
- vqgen_init(&v,dim,vqext_aux,entries,mindist,
- vqext_metric,vqext_weight,centroid);
- init=1;
-
- /* quant setup */
- line=rline(in,out,1);
- if(sscanf(line,"%ld %ld %d %d",&q.min,&q.delta,
- &q.quant,&q.sequencep)!=4){
- fprintf(stderr,"Syntax error reading book file\n");
- exit(1);
- }
-
- /* quantized entries */
- i=0;
- for(j=0;j<entries;j++){
- for(k=0;k<dim;k++){
- line=rline(in,out,0);
- sscanf(line,"%f",&a);
- v.entrylist[i++]=a;
- }
- }
- vqgen_unquantize(&v,&q);
-
- /* bias */
- i=0;
- for(j=0;j<entries;j++){
- line=rline(in,out,0);
- sscanf(line,"%f",&a);
- v.bias[i++]=a;
- }
-
- v.seeded=1;
- {
- float *b=alloca((dim+vqext_aux)*sizeof(float));
- i=0;
- while(1){
- for(k=0;k<dim+vqext_aux;k++){
- line=rline(in,out,0);
- if(!line)break;
- sscanf(line,"%f",b+k);
- }
- if(feof(in))break;
- vqgen_addpoint(&v,b,b+dim);
- }
- }
-
- fclose(in);
- }
- }
-
- /* get the rest... */
- argv=argv++;
- while(*argv){
- if(argv[0][0]=='-'){
- /* it's an option */
- if(!argv[1]){
- fprintf(stderr,"Option %s missing argument.\n",argv[0]);
- exit(1);
- }
- switch(argv[0][1]){
- case 'p':
- if(sscanf(argv[1],"%d,%d,%d",&entries,&dim,&q.quant)!=3)
- goto syner;
- break;
- case 's':
- if(sscanf(argv[1],"%d,%d",&start,&num)!=2){
- num= -1;
- if(sscanf(argv[1],"%d",&start)!=1)
- goto syner;
- }
- break;
- case 'e':
- if(sscanf(argv[1],"%f",&desired)!=1)
- goto syner;
- break;
- case 'd':
- if(sscanf(argv[1],"%f",&mindist)!=1)
- goto syner;
- if(init)v.mindist=mindist;
- break;
- case 'i':
- if(sscanf(argv[1],"%d",&iter)!=1)
- goto syner;
- break;
- case 'b':
- biasp=0;
- break;
- case 'c':
- centroid=1;
- break;
- default:
- fprintf(stderr,"Unknown option %s\n",argv[0]);
- exit(1);
- }
- argv+=2;
- }else{
- /* it's an input file */
- char *file=strdup(*argv++);
- FILE *in;
- int cols=-1;
-
- if(!init){
- if(dim==-1 || entries==-1 || q.quant==-1){
- fprintf(stderr,"-p required when training a new set\n");
- exit(1);
- }
- vqgen_init(&v,dim,vqext_aux,entries,mindist,
- vqext_metric,vqext_weight,centroid);
- init=1;
- }
-
- in=fopen(file,"r");
- if(in==NULL){
- fprintf(stderr,"Could not open input file %s\n",file);
- exit(1);
- }
- fprintf(out,"# training file entry: %s\n",file);
-
- while((line=rline(in,out,0))){
- if(cols==-1){
- char *temp=line;
- while(*temp==' ')temp++;
- for(cols=0;*temp;cols++){
- while(*temp>32)temp++;
- while(*temp==' ')temp++;
- }
-
- fprintf(stderr,"%d colums per line in file %s\n",cols,file);
-
- }
- {
- int i;
- float b[cols];
- if(start+num*dim>cols){
- fprintf(stderr,"ran out of columns reading %s\n",file);
- exit(1);
- }
- while(*line==' ')line++;
- for(i=0;i<cols;i++){
-
- /* static length buffer bug workaround */
- char *temp=line;
- char old;
- while(*temp>32)temp++;
-
- old=temp[0];
- temp[0]='\0';
- b[i]=atof(line);
- temp[0]=old;
-
- while(*line>32)line++;
- while(*line==' ')line++;
- }
- if(num<=0)num=(cols-start)/dim;
- for(i=0;i<num;i++)
- vqext_addpoint_adj(&v,b,start+i*dim,dim,cols,num);
-
- }
- }
- fclose(in);
- }
- }
-
- if(!init){
- fprintf(stderr,"No input files!\n");
- exit(1);
- }
-
- vqext_preprocess(&v);
-
- /* train the book */
- signal(SIGTERM,setexit);
- signal(SIGINT,setexit);
-
- for(i=0;i<iter && !exiting;i++){
- float result;
- if(i!=0){
- vqgen_unquantize(&v,&q);
- vqgen_cellmetric(&v);
- }
- result=vqgen_iterate(&v,biasp);
- vqext_quantize(&v,&q);
- if(result<desired)break;
- }
-
- /* save the book */
-
- fprintf(out,"# OggVorbis VQ codebook trainer, intermediate file\n");
- fprintf(out,"%s\n",vqext_booktype);
- fprintf(out,"%d %d %d\n",entries,dim,vqext_aux);
- fprintf(out,"%ld %ld %d %d\n",
- q.min,q.delta,q.quant,q.sequencep);
-
- /* quantized entries */
- fprintf(out,"# quantized entries---\n");
- i=0;
- for(j=0;j<entries;j++)
- for(k=0;k<dim;k++)
- fprintf(out,"%d\n",(int)(rint(v.entrylist[i++])));
-
- fprintf(out,"# biases---\n");
- i=0;
- for(j=0;j<entries;j++)
- fprintf(out,"%f\n",v.bias[i++]);
-
- /* we may have done the density limiting mesh trick; refetch the
- training points from the temp file */
-
- rewind(v.asciipoints);
- fprintf(out,"# points---\n");
- {
- /* sloppy, no error handling */
- long bytes;
- char buff[4096];
- while((bytes=fread(buff,1,4096,v.asciipoints)))
- while(bytes)bytes-=fwrite(buff,1,bytes,out);
- }
-
- fclose(out);
- fclose(v.asciipoints);
-
- vqgen_unquantize(&v,&q);
- vqgen_cellmetric(&v);
- exit(0);
-
- syner:
- fprintf(stderr,"Syntax error in argument '%s'\n",*argv);
- exit(1);
-}
diff --git a/vq/vqext.h b/vq/vqext.h
deleted file mode 100644
index 74fa2c1f..00000000
--- a/vq/vqext.h
+++ /dev/null
@@ -1,34 +0,0 @@
-/********************************************************************
- * *
- * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *
- * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
- * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
- * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
- * *
- * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2001 *
- * by the XIPHOPHORUS Company http://www.xiph.org/ *
- * *
- ********************************************************************
-
- function: prototypes for extermal metrics specific to data type
- last mod: $Id: vqext.h,v 1.14 2001/12/20 01:00:40 segher Exp $
-
- ********************************************************************/
-
-#ifndef _V_VQEXT_
-#define _V_VQEXT_
-
-#include "vqgen.h"
-
-extern char *vqext_booktype;
-extern quant_meta q;
-extern int vqext_aux;
-
-extern float vqext_metric(vqgen *v,float *e, float *p);
-extern float *vqext_weight(vqgen *v,float *p);
-extern void vqext_addpoint_adj(vqgen *v,float *b,int start,int dim,int cols,int num);
-extern void vqext_preprocess(vqgen *v);
-extern void vqext_quantize(vqgen *v,quant_meta *);
-
-
-#endif
diff --git a/vq/vqgen.c b/vq/vqgen.c
deleted file mode 100644
index 3407c6f9..00000000
--- a/vq/vqgen.c
+++ /dev/null
@@ -1,568 +0,0 @@
-/********************************************************************
- * *
- * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *
- * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
- * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
- * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
- * *
- * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2001 *
- * by the XIPHOPHORUS Company http://www.xiph.org/ *
- * *
- ********************************************************************
-
- function: train a VQ codebook
- last mod: $Id: vqgen.c,v 1.40 2001/12/20 01:00:40 segher Exp $
-
- ********************************************************************/
-
-/* This code is *not* part of libvorbis. It is used to generate
- trained codebooks offline and then spit the results into a
- pregenerated codebook that is compiled into libvorbis. It is an
- expensive (but good) algorithm. Run it on big iron. */
-
-/* There are so many optimizations to explore in *both* stages that
- considering the undertaking is almost withering. For now, we brute
- force it all */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <math.h>
-#include <string.h>
-
-#include "vqgen.h"
-#include "bookutil.h"
-
-/* Codebook generation happens in two steps:
-
- 1) Train the codebook with data collected from the encoder: We use
- one of a few error metrics (which represent the distance between a
- given data point and a candidate point in the training set) to
- divide the training set up into cells representing roughly equal
- probability of occurring.
-
- 2) Generate the codebook and auxiliary data from the trained data set
-*/
-
-/* Codebook training ****************************************************
- *
- * The basic idea here is that a VQ codebook is like an m-dimensional
- * foam with n bubbles. The bubbles compete for space/volume and are
- * 'pressurized' [biased] according to some metric. The basic alg
- * iterates through allowing the bubbles to compete for space until
- * they converge (if the damping is dome properly) on a steady-state
- * solution. Individual input points, collected from libvorbis, are
- * used to train the algorithm monte-carlo style. */
-
-/* internal helpers *****************************************************/
-#define vN(data,i) (data+v->elements*i)
-
-/* default metric; squared 'distance' from desired value. */
-float _dist(vqgen *v,float *a, float *b){
- int i;
- int el=v->elements;
- float acc=0.f;
- for(i=0;i<el;i++){
- float val=(a[i]-b[i]);
- acc+=val*val;
- }
- return sqrt(acc);
-}
-
-float *_weight_null(vqgen *v,float *a){
- return a;
-}
-
-/* *must* be beefed up. */
-void _vqgen_seed(vqgen *v){
- long i;
- for(i=0;i<v->entries;i++)
- memcpy(_now(v,i),_point(v,i),sizeof(float)*v->elements);
- v->seeded=1;
-}
-
-int directdsort(const void *a, const void *b){
- float av=*((float *)a);
- float bv=*((float *)b);
- if(av>bv)return(-1);
- return(1);
-}
-
-void vqgen_cellmetric(vqgen *v){
- int j,k;
- float min=-1.f,max=-1.f,mean=0.f,acc=0.f;
- long dup=0,unused=0;
- #ifdef NOISY
- int i;
- char buff[80];
- float spacings[v->entries];
- int count=0;
- FILE *cells;
- sprintf(buff,"cellspace%d.m",v->it);
- cells=fopen(buff,"w");
-#endif
-
- /* minimum, maximum, cell spacing */
- for(j=0;j<v->entries;j++){
- float localmin=-1.;
-
- for(k=0;k<v->entries;k++){
- if(j!=k){
- float this=_dist(v,_now(v,j),_now(v,k));
- if(this>0){
- if(v->assigned[k] && (localmin==-1 || this<localmin))
- localmin=this;
- }else{
- if(k<j){
- dup++;
- break;
- }
- }
- }
- }
- if(k<v->entries)continue;
-
- if(v->assigned[j]==0){
- unused++;
- continue;
- }
-
- localmin=v->max[j]+localmin/2; /* this gives us rough diameter */
- if(min==-1 || localmin<min)min=localmin;
- if(max==-1 || localmin>max)max=localmin;
- mean+=localmin;
- acc++;
-#ifdef NOISY
- spacings[count++]=localmin;
-#endif
- }
-
- fprintf(stderr,"cell diameter: %.03g::%.03g::%.03g (%ld unused/%ld dup)\n",
- min,mean/acc,max,unused,dup);
-
-#ifdef NOISY
- qsort(spacings,count,sizeof(float),directdsort);
- for(i=0;i<count;i++)
- fprintf(cells,"%g\n",spacings[i]);
- fclose(cells);
-#endif
-
-}
-
-/* External calls *******************************************************/
-
-/* We have two forms of quantization; in the first, each vector
- element in the codebook entry is orthogonal. Residues would use this
- quantization for example.
-
- In the second, we have a sequence of monotonically increasing
- values that we wish to quantize as deltas (to save space). We
- still need to quantize so that absolute values are accurate. For
- example, LSP quantizes all absolute values, but the book encodes
- distance between values because each successive value is larger
- than the preceeding value. Thus the desired quantibits apply to
- the encoded (delta) values, not abs positions. This requires minor
- additional encode-side trickery. */
-
-void vqgen_quantize(vqgen *v,quant_meta *q){
-
- float maxdel;
- float mindel;
-
- float delta;
- float maxquant=((1<<q->quant)-1);
-
- int j,k;
-
- mindel=maxdel=_now(v,0)[0];
-
- for(j=0;j<v->entries;j++){
- float last=0.f;
- for(k=0;k<v->elements;k++){
- if(mindel>_now(v,j)[k]-last)mindel=_now(v,j)[k]-last;
- if(maxdel<_now(v,j)[k]-last)maxdel=_now(v,j)[k]-last;
- if(q->sequencep)last=_now(v,j)[k];
- }
- }
-
-
- /* first find the basic delta amount from the maximum span to be
- encoded. Loosen the delta slightly to allow for additional error
- during sequence quantization */
-
- delta=(maxdel-mindel)/((1<<q->quant)-1.5f);
-
- q->min=_float32_pack(mindel);
- q->delta=_float32_pack(delta);
-
- mindel=_float32_unpack(q->min);
- delta=_float32_unpack(q->delta);
-
- for(j=0;j<v->entries;j++){
- float last=0;
- for(k=0;k<v->elements;k++){
- float val=_now(v,j)[k];
- float now=rint((val-last-mindel)/delta);
-
- _now(v,j)[k]=now;
- if(now<0){
- /* be paranoid; this should be impossible */
- fprintf(stderr,"fault; quantized value<0\n");
- exit(1);
- }
-
- if(now>maxquant){
- /* be paranoid; this should be impossible */
- fprintf(stderr,"fault; quantized value>max\n");
- exit(1);
- }
- if(q->sequencep)last=(now*delta)+mindel+last;
- }
- }
-}
-
-/* much easier :-). Unlike in the codebook, we don't un-log log
- scales; we just make sure they're properly offset. */
-void vqgen_unquantize(vqgen *v,quant_meta *q){
- long j,k;
- float mindel=_float32_unpack(q->min);
- float delta=_float32_unpack(q->delta);
-
- for(j=0;j<v->entries;j++){
- float last=0.f;
- for(k=0;k<v->elements;k++){
- float now=_now(v,j)[k];
- now=fabs(now)*delta+last+mindel;
- if(q->sequencep)last=now;
- _now(v,j)[k]=now;
- }
- }
-}
-
-void vqgen_init(vqgen *v,int elements,int aux,int entries,float mindist,
- float (*metric)(vqgen *,float *, float *),
- float *(*weight)(vqgen *,float *),int centroid){
- memset(v,0,sizeof(vqgen));
-
- v->centroid=centroid;
- v->elements=elements;
- v->aux=aux;
- v->mindist=mindist;
- v->allocated=32768;
- v->pointlist=_ogg_malloc(v->allocated*(v->elements+v->aux)*sizeof(float));
-
- v->entries=entries;
- v->entrylist=_ogg_malloc(v->entries*v->elements*sizeof(float));
- v->assigned=_ogg_malloc(v->entries*sizeof(long));
- v->bias=_ogg_calloc(v->entries,sizeof(float));
- v->max=_ogg_calloc(v->entries,sizeof(float));
- if(metric)
- v->metric_func=metric;
- else
- v->metric_func=_dist;
- if(weight)
- v->weight_func=weight;
- else
- v->weight_func=_weight_null;
-
- v->asciipoints=tmpfile();
-
-}
-
-void vqgen_addpoint(vqgen *v, float *p,float *a){
- int k;
- for(k=0;k<v->elements;k++)
- fprintf(v->asciipoints,"%.12g\n",p[k]);
- for(k=0;k<v->aux;k++)
- fprintf(v->asciipoints,"%.12g\n",a[k]);
-
- if(v->points>=v->allocated){
- v->allocated*=2;
- v->pointlist=_ogg_realloc(v->pointlist,v->allocated*(v->elements+v->aux)*
- sizeof(float));
- }
-
- memcpy(_point(v,v->points),p,sizeof(float)*v->elements);
- if(v->aux)memcpy(_point(v,v->points)+v->elements,a,sizeof(float)*v->aux);
-
- /* quantize to the density mesh if it's selected */
- if(v->mindist>0.f){
- /* quantize to the mesh */
- for(k=0;k<v->elements+v->aux;k++)
- _point(v,v->points)[k]=
- rint(_point(v,v->points)[k]/v->mindist)*v->mindist;
- }
- v->points++;
- if(!(v->points&0xff))spinnit("loading... ",v->points);
-}
-
-/* yes, not threadsafe. These utils aren't */
-static int sortit=0;
-static int sortsize=0;
-static int meshcomp(const void *a,const void *b){
- if(((sortit++)&0xfff)==0)spinnit("sorting mesh...",sortit);
- return(memcmp(a,b,sortsize));
-}
-
-void vqgen_sortmesh(vqgen *v){
- sortit=0;
- if(v->mindist>0.f){
- long i,march=1;
-
- /* sort to make uniqueness detection trivial */
- sortsize=(v->elements+v->aux)*sizeof(float);
- qsort(v->pointlist,v->points,sortsize,meshcomp);
-
- /* now march through and eliminate dupes */
- for(i=1;i<v->points;i++){
- if(memcmp(_point(v,i),_point(v,i-1),sortsize)){
- /* a new, unique entry. march it down */
- if(i>march)memcpy(_point(v,march),_point(v,i),sortsize);
- march++;
- }
- spinnit("eliminating density... ",v->points-i);
- }
-
- /* we're done */
- fprintf(stderr,"\r%ld training points remining out of %ld"
- " after density mesh (%ld%%)\n",march,v->points,march*100/v->points);
- v->points=march;
-
- }
- v->sorted=1;
-}
-
-float vqgen_iterate(vqgen *v,int biasp){
- long i,j,k;
-
- float fdesired;
- long desired;
- long desired2;
-
- float asserror=0.f;
- float meterror=0.f;
- float *new;
- float *new2;
- long *nearcount;
- float *nearbias;
- #ifdef NOISY
- char buff[80];
- FILE *assig;
- FILE *bias;
- FILE *cells;
- sprintf(buff,"cells%d.m",v->it);
- cells=fopen(buff,"w");
- sprintf(buff,"assig%d.m",v->it);
- assig=fopen(buff,"w");
- sprintf(buff,"bias%d.m",v->it);
- bias=fopen(buff,"w");
- #endif
-
-
- if(v->entries<2){
- fprintf(stderr,"generation requires at least two entries\n");
- exit(1);
- }
-
- if(!v->sorted)vqgen_sortmesh(v);
- if(!v->seeded)_vqgen_seed(v);
-
- fdesired=(float)v->points/v->entries;
- desired=fdesired;
- desired2=desired*2;
- new=_ogg_malloc(sizeof(float)*v->entries*v->elements);
- new2=_ogg_malloc(sizeof(float)*v->entries*v->elements);
- nearcount=_ogg_malloc(v->entries*sizeof(long));
- nearbias=_ogg_malloc(v->entries*desired2*sizeof(float));
-
- /* fill in nearest points for entry biasing */
- /*memset(v->bias,0,sizeof(float)*v->entries);*/
- memset(nearcount,0,sizeof(long)*v->entries);
- memset(v->assigned,0,sizeof(long)*v->entries);
- if(biasp){
- for(i=0;i<v->points;i++){
- float *ppt=v->weight_func(v,_point(v,i));
- float firstmetric=v->metric_func(v,_now(v,0),ppt)+v->bias[0];
- float secondmetric=v->metric_func(v,_now(v,1),ppt)+v->bias[1];
- long firstentry=0;
- long secondentry=1;
-
- if(!(i&0xff))spinnit("biasing... ",v->points+v->points+v->entries-i);
-
- if(firstmetric>secondmetric){
- float temp=firstmetric;
- firstmetric=secondmetric;
- secondmetric=temp;
- firstentry=1;
- secondentry=0;
- }
-
- for(j=2;j<v->entries;j++){
- float thismetric=v->metric_func(v,_now(v,j),ppt)+v->bias[j];
- if(thismetric<secondmetric){
- if(thismetric<firstmetric){
- secondmetric=firstmetric;
- secondentry=firstentry;
- firstmetric=thismetric;
- firstentry=j;
- }else{
- secondmetric=thismetric;
- secondentry=j;
- }
- }
- }
-
- j=firstentry;
- for(j=0;j<v->entries;j++){
-
- float thismetric,localmetric;
- float *nearbiasptr=nearbias+desired2*j;
- long k=nearcount[j];
-
- localmetric=v->metric_func(v,_now(v,j),ppt);
- /* 'thismetric' is to be the bias value necessary in the current
- arrangement for entry j to capture point i */
- if(firstentry==j){
- /* use the secondary entry as the threshhold */
- thismetric=secondmetric-localmetric;
- }else{
- /* use the primary entry as the threshhold */
- thismetric=firstmetric-localmetric;
- }
-
- /* support the idea of 'minimum distance'... if we want the
- cells in a codebook to be roughly some minimum size (as with
- the low resolution residue books) */
-
- /* a cute two-stage delayed sorting hack */
- if(k<desired){
- nearbiasptr[k]=thismetric;
- k++;
- if(k==desired){
- spinnit("biasing... ",v->points+v->points+v->entries-i);
- qsort(nearbiasptr,desired,sizeof(float),directdsort);
- }
-
- }else if(thismetric>nearbiasptr[desired-1]){
- nearbiasptr[k]=thismetric;
- k++;
- if(k==desired2){
- spinnit("biasing... ",v->points+v->points+v->entries-i);
- qsort(nearbiasptr,desired2,sizeof(float),directdsort);
- k=desired;
- }
- }
- nearcount[j]=k;
- }
- }
-
- /* inflate/deflate */
-
- for(i=0;i<v->entries;i++){
- float *nearbiasptr=nearbias+desired2*i;
-
- spinnit("biasing... ",v->points+v->entries-i);
-
- /* due to the delayed sorting, we likely need to finish it off....*/
- if(nearcount[i]>desired)
- qsort(nearbiasptr,nearcount[i],sizeof(float),directdsort);
-
- v->bias[i]=nearbiasptr[desired-1];
-
- }
- }else{
- memset(v->bias,0,v->entries*sizeof(float));
- }
-
- /* Now assign with new bias and find new midpoints */
- for(i=0;i<v->points;i++){
- float *ppt=v->weight_func(v,_point(v,i));
- float firstmetric=v->metric_func(v,_now(v,0),ppt)+v->bias[0];
- long firstentry=0;
-
- if(!(i&0xff))spinnit("centering... ",v->points-i);
-
- for(j=0;j<v->entries;j++){
- float thismetric=v->metric_func(v,_now(v,j),ppt)+v->bias[j];
- if(thismetric<firstmetric){
- firstmetric=thismetric;
- firstentry=j;
- }
- }
-
- j=firstentry;
-
-#ifdef NOISY
- fprintf(cells,"%g %g\n%g %g\n\n",
- _now(v,j)[0],_now(v,j)[1],
- ppt[0],ppt[1]);
-#endif
-
- firstmetric-=v->bias[j];
- meterror+=firstmetric;
-
- if(v->centroid==0){
- /* set up midpoints for next iter */
- if(v->assigned[j]++){
- for(k=0;k<v->elements;k++)
- vN(new,j)[k]+=ppt[k];
- if(firstmetric>v->max[j])v->max[j]=firstmetric;
- }else{
- for(k=0;k<v->elements;k++)
- vN(new,j)[k]=ppt[k];
- v->max[j]=firstmetric;
- }
- }else{
- /* centroid */
- if(v->assigned[j]++){
- for(k=0;k<v->elements;k++){
- if(vN(new,j)[k]>ppt[k])vN(new,j)[k]=ppt[k];
- if(vN(new2,j)[k]<ppt[k])vN(new2,j)[k]=ppt[k];
- }
- if(firstmetric>v->max[firstentry])v->max[j]=firstmetric;
- }else{
- for(k=0;k<v->elements;k++){
- vN(new,j)[k]=ppt[k];
- vN(new2,j)[k]=ppt[k];
- }
- v->max[firstentry]=firstmetric;
- }
- }
- }
-
- /* assign midpoints */
-
- for(j=0;j<v->entries;j++){
-#ifdef NOISY
- fprintf(assig,"%ld\n",v->assigned[j]);
- fprintf(bias,"%g\n",v->bias[j]);
-#endif
- asserror+=fabs(v->assigned[j]-fdesired);
- if(v->assigned[j]){
- if(v->centroid==0){
- for(k=0;k<v->elements;k++)
- _now(v,j)[k]=vN(new,j)[k]/v->assigned[j];
- }else{
- for(k=0;k<v->elements;k++)
- _now(v,j)[k]=(vN(new,j)[k]+vN(new2,j)[k])/2.f;
- }
- }
- }
-
- asserror/=(v->entries*fdesired);
-
- fprintf(stderr,"Pass #%d... ",v->it);
- fprintf(stderr,": dist %g(%g) metric error=%g \n",
- asserror,fdesired,meterror/v->points);
- v->it++;
-
- free(new);
- free(nearcount);
- free(nearbias);
-#ifdef NOISY
- fclose(assig);
- fclose(bias);
- fclose(cells);
-#endif
- return(asserror);
-}
-
diff --git a/vq/vqgen.h b/vq/vqgen.h
deleted file mode 100644
index 256d5a54..00000000
--- a/vq/vqgen.h
+++ /dev/null
@@ -1,85 +0,0 @@
-/********************************************************************
- * *
- * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *
- * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
- * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
- * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
- * *
- * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2001 *
- * by the XIPHOPHORUS Company http://www.xiph.org/ *
- * *
- ********************************************************************
-
- function: build a VQ codebook
- last mod: $Id: vqgen.h,v 1.19 2001/12/20 01:00:40 segher Exp $
-
- ********************************************************************/
-
-#ifndef _VQGEN_H_
-#define _VQGEN_H_
-
-typedef struct vqgen{
- int seeded;
- int sorted;
-
- int it;
- int elements;
-
- int aux;
- float mindist;
- int centroid;
-
- /* point cache */
- float *pointlist;
- long points;
- long allocated;
-
- /* entries */
- float *entrylist;
- long *assigned;
- float *bias;
- long entries;
- float *max;
-
- float (*metric_func) (struct vqgen *v,float *entry,float *point);
- float *(*weight_func) (struct vqgen *v,float *point);
-
- FILE *asciipoints;
-} vqgen;
-
-typedef struct {
- long min; /* packed 24 bit float */
- long delta; /* packed 24 bit float */
- int quant; /* 0 < quant <= 16 */
- int sequencep; /* bitflag */
-} quant_meta;
-
-static inline float *_point(vqgen *v,long ptr){
- return v->pointlist+((v->elements+v->aux)*ptr);
-}
-
-static inline float *_aux(vqgen *v,long ptr){
- return _point(v,ptr)+v->aux;
-}
-
-static inline float *_now(vqgen *v,long ptr){
- return v->entrylist+(v->elements*ptr);
-}
-
-extern void vqgen_init(vqgen *v,
- int elements,int aux,int entries,float mindist,
- float (*metric)(vqgen *,float *, float *),
- float *(*weight)(vqgen *,float *),int centroid);
-extern void vqgen_addpoint(vqgen *v, float *p,float *aux);
-
-extern float vqgen_iterate(vqgen *v,int biasp);
-extern void vqgen_unquantize(vqgen *v,quant_meta *q);
-extern void vqgen_quantize(vqgen *v,quant_meta *q);
-extern void vqgen_cellmetric(vqgen *v);
-
-#endif
-
-
-
-
-
diff --git a/vq/vqsplit.c b/vq/vqsplit.c
deleted file mode 100644
index b79e807d..00000000
--- a/vq/vqsplit.c
+++ /dev/null
@@ -1,612 +0,0 @@
-/********************************************************************
- * *
- * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *
- * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
- * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
- * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
- * *
- * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2001 *
- * by the XIPHOPHORUS Company http://www.xiph.org/ *
- * *
- ********************************************************************
-
- function: build a VQ codebook and the encoding decision 'tree'
- last mod: $Id: vqsplit.c,v 1.26 2001/12/20 01:00:40 segher Exp $
-
- ********************************************************************/
-
-/* This code is *not* part of libvorbis. It is used to generate
- trained codebooks offline and then spit the results into a
- pregenerated codebook that is compiled into libvorbis. It is an
- expensive (but good) algorithm. Run it on big iron. */
-
-/* There are so many optimizations to explore in *both* stages that
- considering the undertaking is almost withering. For now, we brute
- force it all */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <math.h>
-#include <string.h>
-#include <sys/time.h>
-
-#include "vqgen.h"
-#include "vqsplit.h"
-#include "bookutil.h"
-
-/* Codebook generation happens in two steps:
-
- 1) Train the codebook with data collected from the encoder: We use
- one of a few error metrics (which represent the distance between a
- given data point and a candidate point in the training set) to
- divide the training set up into cells representing roughly equal
- probability of occurring.
-
- 2) Generate the codebook and auxiliary data from the trained data set
-*/
-
-/* Building a codebook from trained set **********************************
-
- The codebook in raw form is technically finished once it's trained.
- However, we want to finalize the representative codebook values for
- each entry and generate auxiliary information to optimize encoding.
- We generate the auxiliary coding tree using collected data,
- probably the same data as in the original training */
-
-/* At each recursion, the data set is split in half. Cells with data
- points on side A go into set A, same with set B. The sets may
- overlap. If the cell overlaps the deviding line only very slightly
- (provided parameter), we may choose to ignore the overlap in order
- to pare the tree down */
-
-long *isortvals;
-int iascsort(const void *a,const void *b){
- long av=isortvals[*((long *)a)];
- long bv=isortvals[*((long *)b)];
- return(av-bv);
-}
-
-static float _Ndist(int el,float *a, float *b){
- int i;
- float acc=0.f;
- for(i=0;i<el;i++){
- float val=(a[i]-b[i]);
- acc+=val*val;
- }
- return sqrt(acc);
-}
-
-#define _Npoint(i) (pointlist+dim*(i))
-#define _Nnow(i) (entrylist+dim*(i))
-
-
-/* goes through the split, but just counts it and returns a metric*/
-int vqsp_count(float *entrylist,float *pointlist,int dim,
- long *membership,long *reventry,
- long *entryindex,long entries,
- long *pointindex,long points,int splitp,
- long *entryA,long *entryB,
- long besti,long bestj,
- long *entriesA,long *entriesB,long *entriesC){
- long i,j;
- long A=0,B=0,C=0;
- long pointsA=0;
- long pointsB=0;
- long *temppointsA=NULL;
- long *temppointsB=NULL;
-
- if(splitp){
- temppointsA=_ogg_malloc(points*sizeof(long));
- temppointsB=_ogg_malloc(points*sizeof(long));
- }
-
- memset(entryA,0,sizeof(long)*entries);
- memset(entryB,0,sizeof(long)*entries);
-
- /* Do the points belonging to this cell occur on sideA, sideB or
- both? */
-
- for(i=0;i<points;i++){
- float *ppt=_Npoint(pointindex[i]);
- long firstentry=membership[pointindex[i]];
-
- if(firstentry==besti){
- entryA[reventry[firstentry]]=1;
- if(splitp)temppointsA[pointsA++]=pointindex[i];
- continue;
- }
- if(firstentry==bestj){
- entryB[reventry[firstentry]]=1;
- if(splitp)temppointsB[pointsB++]=pointindex[i];
- continue;
- }
- {
- float distA=_Ndist(dim,ppt,_Nnow(besti));
- float distB=_Ndist(dim,ppt,_Nnow(bestj));
- if(distA<distB){
- entryA[reventry[firstentry]]=1;
- if(splitp)temppointsA[pointsA++]=pointindex[i];
- }else{
- entryB[reventry[firstentry]]=1;
- if(splitp)temppointsB[pointsB++]=pointindex[i];
- }
- }
- }
-
- /* The entry splitting isn't total, so that storage has to be
- allocated for recursion. Reuse the entryA/entryB vectors */
- /* keep the entries in ascending order (relative to the original
- list); we rely on that stability when ordering p/q choice */
- for(j=0;j<entries;j++){
- if(entryA[j] && entryB[j])C++;
- if(entryA[j])entryA[A++]=entryindex[j];
- if(entryB[j])entryB[B++]=entryindex[j];
- }
- *entriesA=A;
- *entriesB=B;
- *entriesC=C;
- if(splitp){
- memcpy(pointindex,temppointsA,sizeof(long)*pointsA);
- memcpy(pointindex+pointsA,temppointsB,sizeof(long)*pointsB);
- free(temppointsA);
- free(temppointsB);
- }
- return(pointsA);
-}
-
-int lp_split(float *pointlist,long totalpoints,
- codebook *b,
- long *entryindex,long entries,
- long *pointindex,long points,
- long *membership,long *reventry,
- long depth, long *pointsofar){
-
- encode_aux_nearestmatch *t=b->c->nearest_tree;
-
- /* The encoder, regardless of book, will be using a straight
- euclidian distance-to-point metric to determine closest point.
- Thus we split the cells using the same (we've already trained the
- codebook set spacing and distribution using special metrics and
- even a midpoint division won't disturb the basic properties) */
-
- int dim=b->dim;
- float *entrylist=b->valuelist;
- long ret;
- long *entryA=_ogg_calloc(entries,sizeof(long));
- long *entryB=_ogg_calloc(entries,sizeof(long));
- long entriesA=0;
- long entriesB=0;
- long entriesC=0;
- long pointsA=0;
- long i,j,k;
-
- long besti=-1;
- long bestj=-1;
-
- char spinbuf[80];
- sprintf(spinbuf,"splitting [%ld left]... ",totalpoints-*pointsofar);
-
- /* one reverse index needed */
- for(i=0;i<b->entries;i++)reventry[i]=-1;
- for(i=0;i<entries;i++)reventry[entryindex[i]]=i;
-
- /* We need to find the dividing hyperplane. find the median of each
- axis as the centerpoint and the normal facing farthest point */
-
- /* more than one way to do this part. For small sets, we can brute
- force it. */
-
- if(entries<8 || (float)points*entries*entries<16.f*1024*1024){
- /* try every pair possibility */
- float best=0;
- float this;
- for(i=0;i<entries-1;i++){
- for(j=i+1;j<entries;j++){
- spinnit(spinbuf,entries-i);
- vqsp_count(b->valuelist,pointlist,dim,
- membership,reventry,
- entryindex,entries,
- pointindex,points,0,
- entryA,entryB,
- entryindex[i],entryindex[j],
- &entriesA,&entriesB,&entriesC);
- this=(entriesA-entriesC)*(entriesB-entriesC);
-
- /* when choosing best, we also want some form of stability to
- make sure more branches are pared later; secondary
- weighting isn;t needed as the entry lists are in ascending
- order, and we always try p/q in the same sequence */
-
- if( (besti==-1) ||
- (this>best) ){
-
- best=this;
- besti=entryindex[i];
- bestj=entryindex[j];
-
- }
- }
- }
- }else{
- float *p=alloca(dim*sizeof(float));
- float *q=alloca(dim*sizeof(float));
- float best=0.f;
-
- /* try COG/normal and furthest pairs */
- /* meanpoint */
- /* eventually, we want to select the closest entry and figure n/c
- from p/q (because storing n/c is too large */
- for(k=0;k<dim;k++){
- spinnit(spinbuf,entries);
-
- p[k]=0.f;
- for(j=0;j<entries;j++)
- p[k]+=b->valuelist[entryindex[j]*dim+k];
- p[k]/=entries;
-
- }
-
- /* we go through the entries one by one, looking for the entry on
- the other side closest to the point of reflection through the
- center */
-
- for(i=0;i<entries;i++){
- float *ppi=_Nnow(entryindex[i]);
- float ref_best=0.f;
- float ref_j=-1;
- float this;
- spinnit(spinbuf,entries-i);
-
- for(k=0;k<dim;k++)
- q[k]=2*p[k]-ppi[k];
-
- for(j=0;j<entries;j++){
- if(j!=i){
- float this=_Ndist(dim,q,_Nnow(entryindex[j]));
- if(ref_j==-1 || this<=ref_best){ /* <=, not <; very important */
- ref_best=this;
- ref_j=entryindex[j];
- }
- }
- }
-
- vqsp_count(b->valuelist,pointlist,dim,
- membership,reventry,
- entryindex,entries,
- pointindex,points,0,
- entryA,entryB,
- entryindex[i],ref_j,
- &entriesA,&entriesB,&entriesC);
- this=(entriesA-entriesC)*(entriesB-entriesC);
-
- /* when choosing best, we also want some form of stability to
- make sure more branches are pared later; secondary
- weighting isn;t needed as the entry lists are in ascending
- order, and we always try p/q in the same sequence */
-
- if( (besti==-1) ||
- (this>best) ){
-
- best=this;
- besti=entryindex[i];
- bestj=ref_j;
-
- }
- }
- if(besti>bestj){
- long temp=besti;
- besti=bestj;
- bestj=temp;
- }
-
- }
-
- /* find cells enclosing points */
- /* count A/B points */
-
- pointsA=vqsp_count(b->valuelist,pointlist,dim,
- membership,reventry,
- entryindex,entries,
- pointindex,points,1,
- entryA,entryB,
- besti,bestj,
- &entriesA,&entriesB,&entriesC);
-
- /* fprintf(stderr,"split: total=%ld depth=%ld set A=%ld:%ld:%ld=B\n",
- entries,depth,entriesA-entriesC,entriesC,entriesB-entriesC);*/
- {
- long thisaux=t->aux++;
- if(t->aux>=t->alloc){
- t->alloc*=2;
- t->ptr0=_ogg_realloc(t->ptr0,sizeof(long)*t->alloc);
- t->ptr1=_ogg_realloc(t->ptr1,sizeof(long)*t->alloc);
- t->p=_ogg_realloc(t->p,sizeof(long)*t->alloc);
- t->q=_ogg_realloc(t->q,sizeof(long)*t->alloc);
- }
-
- t->p[thisaux]=besti;
- t->q[thisaux]=bestj;
-
- if(entriesA==1){
- ret=1;
- t->ptr0[thisaux]=entryA[0];
- *pointsofar+=pointsA;
- }else{
- t->ptr0[thisaux]= -t->aux;
- ret=lp_split(pointlist,totalpoints,b,entryA,entriesA,pointindex,pointsA,
- membership,reventry,depth+1,pointsofar);
- }
- if(entriesB==1){
- ret++;
- t->ptr1[thisaux]=entryB[0];
- *pointsofar+=points-pointsA;
- }else{
- t->ptr1[thisaux]= -t->aux;
- ret+=lp_split(pointlist,totalpoints,b,entryB,entriesB,pointindex+pointsA,
- points-pointsA,membership,reventry,
- depth+1,pointsofar);
- }
- }
- free(entryA);
- free(entryB);
- return(ret);
-}
-
-static int _node_eq(encode_aux_nearestmatch *v, long a, long b){
- long Aptr0=v->ptr0[a];
- long Aptr1=v->ptr1[a];
- long Bptr0=v->ptr0[b];
- long Bptr1=v->ptr1[b];
-
- /* the possibility of choosing the same p and q, but switched, can;t
- happen because we always look for the best p/q in the same search
- order and the search is stable */
-
- if(Aptr0==Bptr0 && Aptr1==Bptr1)
- return(1);
-
- return(0);
-}
-
-void vqsp_book(vqgen *v, codebook *b, long *quantlist){
- long i,j;
- static_codebook *c=(static_codebook *)b->c;
- encode_aux_nearestmatch *t;
-
- memset(b,0,sizeof(codebook));
- memset(c,0,sizeof(static_codebook));
- b->c=c;
- t=c->nearest_tree=_ogg_calloc(1,sizeof(encode_aux_nearestmatch));
- c->maptype=2;
-
- /* make sure there are no duplicate entries and that every
- entry has points */
-
- for(i=0;i<v->entries;){
- /* duplicate? if so, eliminate */
- for(j=0;j<i;j++){
- if(_Ndist(v->elements,_now(v,i),_now(v,j))==0.f){
- fprintf(stderr,"found a duplicate entry! removing...\n");
- v->entries--;
- memcpy(_now(v,i),_now(v,v->entries),sizeof(float)*v->elements);
- memcpy(quantlist+i*v->elements,quantlist+v->entries*v->elements,
- sizeof(long)*v->elements);
- break;
- }
- }
- if(j==i)i++;
- }
-
- {
- v->assigned=_ogg_calloc(v->entries,sizeof(long));
- for(i=0;i<v->points;i++){
- float *ppt=_point(v,i);
- float firstmetric=_Ndist(v->elements,_now(v,0),ppt);
- long firstentry=0;
-
- if(!(i&0xff))spinnit("checking... ",v->points-i);
-
- for(j=0;j<v->entries;j++){
- float thismetric=_Ndist(v->elements,_now(v,j),ppt);
- if(thismetric<firstmetric){
- firstmetric=thismetric;
- firstentry=j;
- }
- }
-
- v->assigned[firstentry]++;
- }
-
- for(j=0;j<v->entries;){
- if(v->assigned[j]==0){
- fprintf(stderr,"found an unused entry! removing...\n");
- v->entries--;
- memcpy(_now(v,j),_now(v,v->entries),sizeof(float)*v->elements);
- v->assigned[j]=v->assigned[v->elements];
- memcpy(quantlist+j*v->elements,quantlist+v->entries*v->elements,
- sizeof(long)*v->elements);
- continue;
- }
- j++;
- }
- }
-
- fprintf(stderr,"Building a book with %ld unique entries...\n",v->entries);
-
- {
- long *entryindex=_ogg_malloc(v->entries*sizeof(long *));
- long *pointindex=_ogg_malloc(v->points*sizeof(long));
- long *membership=_ogg_malloc(v->points*sizeof(long));
- long *reventry=_ogg_malloc(v->entries*sizeof(long));
- long pointssofar=0;
-
- for(i=0;i<v->entries;i++)entryindex[i]=i;
- for(i=0;i<v->points;i++)pointindex[i]=i;
-
- t->alloc=4096;
- t->ptr0=_ogg_malloc(sizeof(long)*t->alloc);
- t->ptr1=_ogg_malloc(sizeof(long)*t->alloc);
- t->p=_ogg_malloc(sizeof(long)*t->alloc);
- t->q=_ogg_malloc(sizeof(long)*t->alloc);
- t->aux=0;
- c->dim=v->elements;
- c->entries=v->entries;
- c->lengthlist=_ogg_calloc(c->entries,sizeof(long));
- b->valuelist=v->entrylist; /* temporary; replaced later */
- b->dim=c->dim;
- b->entries=c->entries;
-
- for(i=0;i<v->points;i++)membership[i]=-1;
- for(i=0;i<v->points;i++){
- float *ppt=_point(v,i);
- long firstentry=0;
- float firstmetric=_Ndist(v->elements,_now(v,0),ppt);
-
- if(!(i&0xff))spinnit("assigning... ",v->points-i);
-
- for(j=1;j<v->entries;j++){
- if(v->assigned[j]!=-1){
- float thismetric=_Ndist(v->elements,_now(v,j),ppt);
- if(thismetric<=firstmetric){
- firstmetric=thismetric;
- firstentry=j;
- }
- }
- }
-
- membership[i]=firstentry;
- }
-
- fprintf(stderr,"Leaves added: %d \n",
- lp_split(v->pointlist,v->points,
- b,entryindex,v->entries,
- pointindex,v->points,
- membership,reventry,
- 0,&pointssofar));
-
- free(pointindex);
- free(membership);
- free(reventry);
-
- fprintf(stderr,"Paring/rerouting redundant branches... ");
-
- /* The tree is likely big and redundant. Pare and reroute branches */
- {
- int changedflag=1;
-
- while(changedflag){
- changedflag=0;
-
- /* span the tree node by node; list unique decision nodes and
- short circuit redundant branches */
-
- for(i=0;i<t->aux;){
- int k;
-
- /* check list of unique decisions */
- for(j=0;j<i;j++)
- if(_node_eq(t,i,j))break;
-
- if(j<i){
- /* a redundant entry; find all higher nodes referencing it and
- short circuit them to the previously noted unique entry */
- changedflag=1;
- for(k=0;k<t->aux;k++){
- if(t->ptr0[k]==-i)t->ptr0[k]=-j;
- if(t->ptr1[k]==-i)t->ptr1[k]=-j;
- }
-
- /* Now, we need to fill in the hole from this redundant
- entry in the listing. Insert the last entry in the list.
- Fix the forward pointers to that last entry */
- t->aux--;
- t->ptr0[i]=t->ptr0[t->aux];
- t->ptr1[i]=t->ptr1[t->aux];
- t->p[i]=t->p[t->aux];
- t->q[i]=t->q[t->aux];
- for(k=0;k<t->aux;k++){
- if(t->ptr0[k]==-t->aux)t->ptr0[k]=-i;
- if(t->ptr1[k]==-t->aux)t->ptr1[k]=-i;
- }
- /* hole plugged */
-
- }else
- i++;
- }
-
- fprintf(stderr,"\rParing/rerouting redundant branches... "
- "%ld remaining ",t->aux);
- }
- fprintf(stderr,"\n");
- }
- }
-
- /* run all training points through the decision tree to get a final
- probability count */
- {
- long *probability=_ogg_malloc(c->entries*sizeof(long));
- for(i=0;i<c->entries;i++)probability[i]=1; /* trivial guard */
- b->dim=c->dim;
-
- /* sigh. A necessary hack */
- for(i=0;i<t->aux;i++)t->p[i]*=c->dim;
- for(i=0;i<t->aux;i++)t->q[i]*=c->dim;
-
- for(i=0;i<v->points;i++){
- /* we use the linear matcher regardless becuase the trainer
- doesn't convert log to linear */
- int ret=_best(b,v->pointlist+i*v->elements,1);
- probability[ret]++;
- if(!(i&0xff))spinnit("counting hits... ",v->points-i);
- }
- for(i=0;i<t->aux;i++)t->p[i]/=c->dim;
- for(i=0;i<t->aux;i++)t->q[i]/=c->dim;
-
- build_tree_from_lengths(c->entries,probability,c->lengthlist);
-
- free(probability);
- }
-
- /* Sort the entries by codeword length, short to long (eases
- assignment and packing to do it now) */
- {
- long *wordlen=c->lengthlist;
- long *index=_ogg_malloc(c->entries*sizeof(long));
- long *revindex=_ogg_malloc(c->entries*sizeof(long));
- int k;
- for(i=0;i<c->entries;i++)index[i]=i;
- isortvals=c->lengthlist;
- qsort(index,c->entries,sizeof(long),iascsort);
-
- /* rearrange storage; ptr0/1 first as it needs a reverse index */
- /* n and c stay unchanged */
- for(i=0;i<c->entries;i++)revindex[index[i]]=i;
- for(i=0;i<t->aux;i++){
- if(!(i&0x3f))spinnit("sorting... ",t->aux-i);
-
- if(t->ptr0[i]>=0)t->ptr0[i]=revindex[t->ptr0[i]];
- if(t->ptr1[i]>=0)t->ptr1[i]=revindex[t->ptr1[i]];
- t->p[i]=revindex[t->p[i]];
- t->q[i]=revindex[t->q[i]];
- }
- free(revindex);
-
- /* map lengthlist and vallist with index */
- c->lengthlist=_ogg_calloc(c->entries,sizeof(long));
- b->valuelist=_ogg_malloc(sizeof(float)*c->entries*c->dim);
- c->quantlist=_ogg_malloc(sizeof(long)*c->entries*c->dim);
- for(i=0;i<c->entries;i++){
- long e=index[i];
- for(k=0;k<c->dim;k++){
- b->valuelist[i*c->dim+k]=v->entrylist[e*c->dim+k];
- c->quantlist[i*c->dim+k]=quantlist[e*c->dim+k];
- }
- c->lengthlist[i]=wordlen[e];
- }
-
- free(wordlen);
- }
-
- fprintf(stderr,"Done. \n\n");
-}
-
diff --git a/vq/vqsplit.h b/vq/vqsplit.h
deleted file mode 100644
index cdaa3279..00000000
--- a/vq/vqsplit.h
+++ /dev/null
@@ -1,37 +0,0 @@
-/********************************************************************
- * *
- * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *
- * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
- * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
- * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
- * *
- * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2001 *
- * by the XIPHOPHORUS Company http://www.xiph.org/ *
- * *
- ********************************************************************
-
- function: build a VQ codebook decision tree
- last mod: $Id: vqsplit.h,v 1.8 2001/12/20 01:00:40 segher Exp $
-
- ********************************************************************/
-
-#ifndef _VQSPL_H_
-#define _VQSPL_H_
-
-#include "codebook.h"
-
-extern void vqsp_book(vqgen *v,codebook *b,long *quantlist);
-extern int vqenc_entry(codebook *b,float *val);
-extern int lp_split(float *pointlist,long totalpoints,
- codebook *b,
- long *entryindex,long entries,
- long *pointindex,long points,
- long *membership,long *reventry,
- long depth, long *pointsofar);
-
-#endif
-
-
-
-
-