vpredictor.c
2.81 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include "vadpcm.h"
int
readcodebook(FILE *fhandle, int ****table, int *order, int *npredictors)
{
int **table_entry;
int i, j, k;
fscanf(fhandle, "%d",order);
fscanf(fhandle, "%d",npredictors);
*table = (int ***) malloc(*npredictors*sizeof(int **));
for (i=0; i < *npredictors; i++){
(*table)[i] = (int **) malloc(VECTORSIZE*sizeof(int *));
for (j=0; j<VECTORSIZE; j++)
(*table)[i][j] = (int *) malloc((VECTORSIZE + *order)*sizeof(int));
}
for (i=0; i < *npredictors; i++){
table_entry = (*table)[i];
for (j=0; j < *order; j++)
for (k=0; k<VECTORSIZE; k++)
fscanf(fhandle,"%d",&table_entry[k][j]);
/* Now copy the right stuff to the rest of the matrix */
for (k=1; k<VECTORSIZE; k++)
table_entry[k][*order] = table_entry[k-1][*order-1];
table_entry[0][*order] = VSCALING;
for (k=1; k<VECTORSIZE; k++){
for (j=0; j<k; j++)
table_entry[j][k + *order] = 0.0;
for (; j<VECTORSIZE; j++)
table_entry[j][k + *order] = table_entry[j-k][*order];
}
}
return 0;
}
int
readaifccodebook(FILE *fhandle, int ****table, short *order, short *npredictors)
{
int **table_entry;
int i, j, k;
short ts;
fread(order, sizeof(short), 1, fhandle);
fread(npredictors, sizeof(short), 1, fhandle);
*order = htons(*order);
*npredictors = htons(*npredictors);
*table = (int ***) malloc(*npredictors*sizeof(int **));
for (i=0; i < *npredictors; i++){
(*table)[i] = (int **) malloc(VECTORSIZE*sizeof(int *));
for (j=0; j<VECTORSIZE; j++)
(*table)[i][j] = (int *) malloc((VECTORSIZE + *order)*sizeof(int));
}
for (i=0; i < *npredictors; i++){
table_entry = (*table)[i];
for (j=0; j < *order; j++) {
for (k=0; k<VECTORSIZE; k++){
fread(&ts, sizeof(short), 1, fhandle);
table_entry[k][j] = (short) htons(ts);
}
}
/* Now copy the right stuff to the rest of the matrix */
for (k=1; k<VECTORSIZE; k++)
table_entry[k][*order] = table_entry[k-1][*order-1];
table_entry[0][*order] = VSCALING;
for (k=1; k<VECTORSIZE; k++){
for (j=0; j<k; j++)
table_entry[j][k + *order] = 0.0;
for (; j<VECTORSIZE; j++)
table_entry[j][k + *order] = table_entry[j-k][*order];
}
}
return 0;
}
int
inner_product(int length, int *v1, int *v2)
{
int j = 0;
int dout, fiout, out = 0;
for (; j<length; j++)
out += *v1++ * *v2++;
/* Mimic truncation on the RSP - ie always towards more negative */
dout = (int) out/VSCALING;
fiout = VSCALING * dout;
if ((out-fiout) < 0)
return(dout - 1);
else
return(dout);
}