From: drowe67 Date: Mon, 30 Jan 2017 23:27:21 +0000 (+0000) Subject: optional Fs/4 freq shift and some optimisation of tlininterp X-Git-Url: http://git.whiteaudio.com/gitweb/?a=commitdiff_plain;h=2e9a5d5e3c8db7a92a0a8fbcbc5324b6f2bcc25f;p=freetel-svn-tracking.git optional Fs/4 freq shift and some optimisation of tlininterp git-svn-id: https://svn.code.sf.net/p/freetel/code@3009 01035d8c-6547-0410-b346-abe4f91aad63 --- diff --git a/codec2-dev/unittest/tdec.c b/codec2-dev/unittest/tdec.c index 6b1f245f..9addcfe9 100644 --- a/codec2-dev/unittest/tdec.c +++ b/codec2-dev/unittest/tdec.c @@ -19,16 +19,20 @@ #define SIGNED_16BIT 0 #define SIGNED_8BIT 1 +void freq_shift_complex_buf(short buf[], int n, int lo_i[], int lo_q[]); + void display_help(void) { fprintf(stderr, "\nusage: tdec inputRawFile OutputRawFile DecimationRatio [-c]\n"); fprintf(stderr, "\nUse - for stdin/stdout\n\n"); fprintf(stderr, "-c complex signed 16 bit input and output\n"); fprintf(stderr, "-d complex signed 8 bit input, complex signed 16 bit output\n\n"); + fprintf(stderr, "-f -Fs/4 freq shift\n\n"); } int main(int argc, char *argv[]) { FILE *fin, *fout; short dec; + int lo_i[3], lo_q[3]; if (argc < 3) { display_help(); @@ -50,12 +54,16 @@ int main(int argc, char *argv[]) { dec = atoi(argv[3]); int channels = 1; + int freq_shift = 0; + lo_i[0] = -1; lo_i[1] = 0; + lo_q[0] = 0; lo_q[1] = -1; int opt; int format = SIGNED_16BIT; - while ((opt = getopt(argc, argv, "cd")) != -1) { + while ((opt = getopt(argc, argv, "cdf")) != -1) { switch (opt) { case 'c': channels = 2; break; case 'd': channels = 2; format = SIGNED_8BIT; break; + case 'f': freq_shift = 1; break; default: display_help(); exit(1); @@ -65,20 +73,25 @@ int main(int argc, char *argv[]) { if (format == SIGNED_16BIT) { short buf[dec*channels]; while(fread(buf, sizeof(short)*channels, dec, fin) == dec) { + if (freq_shift) + freq_shift_complex_buf(buf, dec*channels, lo_i, lo_q); + exit(0); fwrite(buf, sizeof(short), channels, fout); } } else { uint8_t inbuf[dec*channels]; - short outbuf[channels]; + short outbuf[dec*channels]; short sam, i; while(fread(inbuf, sizeof(uint8_t)*channels, dec, fin) == dec) { - for (i=0; i #include -#define SIGNED_16BIT 0 -#define SIGNED_8BIT 1 +#define NBUF 1000 +#define SIGNED_16BIT 0 +#define SIGNED_8BIT 1 void display_help(void) { fprintf(stderr, "\nusage: tlininterp inputRawFile OutputRawFile OverSampleRatio [-c]\n"); fprintf(stderr, "\nUse - for stdin/stdout\n\n"); fprintf(stderr, "-c complex signed 16 bit input and output\n"); fprintf(stderr, "-d complex signed 16 bit input, complex signed 8 bit output\n\n"); + fprintf(stderr, "-d complex signed 16 bit input, complex signed 8 bit output\n\n"); + fprintf(stderr, "-f +Fs/4 freq shift\n\n"); } int main(int argc, char *argv[]) { FILE *fin, *fout; - short left[2], right[2], out[2], i; + short left[2], right[2], out[2*NBUF], i; float oversample, t; - int8_t out_s8[2]; + int8_t out_s8[2*NBUF]; + int lo_i[3], lo_q[3]; if (argc < 3) { display_help(); @@ -54,12 +58,16 @@ int main(int argc, char *argv[]) { oversample = atof(argv[3]); int channels = 1; + int freq_shift = 0; + lo_i[0] = -1; lo_i[1] = 0; + lo_q[0] = 0; lo_q[1] = -1; int format = SIGNED_16BIT; int opt; - while ((opt = getopt(argc, argv, "cd")) != -1) { + while ((opt = getopt(argc, argv, "cdf")) != -1) { switch (opt) { case 'c': channels = 2; break; case 'd': channels = 2; format = SIGNED_8BIT; break; + case 'f': freq_shift = 1; break; default: display_help(); exit(1); @@ -69,30 +77,72 @@ int main(int argc, char *argv[]) { for (i=0; i> 8; + /* once we have enough samples write to disk */ + + j++; + if (j == NBUF) { + if (format == SIGNED_16BIT) { + fwrite(&out, sizeof(short)*channels, NBUF, fout); + } else { + for (i=0; i> 8; + } + fwrite(&out_s8, sizeof(int8_t)*channels, NBUF, fout); } - fwrite(&out_s8, sizeof(int8_t), channels, fout); + j = 0; } t += 1.0/oversample; } + t -= 1.0; for (i=0; i> 8; + } + fwrite(&out_s8, sizeof(int8_t)*channels, j, fout); + } + fclose(fout); fclose(fin);