Skip to content

Commit 99dd4b3

Browse files
committedNov 22, 2015
Merge pull request ha7ilm#4 from mossmann/master
converters for signed chars, compatible with hackrf_transfer
2 parents 6ee80ea + a3ad1e6 commit 99dd4b3

File tree

4 files changed

+39
-0
lines changed

4 files changed

+39
-0
lines changed
 

‎README.md

+2
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ The following commands are available:
122122

123123
- `csdr convert_u8_f`
124124
- `csdr convert_f_u8`
125+
- `csdr convert_s8_f`
126+
- `csdr convert_f_s8`
125127
- `csdr convert_i16_f`
126128
- `csdr convert_f_i16`
127129

‎csdr.c

+25
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ char usage[]=
5555
"list of functions:\n\n"
5656
" convert_u8_f\n"
5757
" convert_f_u8\n"
58+
" convert_s8_f\n"
59+
" convert_f_s8\n"
5860
" convert_f_i16\n"
5961
" convert_i16_f\n"
6062
" realpart_cf\n"
@@ -204,6 +206,7 @@ int main(int argc, char *argv[])
204206
{
205207
static float input_buffer[BIG_BUFSIZE*2];
206208
static unsigned char buffer_u8[BIG_BUFSIZE*2];
209+
static signed char buffer_s8[BIG_BUFSIZE*2];
207210
static float output_buffer[BIG_BUFSIZE*2];
208211
static short buffer_i16[BIG_BUFSIZE*2];
209212
static float temp_f[BIG_BUFSIZE*4];
@@ -231,6 +234,28 @@ int main(int argc, char *argv[])
231234
TRY_YIELD;
232235
}
233236
}
237+
if(!strcmp(argv[1],"convert_s8_f"))
238+
{
239+
for(;;)
240+
{
241+
FEOF_CHECK;
242+
fread(buffer_s8, sizeof(signed char), BUFSIZE, stdin);
243+
convert_s8_f(buffer_s8, output_buffer, BUFSIZE);
244+
FWRITE_R;
245+
TRY_YIELD;
246+
}
247+
}
248+
if(!strcmp(argv[1],"convert_f_s8")) //not tested
249+
{
250+
for(;;)
251+
{
252+
FEOF_CHECK;
253+
FREAD_R;
254+
convert_f_s8(input_buffer, buffer_s8, BUFSIZE);
255+
fwrite(buffer_s8, sizeof(signed char), BUFSIZE, stdout);
256+
TRY_YIELD;
257+
}
258+
}
234259
if(!strcmp(argv[1],"convert_f_i16"))
235260
{
236261
for(;;)

‎libcsdr.c

+10
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,11 @@ void convert_u8_f(unsigned char* input, float* output, int input_size)
805805
for(int i=0;i<input_size;i++) output[i]=((float)input[i])/(UCHAR_MAX/2.0)-1.0; //@convert_u8_f
806806
}
807807

808+
void convert_s8_f(signed char* input, float* output, int input_size)
809+
{
810+
for(int i=0;i<input_size;i++) output[i]=((float)input[i])/SCHAR_MAX; //@convert_s8_f
811+
}
812+
808813
void convert_i16_f(short* input, float* output, int input_size)
809814
{
810815
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)
817822
//of at least -60 dB is shown on the FFT plot after convert_f_u8 -> convert_u8_f
818823
}
819824

825+
void convert_f_s8(float* input, signed char* output, int input_size)
826+
{
827+
for(int i=0;i<input_size;i++) output[i]=input[i]*SCHAR_MAX; //@convert_f_s8
828+
}
829+
820830
void convert_f_i16(float* input, short* output, int input_size)
821831
{
822832
/*for(int i=0;i<input_size;i++)

‎libcsdr.h

+2
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ void gain_ff(float* input, float* output, int input_size, float gain);
164164

165165
void convert_u8_f(unsigned char* input, float* output, int input_size);
166166
void convert_f_u8(float* input, unsigned char* output, int input_size);
167+
void convert_s8_f(signed char* input, float* output, int input_size);
168+
void convert_f_s8(float* input, signed char* output, int input_size);
167169
void convert_f_i16(float* input, short* output, int input_size);
168170
void convert_i16_f(short* input, float* output, int input_size);
169171

0 commit comments

Comments
 (0)
Please sign in to comment.