From: drowe67 Date: Thu, 1 Mar 2012 19:18:11 +0000 (+0000) Subject: JVM's joint pitch & energy quantisation X-Git-Url: http://git.whiteaudio.com/gitweb/?a=commitdiff_plain;h=96cdeac01477305fdce71d69d11965ec263fa18d;p=freetel-svn-tracking.git JVM's joint pitch & energy quantisation git-svn-id: https://svn.code.sf.net/p/freetel/code@335 01035d8c-6547-0410-b346-abe4f91aad63 --- diff --git a/codec2-dev/unittest/ge_train.c b/codec2-dev/unittest/ge_train.c new file mode 100644 index 00000000..57c4fa3b --- /dev/null +++ b/codec2-dev/unittest/ge_train.c @@ -0,0 +1,299 @@ +/* + ge_train.c + Jean Marc Valin Feb 2012 + + Joint pitch and energy VQ training program + + usage: + + cat GE | ./ge_train 2 1000000 8 > quantized + + The first column is the log2 of the pitch compared to the lowest freq, + so log2(wo/pi*4000/50) where wo is the frequency your patch outputs. The + second column is the energy in dB, so 10*log10(1e-4+E) +*/ + +/* + Copyright (C) 2012 Jean-Marc Valin + + 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, 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 + +#define MIN(a,b) ((a)<(b)?(a):(b)) +//#define COEF 0.0 + +static float COEF[2] = {0.8, 0.9}; +//static float COEF[2] = {0.0, 0.}; + +#define MAX_ENTRIES 16384 + +void compute_weights2(const float *x, const float *xp, float *w, int ndim) +{ + w[0] = 30; + w[1] = 1; + if (x[1]<0) + { + w[0] *= .6; + w[1] *= .3; + } + if (x[1]<-10) + { + w[0] *= .3; + w[1] *= .3; + } + /* Higher weight if pitch is stable */ + if (fabs(x[0]-xp[0])<.2) + { + w[0] *= 2; + w[1] *= 1.5; + } else if (fabs(x[0]-xp[0])>.5) /* Lower if not stable */ + { + w[0] *= .5; + } + + /* Lower weight for low energy */ + if (x[1] < xp[1]-10) + { + w[1] *= .5; + } + if (x[1] < xp[1]-20) + { + w[1] *= .5; + } + + //w[0] = 30; + //w[1] = 1; + + /* Square the weights because it's applied on the squared error */ + w[0] *= w[0]; + w[1] *= w[1]; + +} + +int find_nearest_weighted(const float *codebook, int nb_entries, float *x, const float *w, int ndim) +{ + int i, j; + float min_dist = 1e15; + int nearest = 0; + + for (i=0;i