/// <summary> /// 変換テスト /// </summary> private void ConvertTest() { if (!convertTestFlg) { return; } float[] x1 = new float[] { 1, 2, 3, 4, 5 }; float[] x2 = new float[] { 6, 5, 3, 2, 1 }; float[] impulseX = new float[] { 0.1f, 0.2f, 0.3f, 0.4f }; float[] ret; debugButton.AddButton("ConvertTest", () => { var v = new OverlapAdd(Constant.CreateTest()); v.SetImpulseResponse(impulseX); //v.SetIdentifyImpulseResponse(); v.Convolution(x1); ret = v.GetConvolution(); Debug.Log($"x1 convolution ================================="); for (int i = 0; i < ret.Length; ++i) { Debug.Log($"[{i}]:{ret[i]:0.00}"); } v.Convolution(x2); ret = v.GetConvolution(); Debug.Log($"x2 convolution ================================="); for (int i = 0; i < ret.Length; ++i) { Debug.Log($"[{i}]:{ret[i]:0.00}"); } Debug.Log($"overlap ================================="); var overlap = v.GetOverlap(); for (int i = 0; i < overlap.Length; ++i) { Debug.Log($"[{i}]:{overlap[i]:0.00}"); } }); }
/// <summary> /// 角度に対応するサウンドデータ取得 /// WebGLでない場合はサブスレッドから実行される /// </summary> public void GetBlockBuffer(int angle, int sampleoffset, AudioClipStreamingPlayer.BlockBuffer buffer) { if (angle >= 0) { ImpulseResponses.Data data; data = ImpulseResponses.GetTransformedImpulseResponse(angle); overlapAddLeft.SetTransformedImpulseResponse(data.channelLX, data.channelLY); overlapAddRight.SetTransformedImpulseResponse(data.channelRX, data.channelRY); } else { overlapAddLeft.SetIdentifyImpulseResponse(); overlapAddRight.SetIdentifyImpulseResponse(); } waveAudioClip.GetData(bufferSample, sampleoffset, c.blockSamples); overlapAddLeft.Convolution(bufferSample); overlapAddRight.Convolution(bufferSample); float[] ret_l = overlapAddLeft.GetConvolution(); float[] ret_r = overlapAddRight.GetConvolution(); Buffer.BlockCopy(ret_l, 0, buffer.left, 0, c.blockSamples * SizeofFloat); Buffer.BlockCopy(ret_r, 0, buffer.right, 0, c.blockSamples * SizeofFloat); }