From: drowe67 Date: Mon, 30 Jan 2017 05:27:39 +0000 (+0000) Subject: added 8 bit signed ouput example, scatter looks OK X-Git-Url: http://git.whiteaudio.com/gitweb/?a=commitdiff_plain;h=79bb10637ea3ca56133ab0b5b195d75a94466fa1;p=freetel-svn-tracking.git added 8 bit signed ouput example, scatter looks OK git-svn-id: https://svn.code.sf.net/p/freetel/code@3007 01035d8c-6547-0410-b346-abe4f91aad63 --- diff --git a/codec2-dev/unittest/tdec.c b/codec2-dev/unittest/tdec.c index 724dfa49..6b1f245f 100644 --- a/codec2-dev/unittest/tdec.c +++ b/codec2-dev/unittest/tdec.c @@ -1,11 +1,9 @@ /* - tlininterp.c + tdec.c David Rowe Jan 2017 - Linear interpolator, CPU effecient way of getting large oversample - ratios, if the input is already limited to a fraction of the - input sampling rate. + Trivial non filtered decimator for high ration sample rate conversion. build: gcc tdec.c -o tdec -Wall -O2 @@ -16,11 +14,16 @@ #include #include #include +#include + +#define SIGNED_16BIT 0 +#define SIGNED_8BIT 1 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 (two channel) resampling\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"); } int main(int argc, char *argv[]) { @@ -48,19 +51,37 @@ int main(int argc, char *argv[]) { int channels = 1; int opt; - while ((opt = getopt(argc, argv, "c")) != -1) { + int format = SIGNED_16BIT; + while ((opt = getopt(argc, argv, "cd")) != -1) { switch (opt) { case 'c': channels = 2; break; + case 'd': channels = 2; format = SIGNED_8BIT; break; default: display_help(); exit(1); } } - short buf[dec*channels]; - fprintf(stderr, "dec: %d\n", dec); - while(fread(buf, sizeof(short)*channels, dec, fin) == dec) { - fwrite(buf, sizeof(short), channels, fout); + if (format == SIGNED_16BIT) { + short buf[dec*channels]; + while(fread(buf, sizeof(short)*channels, dec, fin) == dec) { + fwrite(buf, sizeof(short), channels, fout); + } + } + else { + uint8_t inbuf[dec*channels]; + short outbuf[channels]; + short sam, i; + + while(fread(inbuf, sizeof(uint8_t)*channels, dec, fin) == dec) { + for (i=0; i #include #include +#include -#define N 10000 /* processing buffer size */ +#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 (two channel) resampling\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"); } int main(int argc, char *argv[]) { FILE *fin, *fout; - short left, right, out; + short left[2], right[2], out[2], i; float oversample, t; + int8_t out_s8[2]; if (argc < 3) { display_help(); @@ -50,26 +54,43 @@ int main(int argc, char *argv[]) { oversample = atof(argv[3]); int channels = 1; + int format = SIGNED_16BIT; int opt; - while ((opt = getopt(argc, argv, "c")) != -1) { + while ((opt = getopt(argc, argv, "cd")) != -1) { switch (opt) { case 'c': channels = 2; break; + case 'd': channels = 2; format = SIGNED_8BIT; break; default: display_help(); exit(1); } } - left = 0; + for (i=0; i> 8; + } + fwrite(&out_s8, sizeof(int8_t), channels, fout); + } + t += 1.0/oversample; } t -= 1.0; - left = right; + for (i=0; i