Skip to content

Commit e288136

Browse files
authored
Merge pull request drowe67#205 from drowe67/dr-trellis
Trellis decoding of VQ
2 parents 7d51460 + d6f7b34 commit e288136

File tree

3 files changed

+612
-6
lines changed

3 files changed

+612
-6
lines changed

misc/vq_mbest.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <stdlib.h>
1313
#include <stdio.h>
1414
#include <string.h>
15+
#include <limits.h>
1516
#include "mbest.h"
1617

1718
#define MAX_K 20
@@ -35,9 +36,10 @@ int main(int argc, char *argv[]) {
3536
char fnames[256], fn[256], *comma, *p;
3637
FILE *fq;
3738
float lower = -1E32;
38-
int st = -1;
39-
int en = -1;
40-
39+
int st = -1;
40+
int en = -1;
41+
int num = INT_MAX;
42+
4143
int o = 0; int opt_idx = 0;
4244
while (o != -1) {
4345
static struct option long_opts[] = {
@@ -48,10 +50,11 @@ int main(int argc, char *argv[]) {
4850
{"verbose", required_argument, 0, 'v'},
4951
{"st", required_argument, 0, 't'},
5052
{"en", required_argument, 0, 'e'},
53+
{"num", required_argument, 0, 'n'},
5154
{0, 0, 0, 0}
5255
};
5356

54-
o = getopt_long(argc,argv,"hk:q:m:vt:e:",long_opts,&opt_idx);
57+
o = getopt_long(argc,argv,"hk:q:m:vt:e:n:",long_opts,&opt_idx);
5558
switch (o) {
5659
case 'k':
5760
k = atoi(optarg);
@@ -96,6 +99,9 @@ int main(int argc, char *argv[]) {
9699
mbest_survivors = atoi(optarg);
97100
fprintf(stderr, "mbest_survivors = %d\n", mbest_survivors);
98101
break;
102+
case 'n':
103+
num = atoi(optarg);
104+
break;
99105
case 'l':
100106
lower = atof(optarg);
101107
break;
@@ -118,6 +124,8 @@ int main(int argc, char *argv[]) {
118124
fprintf(stderr, "--mbest N number of survivors at each stage, set to 0 for standard VQ search\n");
119125
fprintf(stderr, "--st Kst start vector element for error calculation (default 0)\n");
120126
fprintf(stderr, "--en Ken end vector element for error calculation (default K-1)\n");
127+
fprintf(stderr, "--num numToProcess number of vectors to quantise (default to EOF)\n");
128+
fprintf(stderr, "-v Verbose\n");
121129
exit(1);
122130
}
123131
}
@@ -132,7 +140,7 @@ int main(int argc, char *argv[]) {
132140
int indexes[num_stages], nvecs = 0;
133141
float target[k], quantised[k];
134142
float sqe = 0.0;
135-
while(fread(&target, sizeof(float), k, stdin)) {
143+
while(fread(&target, sizeof(float), k, stdin) && (nvecs < num)) {
136144
int dont_count = 0;
137145
/* optional clamping to lower limit or mean */
138146
float mean = 0.0;
@@ -154,7 +162,7 @@ int main(int argc, char *argv[]) {
154162
fwrite(&quantised, sizeof(float), k, stdout);
155163
nvecs++;
156164
}
157-
fprintf(stderr, "%4.2f\n", sqe/(nvecs*k));
165+
fprintf(stderr, "%4.2f\n", sqe/(nvecs*(en-st+1)));
158166
return 0;
159167
}
160168

0 commit comments

Comments
 (0)