相关疑难解决方法(0)

从byte []创建AudioClip

我有问题.我使用sqlite来存储声音.我在byte []中得到声音.然后将byte []转换为float []:

            private float[] ConvertByteToFloat(byte[] array) 
            {
                float[] floatArr = new float[array.Length / 4];
                for (int i = 0; i < floatArr.Length; i++) 
                {
                    if (BitConverter.IsLittleEndian) 
                        Array.Reverse(array, i * 4, 4);
                    floatArr[i] = BitConverter.ToSingle(array, i * 4);
                }
                return floatArr;
            } 


            float[] f = ConvertByteToFloat(bytes);
Run Code Online (Sandbox Code Playgroud)

然后创建AudioClip:

    AudioClip audioClip = AudioClip.Create("testSound", f.Length, 1, 44100, false, false);
    audioClip.SetData(f, 0);
Run Code Online (Sandbox Code Playgroud)

然后玩吧

AudioSource.PlayClipAtPoint(audioClip, new Vector3(100, 100, 0), 1.0f);
Run Code Online (Sandbox Code Playgroud)

但结果是噪音:(.

c# arrays endianness unity-game-engine

10
推荐指数
1
解决办法
9907
查看次数

标签 统计

arrays ×1

c# ×1

endianness ×1

unity-game-engine ×1