From 40199be556411221647620d3057b38d68e7dfd1c Mon Sep 17 00:00:00 2001 From: drowe67 Date: Mon, 7 Nov 2011 01:05:24 +0000 Subject: [PATCH] first pass at 1400 bit/s simulation git-svn-id: https://svn.code.sf.net/p/freetel/code@301 01035d8c-6547-0410-b346-abe4f91aad63 --- codec2-dev/src/c2sim.c | 847 +++++++++++++++++--------------- codec2-dev/src/quantise.c | 72 +++ codec2-dev/src/quantise.h | 22 +- codec2-dev/unittest/Makefile.am | 15 +- codec2-dev/unittest/Makefile.in | 61 ++- codec2-dev/unittest/genlsp.c | 25 +- 6 files changed, 598 insertions(+), 444 deletions(-) diff --git a/codec2-dev/src/c2sim.c b/codec2-dev/src/c2sim.c index 90d98434..36155c95 100644 --- a/codec2-dev/src/c2sim.c +++ b/codec2-dev/src/c2sim.c @@ -6,7 +6,7 @@ Codec2 simulation. Combines encoder and decoder and allows switching in and out various algorithms and quantisation - steps. Primary program for algorithm developments. + steps. Used for algorithm development. \*---------------------------------------------------------------------------*/ @@ -45,30 +45,7 @@ #include "postfilter.h" #include "interp.h" -/*---------------------------------------------------------------------------*\ - - switch_present() - - Searches the command line arguments for a "switch". If the switch is - found, returns the command line argument where it ws found, else returns - NULL. - -\*---------------------------------------------------------------------------*/ - -int switch_present(sw,argc,argv) -register char sw[]; /* switch in string form */ -register int argc; /* number of command line arguments */ -register char *argv[]; /* array of command line arguments in string form */ -{ - register int i; /* loop variable */ - - for(i=1; i 20)) { - fprintf(stderr, "Error in lpc order: %d\n", order); - exit(1); - } - } - - dump = switch_present("--dump",argc,argv); + for(i=1; i<=MAX_AMP; i++) { + ex_phase[i] = 0.0; + } + for(i=0; i 20)) { + fprintf(stderr, "Error in lpc order: %d\n", order); + exit(1); + } + } + + dump = switch_present("--dump",argc,argv); #ifdef DUMP - if (dump) - dump_on(argv[dump+1]); + if (dump) + dump_on(argv[dump+1]); #endif - lsp = switch_present("--lsp",argc,argv); - lsp_quantiser = 0; - if (lsp) - assert(order == LPC_ORD); - - lspd = switch_present("--lspd",argc,argv); - if (lspd) - assert(order == LPC_ORD); - - lspvq = switch_present("--lspvq",argc,argv); - if (lspvq) - assert(order == LPC_ORD); - - lspres = switch_present("--lspres",argc,argv); - - lspdt = switch_present("--lspdt",argc,argv); - if ( (arg = switch_present("--lspdt_mode",argc,argv))) { - if (strcmp(argv[arg+1],"all") == 0) - lspdt_mode = LSPDT_ALL; - else if (strcmp(argv[arg+1],"low") == 0) - lspdt_mode = LSPDT_LOW; - else if (strcmp(argv[arg+1],"high") == 0) - lspdt_mode = LSPDT_HIGH; - else { - fprintf(stderr, "Error in lspdt_mode: %d\n", lspdt_mode); - exit(1); - } - } - else - lspdt_mode = LSPDT_ALL; - - phase0 = switch_present("--phase0",argc,argv); - if (phase0) { - ex_phase[0] = 0; - } - - hand_voicing = switch_present("--hand_voicing",argc,argv); - if (hand_voicing) { - fvoicing = fopen(argv[hand_voicing+1],"rt"); - assert(fvoicing != NULL); - } - - bg_est = 0.0; - postfilt = switch_present("--postfilter",argc,argv); - - decimate = switch_present("--dec",argc,argv); - - /* Initialise ------------------------------------------------------------*/ - - make_analysis_window(w,W); - make_synthesis_window(Pn); - quantise_init(); - - /* Main loop ------------------------------------------------------------*/ - - frames = 0; - sum_snr = 0; - while(fread(buf,sizeof(short),N,fin)) { - frames++; - //printf("frame: %d", frames); - - /* Read input speech */ - - for(i=0; i max_index) index = max_index; + if (index < min_index) index = min_index; + //printf("max_index: %d min_index: %d hard index: %d ", + // max_index, min_index, index); + + /* mask so that only LSB WO_DT_BITS remain, bit WO_DT_BITS is the sign bit */ + + mask = ((1 << WO_DT_BITS) - 1); + index &= mask; + //printf("mask: 0x%x index: 0x%x\n", mask, index); + + return index; +} + +/*---------------------------------------------------------------------------*\ + + FUNCTION....: decode_Wo_dt() + AUTHOR......: David Rowe + DATE CREATED: 6 Nov 2011 + + Decodes Wo using WO_DT_BITS difference from last frame. + +\*---------------------------------------------------------------------------*/ + +float decode_Wo_dt(int index, float prev_Wo) +{ + float Wo_min = TWO_PI/P_MAX; + float Wo_max = TWO_PI/P_MIN; + float step; + float Wo; + int mask; + + /* sign extend index */ + + //printf("DEC index: %d "); + if (index & (1 << (WO_DT_BITS-1))) { + mask = ~((1 << WO_DT_BITS) - 1); + index |= mask; + } + //printf("DEC mask: 0x%x index: %d \n", mask, index); + + step = (Wo_max - Wo_min)/WO_LEVELS; + Wo = prev_Wo + step*(index); + + return Wo; +} + /*---------------------------------------------------------------------------*\ FUNCTION....: speech_to_uq_lsps() diff --git a/codec2-dev/src/quantise.h b/codec2-dev/src/quantise.h index c74d206c..88b1ce39 100644 --- a/codec2-dev/src/quantise.h +++ b/codec2-dev/src/quantise.h @@ -26,16 +26,18 @@ #ifndef __QUANTISE__ #define __QUANTISE__ -#define WO_BITS 7 -#define WO_LEVELS (1<