So I found some C code to decompress certain PCM samples, and I want to do the same in AS3. I have tried to do so, but it doesn't seem to be working. I know little to no C, although I'm quite fluent in AS3, so I might be translating it incorrectly.
Here is the C code:
BYTE bShift; // shift value
char *inputBuffer[dwSize];
SHORT iCurValue;
DWORD i;
iCurValue=0x0000;
for (i=0;i<dwSize;i++)
{
iCurValue+=(signed short)inputBuffer[i];
Output(iCurValue<<bShift);
}
(Output()
is a placeholder for the action to do on the decompressed sample value.)
Here is a function I made in AS3 which is supposed to do the same thing:
private function pcmDecompress(pcmBytes:ByteArray, shift:int):ByteArray
{
var input:ByteArray = pcmBytes;
var output:ByteArray = new ByteArray();
output.endian = Endian.LITTLE_ENDIAN;
var iCurValue:int = 0x0000;
for (var i:int = 0; i < input.length; i++)
{
iCurValue += input[i];
output.writeShort(iCurValue << shift);
}
return output;
}
Afterwards I encode a WAV file and save it, using output
as the data section containing the samples. The WAV file plays, but all I hear is a lot of static.
Any help would be greatly appreciated.