Apr 20, 2010 at 1:49 PM
Edited Apr 20, 2010 at 1:54 PM
Sorry about the late answer, been really busy.
This is not my code and I do not think it is correct.
It grabs 4 bytes and turns those into a float. To my knowledge a single byte value represents one sample. So in effect there is resampling going on here (divided by 4), not to mention the actual value you end up with is bogus.
I would do something like this (assuming the max byte sample value can be 255):
for (int nIn = 0; nIn < nSamplesIn; nIn += 2)
rightChannel[nOut] = ((float)SampleBuffer[nIn] / 128.0) - 1.0;
leftChannel[nOut] = ((float)SampleBuffer[nIn + 1] / 128.0) - 1.0;
Disclaimer: have not compiled the code ;-)
The typical range for a VST audio channel sample value lies between -1.0 and +1.0. So that is a range of 2.0 over the zero-axis. To create a value of max 2.0 from a byte (with max 255) I divide by 128 (perhaps 127.5 would be more correct ;-). This will get
you values of min 0.0 and max 2.0. Now shift the value down by 1.0 to get to the -1.0 ans +1.0.
Is it less confusing now? ;-)
Hope it helps.