I have a 'huge' amount of data, which may vary between 50 and 100 MegaBytes. I read this data in as an array of bytes using a filestreamer.
The thing is, I want to convert all consecutive 2 bytes into an integer. The way I do this is I loop through the array of bytes with a stepsize of two, and then use BitConvert to do the conversion:
_data[i] = BitConverter.ToInt16(soundData[i : i + 2], 0) // Convert 2 bytes into an int and store at i
So each two bytes get turned into an Int16. The problem however, is that this is too slow, as for a file of about 50 megabytes this can take up 20 seconds!
Is there a generic way of doing this instantly, instead of calling this function on each 2 bytes of my data array such that it isn't that slow? Preferably in a 'safe' way, so no unsafe code.