Skip to content

Commit 0ca6759

Browse files
committed
Reduce the number of required FP multiplications in hs_pitch_refinement() and mbest_search().
1 parent cc94952 commit 0ca6759

File tree

4 files changed

+45
-8
lines changed

4 files changed

+45
-8
lines changed

src/mbest.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,42 @@ void mbest_search(
140140
}
141141
}
142142

143+
/*---------------------------------------------------------------------------*\
144+
145+
mbest_search_equalweight
146+
147+
Searches vec[] to a codebbook of vectors, and maintains a list of the mbest
148+
closest matches. Similar to mbest_search() but with w[] = 1.
149+
150+
\*---------------------------------------------------------------------------*/
151+
152+
void mbest_search_equalweight(
153+
const float *cb, /* VQ codebook to search */
154+
float vec[], /* target vector */
155+
int k, /* dimension of vector */
156+
int m, /* number on entries in codebook */
157+
struct MBEST *mbest, /* list of closest matches */
158+
int index[] /* indexes that lead us here */
159+
)
160+
{
161+
float e;
162+
163+
for(int j = 0; j < m; j++) {
164+
int i;
165+
166+
e = 0.0;
167+
for(int i = 0; i < k; i++) {
168+
float diff = (*cb++) - vec[i];
169+
float diff2 = diff * diff;
170+
e += diff2;
171+
}
172+
173+
index[0] = j;
174+
if (e < mbest->list[mbest->entries - 1].error)
175+
mbest_insert(mbest, index, e);
176+
}
177+
}
178+
143179

144180
/*---------------------------------------------------------------------------*\
145181

src/mbest.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ struct MBEST *mbest_create(int entries);
4646
void mbest_destroy(struct MBEST *mbest);
4747
void mbest_insert(struct MBEST *mbest, int index[], float error);
4848
void mbest_search(const float *cb, float vec[], float w[], int k, int m, struct MBEST *mbest, int index[]);
49+
void mbest_search_equalweight(const float *cb, float vec[], int k, int m, struct MBEST *mbest, int index[]);
4950
void mbest_search450(const float *cb, float vec[], float w[], int k,int shorterK, int m, struct MBEST *mbest, int index[]);
5051

5152
void mbest_print(char title[], struct MBEST *mbest);

src/newamp1.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -166,18 +166,14 @@ float rate_K_mbest_encode(int *indexes, float *x, float *xq, int ndim, int mbest
166166
const float *codebook2 = newamp1vq_cb[1].cb;
167167
struct MBEST *mbest_stage1, *mbest_stage2;
168168
float target[ndim];
169-
float w[ndim];
170169
int index[MBEST_STAGES];
171170
float mse, tmp;
172171

173172
/* codebook is compiled for a fixed K */
174173

175174
assert(ndim == newamp1vq_cb[0].k);
176175

177-
/* equal weights, could be argued mel freq axis gives freq dep weighting */
178-
179-
for(i=0; i<ndim; i++)
180-
w[i] = 1.0;
176+
/* note: using equal weights, could be argued mel freq axis gives freq dep weighting */
181177

182178
mbest_stage1 = mbest_create(mbest_entries);
183179
mbest_stage2 = mbest_create(mbest_entries);
@@ -186,15 +182,15 @@ float rate_K_mbest_encode(int *indexes, float *x, float *xq, int ndim, int mbest
186182

187183
/* Stage 1 */
188184

189-
mbest_search(codebook1, x, w, ndim, newamp1vq_cb[0].m, mbest_stage1, index);
185+
mbest_search_equalweight(codebook1, x, ndim, newamp1vq_cb[0].m, mbest_stage1, index);
190186

191187
/* Stage 2 */
192188

193189
for (j=0; j<mbest_entries; j++) {
194190
index[1] = n1 = mbest_stage1->list[j].index[0];
195191
for(i=0; i<ndim; i++)
196192
target[i] = x[i] - codebook1[ndim*n1+i];
197-
mbest_search(codebook2, target, w, ndim, newamp1vq_cb[1].m, mbest_stage2, index);
193+
mbest_search_equalweight(codebook2, target, ndim, newamp1vq_cb[1].m, mbest_stage2, index);
198194
}
199195

200196
n1 = mbest_stage2->list[0].index[1];

src/sine.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,11 +372,15 @@ void hs_pitch_refinement(MODEL *model, COMP Sw[], float pmin, float pmax, float
372372
for(p=pmin; p<=pmax; p+=pstep) {
373373
E = 0.0;
374374
Wo = TWO_PI/p;
375+
376+
float bFloat = Wo * one_on_r;
377+
float currentBFloat = bFloat;
375378

376379
/* Sum harmonic magnitudes */
377380
for(m=1; m<=model->L; m++) {
378-
b = (int)(m*Wo*one_on_r + 0.5);
381+
b = (int)(currentBFloat + 0.5);
379382
E += Sw[b].real*Sw[b].real + Sw[b].imag*Sw[b].imag;
383+
currentBFloat += bFloat;
380384
}
381385
/* Compare to see if this is a maximum */
382386

0 commit comments

Comments
 (0)