Added convert_s24_f and convert_f_s24
This commit is contained in:
parent
84e00184af
commit
c4b3527490
3 changed files with 77 additions and 9 deletions
30
csdr.c
30
csdr.c
|
@ -61,6 +61,8 @@ char usage[]=
|
||||||
" convert_f_s8\n"
|
" convert_f_s8\n"
|
||||||
" convert_f_s16\n"
|
" convert_f_s16\n"
|
||||||
" convert_s16_f\n"
|
" convert_s16_f\n"
|
||||||
|
" convert_f_s24\n"
|
||||||
|
" convert_s24_f\n"
|
||||||
" realpart_cf\n"
|
" realpart_cf\n"
|
||||||
" clipdetect_ff\n"
|
" clipdetect_ff\n"
|
||||||
" limit_ff [max_amplitude]\n"
|
" limit_ff [max_amplitude]\n"
|
||||||
|
@ -486,7 +488,7 @@ int main(int argc, char *argv[])
|
||||||
TRY_YIELD;
|
TRY_YIELD;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if((!strcmp(argv[1],"convert_i16_f")) || (!strcmp(argv[1],"convert_s16_f"))) //not tested
|
if((!strcmp(argv[1],"convert_i16_f")) || (!strcmp(argv[1],"convert_s16_f")))
|
||||||
{
|
{
|
||||||
if(!sendbufsize(initialize_buffers())) return -2;
|
if(!sendbufsize(initialize_buffers())) return -2;
|
||||||
for(;;)
|
for(;;)
|
||||||
|
@ -498,6 +500,32 @@ int main(int argc, char *argv[])
|
||||||
TRY_YIELD;
|
TRY_YIELD;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(!strcmp(argv[1],"convert_f_s24"))
|
||||||
|
{
|
||||||
|
int bigendian = argc>2 && !strcmp(argv[2],"--bigendian");
|
||||||
|
if(!sendbufsize(initialize_buffers())) return -2;
|
||||||
|
for(;;)
|
||||||
|
{
|
||||||
|
FEOF_CHECK;
|
||||||
|
FREAD_R;
|
||||||
|
convert_f_s24(input_buffer, (unsigned char*)output_buffer, the_bufsize, bigendian);
|
||||||
|
fwrite(output_buffer, sizeof(unsigned char)*3, the_bufsize, stdout);
|
||||||
|
TRY_YIELD;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(!strcmp(argv[1],"convert_s24_f"))
|
||||||
|
{
|
||||||
|
int bigendian = argc>2 && !strcmp(argv[2],"--bigendian");
|
||||||
|
if(!sendbufsize(initialize_buffers())) return -2;
|
||||||
|
for(;;)
|
||||||
|
{
|
||||||
|
FEOF_CHECK;
|
||||||
|
fread(input_buffer, sizeof(unsigned char)*3, the_bufsize, stdin);
|
||||||
|
convert_s24_f((unsigned char*)input_buffer, output_buffer, the_bufsize, bigendian);
|
||||||
|
FWRITE_R;
|
||||||
|
TRY_YIELD;
|
||||||
|
}
|
||||||
|
}
|
||||||
if(!strcmp(argv[1],"realpart_cf"))
|
if(!strcmp(argv[1],"realpart_cf"))
|
||||||
{
|
{
|
||||||
if(!sendbufsize(initialize_buffers())) return -2;
|
if(!sendbufsize(initialize_buffers())) return -2;
|
||||||
|
|
37
libcsdr.c
37
libcsdr.c
|
@ -999,6 +999,43 @@ void convert_f_s16(float* input, short* output, int input_size)
|
||||||
void convert_i16_f(short* input, float* output, int input_size) { convert_s16_f(input, output, input_size); }
|
void convert_i16_f(short* input, float* output, int input_size) { convert_s16_f(input, output, input_size); }
|
||||||
void convert_f_i16(float* input, short* output, int input_size) { convert_f_s16(input, output, input_size); }
|
void convert_f_i16(float* input, short* output, int input_size) { convert_f_s16(input, output, input_size); }
|
||||||
|
|
||||||
|
void convert_f_s24(float* input, unsigned char* output, int input_size, int bigendian)
|
||||||
|
{
|
||||||
|
int k=0;
|
||||||
|
if(bigendian) for(int i=0;i<input_size;i++)
|
||||||
|
{
|
||||||
|
int temp=input[i]*INT_MAX;
|
||||||
|
unsigned char* ptemp=(unsigned char*)&temp;
|
||||||
|
output[k++]=*ptemp;
|
||||||
|
output[k++]=*(ptemp+1);
|
||||||
|
output[k++]=*(ptemp+2);
|
||||||
|
}
|
||||||
|
else for(int i=0;i<input_size;i++)
|
||||||
|
{
|
||||||
|
int temp=input[i]*INT_MAX;
|
||||||
|
unsigned char* ptemp=(unsigned char*)&temp;
|
||||||
|
output[k++]=*(ptemp+2);
|
||||||
|
output[k++]=*(ptemp+1);
|
||||||
|
output[k++]=*ptemp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void convert_s24_f(unsigned char* input, float* output, int input_size, int bigendian)
|
||||||
|
{
|
||||||
|
int k=0;
|
||||||
|
if(bigendian) for(int i=0;i<input_size*3;i+=3)
|
||||||
|
{
|
||||||
|
int temp=(input[i+2]<<8)|(input[i+1]<<16)|(input[i]<<24);
|
||||||
|
output[k++]=((float)temp)/INT_MAX;
|
||||||
|
}
|
||||||
|
else for(int i=0;i<input_size*3;i+=3)
|
||||||
|
{
|
||||||
|
int temp=(input[i]<<8)|(input[i+1]<<16)|(input[i+2]<<24);
|
||||||
|
output[k++]=((float)temp)/INT_MAX;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int trivial_vectorize()
|
int trivial_vectorize()
|
||||||
{
|
{
|
||||||
//this function is trivial to vectorize and should pass on both NEON and SSE
|
//this function is trivial to vectorize and should pass on both NEON and SSE
|
||||||
|
|
|
@ -176,5 +176,8 @@ void convert_f_s16(float* input, short* output, int input_size);
|
||||||
void convert_s16_f(short* input, float* output, int input_size);
|
void convert_s16_f(short* input, float* 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);
|
||||||
|
void convert_f_s24(float* input, unsigned char* output, int input_size, int bigendian);
|
||||||
|
void convert_s24_f(unsigned char* input, float* output, int input_size, int bigendian);
|
||||||
|
|
||||||
|
|
||||||
int is_nan(float f);
|
int is_nan(float f);
|
||||||
|
|
Loading…
Reference in a new issue