From: drowe67 Date: Wed, 7 Nov 2012 22:19:07 +0000 (+0000) Subject: added burst error model simulation X-Git-Url: http://git.whiteaudio.com/gitweb/?a=commitdiff_plain;h=a165567ec5bc65e238e932b7f28f98b1b445bc41;p=freetel-svn-tracking.git added burst error model simulation git-svn-id: https://svn.code.sf.net/p/freetel/code@945 01035d8c-6547-0410-b346-abe4f91aad63 --- diff --git a/codec2-dev/src/c2dec.c b/codec2-dev/src/c2dec.c index d425fdc1..fd4a04d3 100644 --- a/codec2-dev/src/c2dec.c +++ b/codec2-dev/src/c2dec.c @@ -32,6 +32,10 @@ #include #include +#define NONE 0 /* no bit errors */ +#define UNIFORM 1 /* random bit errors */ +#define TWO_STATE 2 /* Two state error model */ + int main(int argc, char *argv[]) { int mode; @@ -40,12 +44,17 @@ int main(int argc, char *argv[]) FILE *fout; short *buf; unsigned char *bits; - int nsam, nbit, nbyte, i, byte, frames, bit_errors; - float ber, r; + int nsam, nbit, nbyte, i, byte, frames, bit_errors, error_mode; + int state, next_state; + float ber, r, pstate0, pstate1; if (argc < 4) { - printf("usage: c2dec 3200|2400|1400|1200 InputBitFile OutputRawSpeechFile [ber]\n"); + printf("basic usage...............: c2dec 3200|2400|1400|1200 InputBitFile OutputRawSpeechFile\n"); + printf("uniform errors usage.......: c2dec 3200|2400|1400|1200 InputBitFile OutputRawSpeechFile uniformBER\n"); + printf("two state fading usage....: c2dec 3200|2400|1400|1200 InputBitFile OutputRawSpeechFile probGood probBad\n"); printf("e.g c2dec 1400 hts1a.c2 hts1a_1400.raw\n"); + printf("e.g c2dec 1400 hts1a.c2 hts1a_1400.raw 0.9\n"); + printf("e.g c2dec 1400 hts1a.c2 hts1a_1400.raw 0.99 0.9\n"); exit(1); } @@ -76,10 +85,21 @@ int main(int argc, char *argv[]) exit(1); } - if (argc == 5) + error_mode = NONE; + ber = 0.0; + pstate0 = pstate1 = 0.0; + + if (argc == 5) { + error_mode = UNIFORM; ber = atof(argv[4]); - else - ber = 0.0; + } + + if (argc == 6) { + error_mode = TWO_STATE; + pstate0 = atof(argv[4]); + pstate1 = atof(argv[5]); + state = 0; + } codec2 = codec2_create(mode); nsam = codec2_samples_per_frame(codec2); @@ -91,7 +111,7 @@ int main(int argc, char *argv[]) while(fread(bits, sizeof(char), nbyte, fin) == (size_t)nbyte) { frames++; - if (ber != 0.0) { + if (error_mode == UNIFORM) { for(i=0; i pstate0) + next_state = 1; + break; + + case 1: + + /* burst error state - 50% bit error rate */ + + for(i=0; i pstate1) + next_state = 0; + break; + + } + + state = next_state; + } + codec2_decode(codec2, buf, bits); fwrite(buf, sizeof(short), nsam, fout); //if this is in a pipeline, we probably don't want the usual