From: drowe67 Date: Tue, 11 Oct 2016 02:08:29 +0000 (+0000) Subject: add stdin/stdout and fractional resampling support X-Git-Url: http://git.whiteaudio.com/gitweb/?a=commitdiff_plain;h=db281fab510ddf11bfcfab309a32b256da72fbc3;p=freetel-svn-tracking.git add stdin/stdout and fractional resampling support git-svn-id: https://svn.code.sf.net/p/freetel/code@2887 01035d8c-6547-0410-b346-abe4f91aad63 --- diff --git a/codec2-dev/unittest/tsrc.c b/codec2-dev/unittest/tsrc.c index ebdca3d1..90e695bf 100644 --- a/codec2-dev/unittest/tsrc.c +++ b/codec2-dev/unittest/tsrc.c @@ -16,6 +16,7 @@ #include #define N8 160 /* processing buffer size at 8 kHz */ +#define FS 8000 /* nominal input sample rate */ #define N48 ((int)N8*(48000/8000)) /* buf size assuming 48k max sample rate */ int main(int argc, char *argv[]) { @@ -29,14 +30,20 @@ int main(int argc, char *argv[]) { int error; if (argc != 4) { - printf("usage %s inputRawFile OutputRawFile OutputSamplerate\n", argv[0]); + printf("usage %s inputRawFile OutputRawFile OutSampleRatio\n", argv[0]); exit(0); } - f8k = fopen(argv[1], "rb"); + if (strcmp(argv[1], "-") == 0) + f8k = stdin; + else + f8k = fopen(argv[1], "rb"); assert(f8k != NULL); - fout = fopen(argv[2], "wb"); + if (strcmp(argv[2], "-") == 0) + fout = stdout; + else + fout = fopen(argv[2], "wb"); assert(fout != NULL); src = src_new(SRC_SINC_FASTEST, 1, &error); @@ -47,17 +54,18 @@ int main(int argc, char *argv[]) { data.input_frames = N8; data.output_frames = N48; data.end_of_input = 0; - data.src_ratio = atof(argv[3])/8000; - printf("%f\n", data.src_ratio); + data.src_ratio = atof(argv[3]); while(fread(in8k_short, sizeof(short), N8, f8k) == N8) { src_short_to_float_array(in8k_short, in8k, N8); src_process(src, &data); - printf("%d %d\n", (int)data.output_frames , (int)data.output_frames_gen); + //fprintf(stderr, "%d %d\n", (int)data.output_frames , (int)data.output_frames_gen); assert(data.output_frames_gen <= N48); src_float_to_short_array(out, out_short, data.output_frames_gen); fwrite(out_short, sizeof(short), data.output_frames_gen, fout); - } + if (fout == stdout) fflush(stdout); + if (f8k == stdin) fflush(stdin); + } fclose(fout); fclose(f8k);