I have a buffer with many positive 16-bit values (which are stored as doubles) that I would like to quantize to 8 bits (0-255 values).
According to Wikipedia, the process will look like this:
So, I wonder if C has a function that can do this quantization, or does anyone know of a C implementation that I could use?
Lots of love, Louise
Assuming the value dis in the range [0.0, max]:
d
[0.0, max]
unsigned char quantize(double d, double max) { return (unsigned char)((d / max) * 255.0); }
, "16- "; 64- IEEE-754. , , .
, - 16 PCM-, - 8- PCM, .
8- PCM , , 128 . (, )
, . ,
double dMax = max_of_all_values(); // ... foreach (dValue in array_of_doubles) { signed char bValue = (signed char)((dValue / dMax)*127.0); }
, , , , , .
: char , 8- PCM, , .
: , . , , ( )
, , " 16- ( )" ; 16 , , .
, , 16- , 1.0 ( 0.0 <= s <= 1.0), , , 8- , 255.
unsigned char s8 = s * 255 ;
0.0 <= s <= 1.0, 0.0 <= s <= max, :
unsigned char s8 = s / max * 255 ;
, , , ; , , ( , , , , , , μ-lay A-law).
Source: https://habr.com/ru/post/1726671/More articles:Alternative mod_expires for setting expiration headers? - phpWhen not to implement a common interface? - genericsBogus IP address from getaddrinfo & inet_ntop - c ++Linking C.obj files in a Delphi application, resolving standard C dependencies - cWhat markup language to store in the database? - databaselatex template or example for personal application - latexПолучение звука непосредственно с аппаратного обеспечения с помощью С# - c#Что означает "- (void)" означает в объявлении этой функции? `- (недействительными) awakeFromNib` - objective-cBizspark is now over 2 months before approval - bizsparkWhy is my custom error handler not called? - phpAll Articles