public Error Create(ComputeDevice computeDevice, PropagationSettings simulationSettings, Scene scene, ProbeManager probeManager) { var error = PhononCore.iplCreateEnvironment(Context.GetContext(), computeDevice.GetDevice(), simulationSettings, scene.GetScene(), probeManager.GetProbeManager(), ref environment); if (error != Error.None) { throw new Exception("Unable to create environment [" + error.ToString() + "]"); } return(error); }
public Error Create(ComputeDevice computeDevice, PropagationSettings simulationSettings) { string fileName = SceneFileName(); if (!File.Exists(fileName)) { return(Error.Fail); } var error = PhononCore.iplLoadFinalizedScene(Context.GetContext(), simulationSettings, SceneFileName(), computeDevice.GetDevice(), null, ref scene); return(error); }
public void SetEnvironment(Environment environment, PropagationSettings simulationSettings) { ambisonicsFormat.channelLayoutType = ChannelLayoutType.Ambisonics; ambisonicsFormat.ambisonicsOrder = simulationSettings.ambisonicsOrder; ambisonicsFormat.numSpeakers = (ambisonicsFormat.ambisonicsOrder + 1) * (ambisonicsFormat.ambisonicsOrder + 1); ambisonicsFormat.ambisonicsOrdering = AmbisonicsOrdering.ACN; ambisonicsFormat.ambisonicsNormalization = AmbisonicsNormalization.N3D; ambisonicsFormat.channelOrder = ChannelOrder.Deinterleaved; var error = PhononCore.iplCreateEnvironmentalRenderer(Context.GetContext(), environment.GetEnvironment(), RenderingSettings(), ambisonicsFormat, ref environmentalRenderer); if (error != Error.None) { throw new Exception("Unable to create environment renderer [" + error.ToString() + "]"); } }
public static PropagationSettings SimulationSettings() { SimulationSettings simSetings = PhononSimulationSettings.GetSimulationSettings(); SceneType rayTracer = PhononSettings.GetRayTracerOption(); float simDuration = simSetings.Value.Duration; int simAmbisonicsOrder = simSetings.Value.AmbisonicsOrder; int simMaxSources = simSetings.Value.MaxSources; int simRays = 0; int simSecondaryRays = 0; int simBounces = 0; bool editorInEditMode = false; #if UNITY_EDITOR editorInEditMode = Application.isEditor && !UnityEditor.EditorApplication.isPlayingOrWillChangePlaymode; #endif //When in edit mode use baked settings, when in play mode or standalone application mode use realtime setttings. if (editorInEditMode) { simRays = simSetings.Value.BakeRays; simSecondaryRays = simSetings.Value.BakeSecondaryRays; simBounces = simSetings.Value.BakeBounces; } else { simRays = simSetings.Value.RealtimeRays; simSecondaryRays = simSetings.Value.RealtimeSecondaryRays; simBounces = simSetings.Value.RealtimeBounces; } PropagationSettings simulationSettings = new PropagationSettings { sceneType = rayTracer, rays = simRays, secondaryRays = simSecondaryRays, bounces = simBounces, irDuration = simDuration, ambisonicsOrder = simAmbisonicsOrder, maxConvolutionSources = simMaxSources, }; return(simulationSettings); }
public Error Export(ComputeDevice computeDevice, PropagationSettings simulationSettings) { var error = Error.None; var objects = GameObject.FindObjectsOfType <PhononGeometry>(); simulationSettings.sceneType = SceneType.Phonon; // Scene type should always be Phonon when exporting the scene. error = PhononCore.iplCreateScene(Context.GetContext(), computeDevice.GetDevice(), simulationSettings, objects.Length, ref scene); if (error != Error.None) { throw new Exception("Unable to create scene for export (" + objects.Length.ToString() + " materials): [" + error.ToString() + "]"); } var materials = new Material[objects.Length]; for (var i = 0; i < objects.Length; ++i) { objects[i].GetMaterial(ref materials[i]); PhononCore.iplSetSceneMaterial(scene, i, materials[i]); } var totalNumVertices = 0; var numVertices = new int[objects.Length]; var totalNumTriangles = 0; var numTriangles = new int[objects.Length]; for (var i = 0; i < objects.Length; ++i) { numVertices[i] = objects[i].GetNumVertices(); totalNumVertices += numVertices[i]; numTriangles[i] = objects[i].GetNumTriangles(); totalNumTriangles += numTriangles[i]; } var staticMesh = IntPtr.Zero; error = PhononCore.iplCreateStaticMesh(scene, totalNumVertices, totalNumTriangles, ref staticMesh); if (error != Error.None) { throw new Exception("Unable to create static mesh for export (" + totalNumVertices.ToString() + " vertices, " + totalNumTriangles.ToString() + " triangles): [" + error.ToString() + "]"); } var vertices = new Vector3[totalNumVertices]; var vertexOffset = 0; var triangles = new Triangle[totalNumTriangles]; var triangleOffset = 0; var materialIndices = new int[totalNumTriangles]; for (var i = 0; i < objects.Length; ++i) { objects[i].GetGeometry(vertices, vertexOffset, triangles, triangleOffset); for (var j = 0; j < numTriangles[i]; ++j) { materialIndices[triangleOffset + j] = i; } vertexOffset += numVertices[i]; triangleOffset += numTriangles[i]; } PhononCore.iplSetStaticMeshVertices(scene, staticMesh, vertices); PhononCore.iplSetStaticMeshTriangles(scene, staticMesh, triangles); PhononCore.iplSetStaticMeshMaterials(scene, staticMesh, materialIndices); PhononCore.iplFinalizeScene(scene, null); #if UNITY_EDITOR if (!Directory.Exists(Application.streamingAssetsPath)) { UnityEditor.AssetDatabase.CreateFolder("Assets", "StreamingAssets"); } #endif error = PhononCore.iplSaveFinalizedScene(scene, SceneFileName()); if (error != Error.None) { throw new Exception("Unable to save scene to " + SceneFileName() + " [" + error.ToString() + "]"); } PhononCore.iplDestroyStaticMesh(ref staticMesh); PhononCore.iplDestroyScene(ref scene); Debug.Log("Scene exported to " + SceneFileName() + "."); return(error); }
public static extern Error iplCreateEnvironment(GlobalContext globalContext, IntPtr computeDevice, PropagationSettings simulationSettings, IntPtr scene, IntPtr probeManager, [In, Out] ref IntPtr environment);
public static extern Error iplLoadFinalizedScene(GlobalContext globalContext, PropagationSettings simulationSettings, string fileName, IntPtr computeDevice, LoadSceneProgressCallback progressCallback, [In, Out] ref IntPtr scene);
public static extern Error iplCreateScene(GlobalContext globalContext, IntPtr computeDevice, PropagationSettings simulationSettings, int numMaterials, [In, Out] ref IntPtr scene);
public static extern Error iplCreateSimulationData(PropagationSettings simulationSettings, RenderingSettings renderingSettings, [In, Out] ref IntPtr simulationData);
// // Initializes the listener. // void Start() { audioEngine = AudioEngineComponent.GetAudioEngine(); if (audioEngine == AudioEngine.Unity) { GlobalContext globalContext = PhononSettings.GetGlobalContext(); PropagationSettings simulationSettings = EnvironmentComponent.SimulationSettings(); RenderingSettings renderingSettings = PhononSettings.GetRenderingSettings(); ambisonicsFormat.channelLayoutType = ChannelLayoutType.Ambisonics; ambisonicsFormat.ambisonicsOrder = simulationSettings.ambisonicsOrder; ambisonicsFormat.numSpeakers = (ambisonicsFormat.ambisonicsOrder + 1) * (ambisonicsFormat.ambisonicsOrder + 1); ambisonicsFormat.ambisonicsOrdering = AmbisonicsOrdering.ACN; ambisonicsFormat.ambisonicsNormalization = AmbisonicsNormalization.N3D; ambisonicsFormat.channelOrder = ChannelOrder.Deinterleaved; if (PhononCore.iplCreateBinauralRenderer(globalContext, renderingSettings, null, ref binauralRenderer) != Error.None) { Debug.Log("Unable to create binaural renderer for object: " + gameObject.name + ". Please check the log file for details."); return; } outputFormat = PhononSettings.GetAudioConfiguration(); AudioFormat ambisonicsBinauralFormat = outputFormat; ambisonicsBinauralFormat.channelOrder = ChannelOrder.Deinterleaved; #if !UNITY_ANDROID if (PhononCore.iplCreateAmbisonicsPanningEffect(binauralRenderer, ambisonicsFormat, ambisonicsBinauralFormat, ref propagationPanningEffect) != Error.None) { Debug.Log("Unable to create Ambisonics panning effect for object: " + gameObject.name + ". Please check the log file for details."); return; } if (outputFormat.channelLayout == ChannelLayout.Stereo) { // Create ambisonics based binaural effect for indirect sound if the output format is stereo. if (PhononCore.iplCreateAmbisonicsBinauralEffect(binauralRenderer, ambisonicsFormat, ambisonicsBinauralFormat, ref propagationBinauralEffect) != Error.None) { Debug.Log("Unable to create propagation binaural effect for object: " + gameObject.name + ". Please check the log file for details."); return; } } #endif wetData = new float[renderingSettings.frameSize * outputFormat.numSpeakers]; wetAmbisonicsDataMarshal = new IntPtr[ambisonicsFormat.numSpeakers]; for (int i = 0; i < ambisonicsFormat.numSpeakers; ++i) { wetAmbisonicsDataMarshal[i] = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(float)) * renderingSettings.frameSize); } wetDataMarshal = new IntPtr[outputFormat.numSpeakers]; for (int i = 0; i < outputFormat.numSpeakers; ++i) { wetDataMarshal[i] = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(float)) * renderingSettings.frameSize); } StartCoroutine(EndOfFrameUpdate()); environmentalRendererComponent = FindObjectOfType <EnvironmentalRendererComponent>(); } }
// // Initializes the effect. // void Start() { audioEngine = AudioEngineComponent.GetAudioEngine(); if (audioEngine == AudioEngine.Unity) { // Setup 3D audio and panning effect for direct sound. GlobalContext globalContext = PhononSettings.GetGlobalContext(); RenderingSettings renderingSettings = PhononSettings.GetRenderingSettings(); directAttnInterlop.Init(directAttnInteropFrames); inputFormat = PhononSettings.GetAudioConfiguration(); outputFormat = PhononSettings.GetAudioConfiguration(); if (PhononCore.iplCreateBinauralRenderer(globalContext, renderingSettings, null, ref binauralRenderer) != Error.None) { Debug.Log("Unable to create binaural renderer for object: " + gameObject.name + ". Please check the log file for details."); return; } if (outputFormat.channelLayout == ChannelLayout.Stereo) { // Create object based binaural effect for direct sound if the output format is stereo. if (PhononCore.iplCreateBinauralEffect(binauralRenderer, inputFormat, outputFormat, ref directBinauralEffect) != Error.None) { Debug.Log("Unable to create 3D effect for object: " + gameObject.name + ". Please check the log file for details."); return; } } if (outputFormat.channelLayout == ChannelLayout.Custom) { // Panning effect for direct sound (used for rendering only for custom speaker layout, otherwise use default Unity panning) if (PhononCore.iplCreatePanningEffect(binauralRenderer, inputFormat, outputFormat, ref directCustomPanningEffect) != Error.None) { Debug.Log("Unable to create custom panning effect for object: " + gameObject.name + ". Please check the log file for details."); return; } } PropagationSettings simulationSettings = EnvironmentComponent.SimulationSettings(); ambisonicsFormat.channelLayoutType = ChannelLayoutType.Ambisonics; ambisonicsFormat.ambisonicsOrder = simulationSettings.ambisonicsOrder; ambisonicsFormat.numSpeakers = (ambisonicsFormat.ambisonicsOrder + 1) * (ambisonicsFormat.ambisonicsOrder + 1); ambisonicsFormat.ambisonicsOrdering = AmbisonicsOrdering.ACN; ambisonicsFormat.ambisonicsNormalization = AmbisonicsNormalization.N3D; ambisonicsFormat.channelOrder = ChannelOrder.Deinterleaved; AudioFormat ambisonicsBinauralFormat = outputFormat; ambisonicsBinauralFormat.channelOrder = ChannelOrder.Deinterleaved; #if !UNITY_ANDROID if (PhononCore.iplCreateAmbisonicsPanningEffect(binauralRenderer, ambisonicsFormat, ambisonicsBinauralFormat, ref propagationPanningEffect) != Error.None) { Debug.Log("Unable to create Ambisonics panning effect for object: " + gameObject.name + ". Please check the log file for details."); return; } if (outputFormat.channelLayout == ChannelLayout.Stereo) { // Create ambisonics based binaural effect for indirect sound if the output format is stereo. if (PhononCore.iplCreateAmbisonicsBinauralEffect(binauralRenderer, ambisonicsFormat, ambisonicsBinauralFormat, ref propagationBinauralEffect) != Error.None) { Debug.Log("Unable to create propagation binaural effect for object: " + gameObject.name + ". Please check the log file for details."); return; } } #endif wetData = new float[renderingSettings.frameSize * outputFormat.numSpeakers]; wetAmbisonicsDataMarshal = new IntPtr[ambisonicsFormat.numSpeakers]; for (int i = 0; i < ambisonicsFormat.numSpeakers; ++i) { wetAmbisonicsDataMarshal[i] = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(float)) * renderingSettings.frameSize); } wetDataMarshal = new IntPtr[outputFormat.numSpeakers]; for (int i = 0; i < outputFormat.numSpeakers; ++i) { wetDataMarshal[i] = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(float)) * renderingSettings.frameSize); } listener = FindObjectOfType <AudioListener>(); phononMixer = FindObjectOfType <PhononMixer>(); StartCoroutine(EndOfFrameUpdate()); environmentalRenderer = FindObjectOfType <EnvironmentalRendererComponent>(); environment = FindObjectOfType <EnvironmentComponent>(); if ((environmentalRenderer == null || environment == null) && (enableReflections || directOcclusionOption != OcclusionOption.None)) { Debug.LogError("Environment and Environmental Renderer component must be attached when reflections are enabled or direct occlusion is set to Raycast or Partial."); } } }