From a3ad1e62d95d54e882c78f7aa9fbdeaea8f582f1 Mon Sep 17 00:00:00 2001 From: Michael Ossmann Date: Sun, 22 Nov 2015 12:53:10 -0700 Subject: [PATCH] converters for signed chars, compatible with hackrf_transfer --- README.md | 2 ++ csdr.c | 25 +++++++++++++++++++++++++ libcsdr.c | 10 ++++++++++ libcsdr.h | 2 ++ 4 files changed, 39 insertions(+) diff --git a/README.md b/README.md index 1742454..138bf38 100644 --- a/README.md +++ b/README.md @@ -122,6 +122,8 @@ The following commands are available: - `csdr convert_u8_f` - `csdr convert_f_u8` +- `csdr convert_s8_f` +- `csdr convert_f_s8` - `csdr convert_i16_f` - `csdr convert_f_i16` diff --git a/csdr.c b/csdr.c index 0b64829..56b9deb 100644 --- a/csdr.c +++ b/csdr.c @@ -55,6 +55,8 @@ char usage[]= "list of functions:\n\n" " convert_u8_f\n" " convert_f_u8\n" +" convert_s8_f\n" +" convert_f_s8\n" " convert_f_i16\n" " convert_i16_f\n" " realpart_cf\n" @@ -204,6 +206,7 @@ int main(int argc, char *argv[]) { static float input_buffer[BIG_BUFSIZE*2]; static unsigned char buffer_u8[BIG_BUFSIZE*2]; + static signed char buffer_s8[BIG_BUFSIZE*2]; static float output_buffer[BIG_BUFSIZE*2]; static short buffer_i16[BIG_BUFSIZE*2]; static float temp_f[BIG_BUFSIZE*4]; @@ -231,6 +234,28 @@ int main(int argc, char *argv[]) TRY_YIELD; } } + if(!strcmp(argv[1],"convert_s8_f")) + { + for(;;) + { + FEOF_CHECK; + fread(buffer_s8, sizeof(signed char), BUFSIZE, stdin); + convert_s8_f(buffer_s8, output_buffer, BUFSIZE); + FWRITE_R; + TRY_YIELD; + } + } + if(!strcmp(argv[1],"convert_f_s8")) //not tested + { + for(;;) + { + FEOF_CHECK; + FREAD_R; + convert_f_s8(input_buffer, buffer_s8, BUFSIZE); + fwrite(buffer_s8, sizeof(signed char), BUFSIZE, stdout); + TRY_YIELD; + } + } if(!strcmp(argv[1],"convert_f_i16")) { for(;;) diff --git a/libcsdr.c b/libcsdr.c index 2cf5e9b..a767727 100644 --- a/libcsdr.c +++ b/libcsdr.c @@ -805,6 +805,11 @@ void convert_u8_f(unsigned char* input, float* output, int input_size) for(int i=0;i convert_u8_f } +void convert_f_s8(float* input, signed char* output, int input_size) +{ + for(int i=0;i