c# - create AudioClip from byte[] -
i have problem. use sqlite store sounds. sound in byte[]. convert byte[] float[]:
private float[] convertbytetofloat(byte[] array) { float[] floatarr = new float[array.length / 4]; (int = 0; < floatarr.length; i++) { if (bitconverter.islittleendian) array.reverse(array, * 4, 4); floatarr[i] = bitconverter.tosingle(array, * 4); } return floatarr; } float[] f = convertbytetofloat(bytes);
then create audioclip:
audioclip audioclip = audioclip.create("testsound", f.length, 1, 44100, false, false); audioclip.setdata(f, 0);
and play it
audiosource.playclipatpoint(audioclip, new vector3(100, 100, 0), 1.0f);
but result noise :( .
floatarr needs scaled within range of -1.0f 1.0f.
floatarr[i] = bitconverter.tosingle(array, i*4) / 0x80000000;
Comments
Post a Comment