/*---------------------------------------------------------------------------*\
FILE........: c2sim.c
AUTHOR......: David Rowe
DATE CREATED: 20/8/2010
Codec2 simulation. Combines encoder and decoder and allows switching in
out various algorithms and quantisation steps.
\*---------------------------------------------------------------------------*/
/*
Copyright (C) 2009 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.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
#include "defines.h"
#include "sine.h"
#include "nlp.h"
#include "dump.h"
#include "lpc.h"
#include "lsp.h"
#include "quantise.h"
#include "phase.h"
#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);
#ifdef DUMP
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);
lspdvq = switch_present("--lspdvq",argc,argv);
if (lspdvq)
assert(order == LPC_ORD);
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);
arg = switch_present("--resample",argc,argv);
resample = atoi(argv[arg+1]);
/* 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 32767.0)
buf[i] = 32767;
else if (Sn_[i] < -32767.0)
buf[i] = -32767;
else
buf[i] = Sn_[i];
}
}