Skip to content

Instantly share code, notes, and snippets.

@alekseytimoshchenko
Created December 2, 2020 07:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alekseytimoshchenko/1cebccf6b0f54bde56dde2df36821c9c to your computer and use it in GitHub Desktop.
Save alekseytimoshchenko/1cebccf6b0f54bde56dde2df36821c9c to your computer and use it in GitHub Desktop.
public static float[] Convert16BitByteArrayToAudioClipData(byte[] source)
{
int x = sizeof(Int16);
int convertedSize = source.Length / x;
float[] data = new float[convertedSize];
Int16 maxValue = Int16.MaxValue;
for (int i = 0; i < convertedSize; i++)
{
int offset = i * x;
data[i] = (float)BitConverter.ToInt16(source, offset) / maxValue;
++i;
}
return data;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment