联合音频

Babybus-u3d技术交流-联合音频

联合音频

联合音频_第1张图片
1.png

联合的音频Load type需要正确设置,否则联合的结果是有问题的。

public static AudioClip Combine(params AudioClip[] clips)

    {

        if (clips == null || clips.Length == 0)

            return null;

 
        int length = 0;

        for (int i = 0; i < clips.Length; i++)

        {

            if (clips[i] == null)

                continue;

 
            length += clips[i].samples * clips[i].channels;

        }

 
        float[] data = new float[length];

        length = 0;

        for (int i = 0; i < clips.Length; i++)

        {

            if (clips[i] == null)

                continue;

 
            float[] buffer = new float[clips[i].samples * clips[i].channels];

            clips[i].GetData(buffer, 0);

            //System.Buffer.BlockCopy(buffer, 0, data, length, buffer.Length);

            buffer.CopyTo(data, length);

            length += buffer.Length;

        }

 
        if (length == 0)

            return null;

 
        AudioClip result = AudioClip.Create("Combine", length / 2, 2, 44100, false, 
false);

        result.SetData(data, 0);

 
        return result;

    }

你可能感兴趣的:(联合音频)