From 1ae097f28f76d34e75e1d8fffdf5d7c57581058b Mon Sep 17 00:00:00 2001 From: Mark Jessop Date: Sat, 27 Jul 2019 12:27:15 +0930 Subject: [PATCH] rx_tester Python 3 compatability. --- rx/rx_tester.py | 15 +++++-- src/tsrc.c | 111 ------------------------------------------------ 2 files changed, 12 insertions(+), 114 deletions(-) delete mode 100644 src/tsrc.c diff --git a/rx/rx_tester.py b/rx/rx_tester.py index 653558e..69d19ec 100644 --- a/rx/rx_tester.py +++ b/rx/rx_tester.py @@ -12,9 +12,12 @@ import time, sys, os +# Check if we are running in Python 2 or 3 +PY3 = sys.version_info[0] == 3 + # Set to whatever resolution you want to test. file_path = "../test_images/%d_800x608.bin" # _raw, _800x608, _640x480, _320x240 -image_numbers = xrange(1,14) +image_numbers = range(1,14) print_as_hex = False @@ -28,12 +31,18 @@ def print_file(filename): f = open(filename,'rb') - for x in range(file_size/256): + for x in range(file_size//256): data = f.read(256) if print_as_hex: data = "".join("{:02x}".format(ord(c)) for c in data) + "\n" - sys.stdout.write(data) + if PY3: + # Python 3 doesn't let us write bytes to stdout directly. + sys.stdout.buffer.write(data) + else: + # Python 2 does.. + sys.stdout.write(data) + sys.stdout.flush() time.sleep(delay_time) diff --git a/src/tsrc.c b/src/tsrc.c deleted file mode 100644 index 3dc3834..0000000 --- a/src/tsrc.c +++ /dev/null @@ -1,111 +0,0 @@ -/* - tsrc.c - David Rowe - Sat Nov 3 2012 - - Unit test for libresample code. - - build: gcc tsrc.c -o tsrc -lm -lsamplerate - - */ - -#include -#include -#include -#include -#include -#include -#include - -#define N 10000 /* processing buffer size */ - -void display_help(void) { - fprintf(stderr, "\nusage: tsrc inputRawFile OutputRawFile OutSampleRatio [-l] [-c]\n"); - fprintf(stderr, "\nUse - for stdin/stdout\n\n"); - fprintf(stderr, "-l fast linear resampler\n"); - fprintf(stderr, "-c complex (two channel) resampling\n\n"); -} - -int main(int argc, char *argv[]) { - FILE *fin, *fout; - short in_short[N], out_short[N]; - float in[N], out[N]; - SRC_STATE *src; - SRC_DATA data; - int error, nin, nremaining, i; - - if (argc < 3) { - display_help(); - exit(1); - } - - if (strcmp(argv[1], "-") == 0) - fin = stdin; - else - fin = fopen(argv[1], "rb"); - assert(fin != NULL); - - if (strcmp(argv[2], "-") == 0) - fout = stdout; - else - fout = fopen(argv[2], "wb"); - assert(fout != NULL); - - data.data_in = in; - data.data_out = out; - data.end_of_input = 0; - data.src_ratio = atof(argv[3]); - - int channels = 1; - int resampler = SRC_SINC_FASTEST; - int opt; - while ((opt = getopt(argc, argv, "lc")) != -1) { - switch (opt) { - case 'l': resampler = SRC_LINEAR; break; - case 'c': channels = 2; break; - default: - display_help(); - exit(1); - } - } - - channels = 2; - - data.input_frames = N/channels; - data.output_frames = N/channels; - - src = src_new(resampler, channels, &error); - assert(src != NULL); - - int total_in = 0; - int total_out = 0; - - nin = data.input_frames; - nremaining = 0; - while(fread(&in_short[nremaining*channels], sizeof(short)*channels, nin, fin) == nin) { - src_short_to_float_array(in_short, in, N); - error = src_process(src, &data); - assert(error == 0); - src_float_to_short_array(out, out_short, data.output_frames_gen*channels); - - fwrite(out_short, sizeof(short), data.output_frames_gen*channels, fout); - if (fout == stdout) fflush(stdout); - - nremaining = data.input_frames - data.input_frames_used; - nin = data.input_frames_used; - //fprintf(stderr, "input frames: %d output_frames %d nremaining: %d\n", - // (int)data.input_frames_used, (int)data.output_frames_gen, nremaining); - for(i=0; i