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"))
{
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;
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);
convert_f_s24(input_buffer, s24buffer, the_bufsize, bigendian);
fwrite(s24buffer, sizeof(unsigned char)*3, the_bufsize, stdout);
TRY_YIELD;
}
}
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;
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);
fread(s24buffer, sizeof(unsigned char)*3, the_bufsize, stdin);
convert_s24_f(s24buffer, output_buffer, the_bufsize, bigendian);
FWRITE_R;
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);
unsigned char* ptemp=(unsigned char*)&temp;
output[k++]=*(ptemp+2);
output[k++]=*(ptemp+1);
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>>8);
unsigned char* ptemp=(unsigned char*)&temp;
output[k++]=*ptemp;
output[k++]=*(ptemp+1);
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;
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;
int temp=(input[i+2]<<24)|(input[i+1]<<16)|(input[i]<<8);
output[k++]=temp/(float)(INT_MAX-256);
}
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 temp=(input[i+2]<<8)|(input[i+1]<<16)|(input[i]<<24);
output[k++]=temp/(float)(INT_MAX-256);
}
}