I have a voice sample. It's coded with 8 bits per sample (char).
What's the correct algorithm to convert the VALUE (not just the type) into 16 bits (short)?
Thanks
Printable View
I have a voice sample. It's coded with 8 bits per sample (char).
What's the correct algorithm to convert the VALUE (not just the type) into 16 bits (short)?
Thanks
Just square the value of the 8bit variable. The 8bit value 256, will then end up being 65536 (the max for a 16bit variable), but 0 will still be 0. Is that what you wanted?The resulting data will of course not be any more accurate than the original 8bit data though.Code:unsigned char some_value = 128;
unsigned short resulting_value = static_cast<unsigned short>(some_value) * static_cast<unsigned short>(some_value);
Hm.. now that Assmaster has suggested.. I don't know , first off, what the requirement is .
But if it is a voice waveform that you have , does squaring the each value be the right thing to do ?
I mean, if I consider the 8-bit value as 2 points in a waveform, then , according to this , the ratio between 2 amplitudes at two instants will not be the same in 8 bit and 16-bit.
Are you trying to scale the values ? In that case , won't a simple multiplier help ?
You must be extremely careful, many audio formats ESPECIALLY 8-bit ones are non linear encoding (i.e. 128 is NOT "halfway" between 0 and 255).
Some of these are even delta calculations.
These operations are done to preserve both dynamic range and resolution within the key frequency domain [the human ear is also non-linear!]
Without knowing the current coding format, and the desiret target format [most 16 bit formats ARE linear, but not all], it is impossible to answer.
I have the conversion functions for most formats if you can provide the needed information. [ One of the perks of having been the lead software designed for Otari's first 100% digital Autio Console :cool: ]
Yeah, probably multiplying by 256 is what you want. The distribution of the values in the domain will remain the same. If you square the values, then smaller values will get suppressed.
Ok, well, bested by that guy above ;)
Yves is correct IF both of the encodings are linear...you might just get lucky! You will know right off the bat if you are wrong [it will sound like nothing you have ever heard!]