From f02dfce6e6c34b3d8a7b8a0e784b506178e331fa Mon Sep 17 00:00:00 2001 From: "erdgeist@erdgeist.org" Date: Thu, 4 Jul 2019 23:26:09 +0200 Subject: stripdown of version 0.9 --- mbest.c | 173 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 173 insertions(+) create mode 100644 mbest.c (limited to 'mbest.c') diff --git a/mbest.c b/mbest.c new file mode 100644 index 0000000..6216b77 --- /dev/null +++ b/mbest.c @@ -0,0 +1,173 @@ +/*---------------------------------------------------------------------------*\ + + 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); +} + + +/*---------------------------------------------------------------------------*\ + + mbest_insert + + Insert the results of a vector to codebook entry comparison. The + list is ordered in order of error, so those entries with the + smallest error will be first on the list. + +\*---------------------------------------------------------------------------*/ + +void mbest_insert(struct MBEST *mbest, int index[], float error) { + int i, j, found; + struct MBEST_LIST *list = mbest->list; + int entries = mbest->entries; + + found = 0; + for(i=0; ii; j--) + list[j] = list[j-1]; + for(j=0; jentries; i++) { + for(j=0; jlist[i].index[j]); + fprintf(stderr, " %f\n", mbest->list[i].error); + } +} +#endif + + +/*---------------------------------------------------------------------------*\ + + 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 */ + float w[], /* weighting 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 */ +) +{ + float e; + int i,j; + float diff; + + for(j=0; j