/*---------------------------------------------------------------------------*\ FILE........: mbest.c AUTHOR......: David Rowe DATE CREATED: Jan 2017 Multistage vector quantiser search algorithm that keeps multiple candidates from each stage. \*---------------------------------------------------------------------------*/ /* Copyright David Rowe 2017 All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License version 2.1, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program; if not, see . */ #include #include #include #include #include #include "mbest.h" struct MBEST *mbest_create(int entries) { int i,j; struct MBEST *mbest; assert(entries > 0); mbest = (struct MBEST *)malloc(sizeof(struct MBEST)); assert(mbest != NULL); mbest->entries = entries; mbest->list = (struct MBEST_LIST *)malloc(entries*sizeof(struct MBEST_LIST)); assert(mbest->list != NULL); for(i=0; ientries; i++) { for(j=0; jlist[i].index[j] = 0; mbest->list[i].error = 1E32; } return mbest; } void mbest_destroy(struct MBEST *mbest) { assert(mbest != NULL); free(mbest->list); free(mbest); } /* apply weighting to VQ for efficient VQ search */ void mbest_precompute_weight(float cb[], float w[], int k, int m) { for (int j=0; jlist; int entries = mbest->entries; found = 0; for(i=0; ientries; i++) { for(j=0; jlist[i].index[j]); fprintf(stderr, " %f\n", (double)mbest->list[i].error); } } /*---------------------------------------------------------------------------*\ mbest_search Searches vec[] to a codebbook of vectors, and maintains a list of the mbest closest matches. \*---------------------------------------------------------------------------*/ void mbest_search( const float *cb, /* VQ codebook to search */ float vec[], /* target vector */ int k, /* dimension of vector */ int m, /* number on entries in codebook */ struct MBEST *mbest, /* list of closest matches */ int index[] /* indexes that lead us here */ ) { int j; /* note weighting can be applied externally by modifiying cb[] and vec: float e = 0.0; for(i=0; ilist[mbest->entries - 1].error) mbest_insert(mbest, index, e); } } /*---------------------------------------------------------------------------*\ mbest_search450 Searches vec[] to a codebbook of vectors, and maintains a list of the mbest closest matches. Only searches the first NewAmp2_K Vectors \*---------------------------------------------------------------------------*/ void mbest_search450(const float *cb, float vec[], float w[], int k,int shorterK, int m, struct MBEST *mbest, int index[]) { float e; int i,j; float diff; for(j=0; j