/*---------------------------------------------------------------------------*\ FILE........: tquant.c AUTHOR......: David Rowe DATE CREATED: 22/8/10 Generates quantisation curves for plotting on Octave. \*---------------------------------------------------------------------------*/ /* Copyright (C) 2010 David Rowe 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 #include #include "defines.h" #include "dump.h" #include "quantise.h" int test_Wo_quant(); int test_lsp_quant(); int test_lsp(int lsp_number, int levels, float max_error_hz); int test_energy_quant(int levels, float max_error_dB); int main() { quantise_init(); test_Wo_quant(); test_lsp_quant(); test_energy_quant(E_LEVELS, 0.5*(E_MAX_DB - E_MIN_DB)/E_LEVELS); return 0; } int test_lsp_quant() { test_lsp( 1, 16, 12.5); test_lsp( 2, 16, 12.5); test_lsp( 3, 16, 25); test_lsp( 4, 16, 50); test_lsp( 5, 16, 50); test_lsp( 6, 16, 50); test_lsp( 7, 16, 50); test_lsp( 8, 8, 50); test_lsp( 9, 8, 50); test_lsp(10, 4, 100); return 0; } int test_energy_quant(int levels, float max_error_dB) { FILE *fe; float e,e_dec, error, low_e, high_e; int index, index_in, index_out, i; /* check 1:1 match between input and output levels */ for(i=0; i max_error_dB) { printf("error: %f %f\n", error, max_error_dB); exit(0); } } fclose(fe); return 0; } int test_lsp(int lsp_number, int levels, float max_error_hz) { float lsp[LPC_ORD]; int indexes_in[LPC_ORD]; int indexes_out[LPC_ORD]; int indexes[LPC_ORD]; int i; float lowf, highf, f, error; char s[MAX_STR]; FILE *flsp; float max_error_rads; lsp_number--; max_error_rads = max_error_hz*TWO_PI/FS; for(i=0; i max_error_rads) { printf("%d error: %f %f\n", lsp_number+1, error, max_error_rads); exit(0); } } fclose(flsp); printf("OK\n"); return 0; } int test_Wo_quant() { int c; FILE *f; float Wo,Wo_dec, error, step_size; int index, index_in, index_out; /* output Wo quant curve for plotting */ f = fopen("quant_pitch.txt","wt"); for(Wo=0.9*(TWO_PI/P_MAX); Wo<=1.1*(TWO_PI/P_MIN); Wo += 0.001) { index = encode_Wo(Wo); fprintf(f, "%f %d\n", Wo, index); } fclose(f); /* check for all Wo codes we get 1:1 match between encoder and decoder Wo levels */ for(c=0; c (step_size/2.0)) { printf("error: %f step_size/2: %f\n", error, step_size/2.0); exit(0); } fprintf(f,"%f\n",error); } printf("OK\n"); fclose(f); return 0; }