Merge pull request #4 from mossmann/master
converters for signed chars, compatible with hackrf_transfer
This commit is contained in:
commit
99dd4b378c
4 changed files with 39 additions and 0 deletions
|
@ -122,6 +122,8 @@ The following commands are available:
|
||||||
|
|
||||||
- `csdr convert_u8_f`
|
- `csdr convert_u8_f`
|
||||||
- `csdr convert_f_u8`
|
- `csdr convert_f_u8`
|
||||||
|
- `csdr convert_s8_f`
|
||||||
|
- `csdr convert_f_s8`
|
||||||
- `csdr convert_i16_f`
|
- `csdr convert_i16_f`
|
||||||
- `csdr convert_f_i16`
|
- `csdr convert_f_i16`
|
||||||
|
|
||||||
|
|
25
csdr.c
25
csdr.c
|
@ -55,6 +55,8 @@ char usage[]=
|
||||||
"list of functions:\n\n"
|
"list of functions:\n\n"
|
||||||
" convert_u8_f\n"
|
" convert_u8_f\n"
|
||||||
" convert_f_u8\n"
|
" convert_f_u8\n"
|
||||||
|
" convert_s8_f\n"
|
||||||
|
" convert_f_s8\n"
|
||||||
" convert_f_i16\n"
|
" convert_f_i16\n"
|
||||||
" convert_i16_f\n"
|
" convert_i16_f\n"
|
||||||
" realpart_cf\n"
|
" realpart_cf\n"
|
||||||
|
@ -204,6 +206,7 @@ int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
static float input_buffer[BIG_BUFSIZE*2];
|
static float input_buffer[BIG_BUFSIZE*2];
|
||||||
static unsigned char buffer_u8[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 float output_buffer[BIG_BUFSIZE*2];
|
||||||
static short buffer_i16[BIG_BUFSIZE*2];
|
static short buffer_i16[BIG_BUFSIZE*2];
|
||||||
static float temp_f[BIG_BUFSIZE*4];
|
static float temp_f[BIG_BUFSIZE*4];
|
||||||
|
@ -231,6 +234,28 @@ int main(int argc, char *argv[])
|
||||||
TRY_YIELD;
|
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"))
|
if(!strcmp(argv[1],"convert_f_i16"))
|
||||||
{
|
{
|
||||||
for(;;)
|
for(;;)
|
||||||
|
|
10
libcsdr.c
10
libcsdr.c
|
@ -805,6 +805,11 @@ void convert_u8_f(unsigned char* input, float* output, int input_size)
|
||||||
for(int i=0;i<input_size;i++) output[i]=((float)input[i])/(UCHAR_MAX/2.0)-1.0; //@convert_u8_f
|
for(int i=0;i<input_size;i++) output[i]=((float)input[i])/(UCHAR_MAX/2.0)-1.0; //@convert_u8_f
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void convert_s8_f(signed char* input, float* output, int input_size)
|
||||||
|
{
|
||||||
|
for(int i=0;i<input_size;i++) output[i]=((float)input[i])/SCHAR_MAX; //@convert_s8_f
|
||||||
|
}
|
||||||
|
|
||||||
void convert_i16_f(short* input, float* output, int input_size)
|
void convert_i16_f(short* input, float* output, int input_size)
|
||||||
{
|
{
|
||||||
for(int i=0;i<input_size;i++) output[i]=(float)input[i]/SHRT_MAX; //@convert_i16_f
|
for(int i=0;i<input_size;i++) output[i]=(float)input[i]/SHRT_MAX; //@convert_i16_f
|
||||||
|
@ -817,6 +822,11 @@ void convert_f_u8(float* input, unsigned char* output, int input_size)
|
||||||
//of at least -60 dB is shown on the FFT plot after convert_f_u8 -> convert_u8_f
|
//of at least -60 dB is shown on the FFT plot after convert_f_u8 -> convert_u8_f
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void convert_f_s8(float* input, signed char* output, int input_size)
|
||||||
|
{
|
||||||
|
for(int i=0;i<input_size;i++) output[i]=input[i]*SCHAR_MAX; //@convert_f_s8
|
||||||
|
}
|
||||||
|
|
||||||
void convert_f_i16(float* input, short* output, int input_size)
|
void convert_f_i16(float* input, short* output, int input_size)
|
||||||
{
|
{
|
||||||
/*for(int i=0;i<input_size;i++)
|
/*for(int i=0;i<input_size;i++)
|
||||||
|
|
|
@ -164,6 +164,8 @@ void gain_ff(float* input, float* output, int input_size, float gain);
|
||||||
|
|
||||||
void convert_u8_f(unsigned char* input, float* output, int input_size);
|
void convert_u8_f(unsigned char* input, float* output, int input_size);
|
||||||
void convert_f_u8(float* input, unsigned char* output, int input_size);
|
void convert_f_u8(float* input, unsigned char* output, int input_size);
|
||||||
|
void convert_s8_f(signed char* input, float* output, int input_size);
|
||||||
|
void convert_f_s8(float* input, signed char* output, int input_size);
|
||||||
void convert_f_i16(float* input, short* output, int input_size);
|
void convert_f_i16(float* input, short* output, int input_size);
|
||||||
void convert_i16_f(short* input, float* output, int input_size);
|
void convert_i16_f(short* input, float* output, int input_size);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue