Fixed 24 bit conversions

This commit is contained in:
ha7ilm 2016-06-23 10:50:08 +02:00
parent de110ff719
commit ef39d8dc27
2 changed files with 16 additions and 14 deletions

14
csdr.c
View file

@ -502,26 +502,28 @@ int main(int argc, char *argv[])
} }
if(!strcmp(argv[1],"convert_f_s24")) if(!strcmp(argv[1],"convert_f_s24"))
{ {
int bigendian = argc>2 && !strcmp(argv[2],"--bigendian"); int bigendian = (argc>2) && (!strcmp(argv[2],"--bigendian"));
unsigned char* s24buffer = (unsigned char*)malloc(sizeof(unsigned char)*the_bufsize*3);
if(!sendbufsize(initialize_buffers())) return -2; if(!sendbufsize(initialize_buffers())) return -2;
for(;;) for(;;)
{ {
FEOF_CHECK; FEOF_CHECK;
FREAD_R; FREAD_R;
convert_f_s24(input_buffer, (unsigned char*)output_buffer, the_bufsize, bigendian); convert_f_s24(input_buffer, s24buffer, the_bufsize, bigendian);
fwrite(output_buffer, sizeof(unsigned char)*3, the_bufsize, stdout); fwrite(s24buffer, sizeof(unsigned char)*3, the_bufsize, stdout);
TRY_YIELD; TRY_YIELD;
} }
} }
if(!strcmp(argv[1],"convert_s24_f")) if(!strcmp(argv[1],"convert_s24_f"))
{ {
int bigendian = argc>2 && !strcmp(argv[2],"--bigendian"); int bigendian = (argc>2) && (!strcmp(argv[2],"--bigendian"));
unsigned char* s24buffer = (unsigned char*)malloc(sizeof(unsigned char)*the_bufsize*3);
if(!sendbufsize(initialize_buffers())) return -2; if(!sendbufsize(initialize_buffers())) return -2;
for(;;) for(;;)
{ {
FEOF_CHECK; FEOF_CHECK;
fread(input_buffer, sizeof(unsigned char)*3, the_bufsize, stdin); fread(s24buffer, sizeof(unsigned char)*3, the_bufsize, stdin);
convert_s24_f((unsigned char*)input_buffer, output_buffer, the_bufsize, bigendian); convert_s24_f(s24buffer, output_buffer, the_bufsize, bigendian);
FWRITE_R; FWRITE_R;
TRY_YIELD; TRY_YIELD;
} }

View file

@ -1006,17 +1006,17 @@ void convert_f_s24(float* input, unsigned char* output, int input_size, int bige
{ {
int temp=input[i]*(INT_MAX>>8); int temp=input[i]*(INT_MAX>>8);
unsigned char* ptemp=(unsigned char*)&temp; unsigned char* ptemp=(unsigned char*)&temp;
output[k++]=*(ptemp+2);
output[k++]=*(ptemp+1);
output[k++]=*ptemp; output[k++]=*ptemp;
output[k++]=*(ptemp+1);
output[k++]=*(ptemp+2);
} }
else for(int i=0;i<input_size;i++) else for(int i=0;i<input_size;i++)
{ {
int temp=input[i]*(INT_MAX>>8); int temp=input[i]*(INT_MAX>>8);
unsigned char* ptemp=(unsigned char*)&temp; unsigned char* ptemp=(unsigned char*)&temp;
output[k++]=*ptemp;
output[k++]=*(ptemp+1);
output[k++]=*(ptemp+2); output[k++]=*(ptemp+2);
output[k++]=*(ptemp+1);
output[k++]=*ptemp;
} }
} }
@ -1025,13 +1025,13 @@ void convert_s24_f(unsigned char* input, float* output, int input_size, int bige
int k=0; int k=0;
if(bigendian) for(int i=0;i<input_size*3;i+=3) 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); int temp=(input[i+2]<<24)|(input[i+1]<<16)|(input[i]<<8);
output[k++]=((float)temp)/INT_MAX; output[k++]=temp/(float)(INT_MAX-256);
} }
else for(int i=0;i<input_size*3;i+=3) else for(int i=0;i<input_size*3;i+=3)
{ {
int temp=(input[i]<<8)|(input[i+1]<<16)|(input[i+2]<<24); int temp=(input[i+2]<<8)|(input[i+1]<<16)|(input[i]<<24);
output[k++]=((float)temp)/INT_MAX; output[k++]=temp/(float)(INT_MAX-256);
} }
} }