前提・実現したいこと
Unityでfloat型の配列から音を再生したいです。
音源はwaveファイルを使用していて,フィルタにかけた後の音の再生方法が検索しても出なかったので教えて頂きたいです。
該当のソースコード
C#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4using System.IO; 5using System; 6using System.Linq; 7 8public class Convolution4 : MonoBehaviour 9{ 10 public AudioClip audioclip; 11 public float[] music_data; 12 private float[] data; 13 14 15 public AudioClip hrtf_l_5; 16 public AudioClip hrtf_r_5; 17 public float[] hrtf_Ldata_5; 18 public float[] hrtf_Rdata_5; 19 public float[] hrtf_data_5L; 20 public float[] hrtf_data_5R; 21 22 public float[] ans_l; 23 public float[] ans_r; 24 public float[] memory_l; 25 public float[] memory_r; 26 // Start is called before the first frame update 27 void Start() 28 { 29 data = new float[audioclip.samples * audioclip.channels]; 30 31 audioclip.GetData(data, 0); 32 // Debug.Log(audioclip.samples); 33 34 music_data = new float[data.Length]; 35 Array.Copy(data, 0, music_data, 0, data.Length); 36 37 38 // Quaternion Theta = UnityEngine.XR.InputTracking.GetLocalRotation(UnityEngine.XR.XRNode.Head); 39 // float Theta_s = 0; 40 // float Theta_h = Theta.eulerAngles.y; 41 float Theta_d = 100; //Theta_h - Theta_s; 42 43 int n; 44 // int nn; 45 int m; 46 //int mm; 47 48 hrtf_Ldata_5 = new float[hrtf_l_5.samples * hrtf_l_5.channels]; 49 50 hrtf_l_5.GetData(hrtf_Ldata_5, 0); 51 // Debug.Log(audioclip.samples); 52 /* 53 for (int b = 0; b < hrtf_Ldata_5.Length; b++) 54 { 55 Debug.Log(hrtf_Ldata_5[b]); 56 } 57 */ 58 hrtf_data_5L = new float[hrtf_Ldata_5.Length]; 59 Array.Copy(hrtf_Ldata_5, 0, hrtf_data_5L, 0, hrtf_Ldata_5.Length); 60 61 62 63 if (0 <= Theta_d && Theta_d < 5) 64 { 65 66 for (n = 0; n < music_data.Length - 1; ++n) 67 { 68 // long ans_l =0; 69 70 for (m = 0; m <= hrtf_data_5L.Length - 1; ++m) 71 { 72 if (n - m >= 0) 73 { 74 // Debug.Log(ans_l); 75 ans_l[n] += hrtf_data_5L[m] * music_data[n - m]; 76 // Debug.Log(ans_l[n]); 77 } 78 } 79 } 80 } 81 82 } 83 84 // Update is called once per frame 85 void Update() 86 { 87 88 } 89 90} 91 92
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。