jcl, on Jun 5 2007, 05:58 AM, said:
iccaros, on Jun 4 2007, 01:27 PM, said:
or would this do the same
Convert.ToSByte() returns a signed byte based on the value of the argument, so no.
Do you really need 16-bit floats? Would, say, a 16-bit fixed-point (e.g., eight bit whole part, eight bit fraction, no exponent) type be adequate? And if you do need floats, do you really want want truncated IEEE singles? And is there any reason to roll your own compression instead of using one of the bazillion free audio codecs?
I am not really trying to create my own, the Navy does this with Time series data (Sonar), and I was given the C code above as an example , but I do not under stand it, it looks like it returns the first 16 most significant bits of a float as a signed short. I guess that when audio is recorded from an hydrophone it is doen at 32 bits and put in to a byte array looking like this.. 00100111011100101010001111110111, and to save broad cast(using HF so very limited bandwidth) space they chop off the last 16 bits and add them back with zeros for play back. so that is what I really need to do, I could change the whole number to a byte array and then fill a 16 bit array with the firt 16 bits and ignore the rest
do something like
byte[] truncate (float f)
{
byte[] output = new byte[16];
byte[] temp = BitConverter.GetBytes( f );
for (int x = 0; x < 16; x++)
{
output[x] = temp[x];
}
return output;
}
In real life this will already be done for me by real equipment and I just add zeros, but for testing I will not have real data and I need to make sure I can create data that will look as close as I can.
Does this sound like it would do the same as the C++ example, or am I way off?
Thanks..