public void LazyInitialize(BinauralRenderer binauralRenderer, bool reflectionEnabled, bool indirectBinauralEnabled, RenderingSettings renderingSettings, bool sourceUpdate, SourceSimulationType sourceSimulationType, string uniqueIdentifier, PhononStaticListener phononStaticListener, ReverbSimulationType reverbSimualtionType, EnvironmentalRenderer environmentalRenderer) { #if !UNITY_ANDROID AudioFormat ambisonicsBinauralFormat = outputFormat; ambisonicsBinauralFormat.channelOrder = ChannelOrder.Deinterleaved; // Set up propagationPanningEffect if (reflectionEnabled && propagationPanningEffect == IntPtr.Zero && binauralRenderer.GetBinauralRenderer() != IntPtr.Zero) { if (PhononCore.iplCreateAmbisonicsPanningEffect(binauralRenderer.GetBinauralRenderer(), ambisonicsFormat, ambisonicsBinauralFormat, ref propagationPanningEffect) != Error.None) { Debug.Log("Unable to create Ambisonics panning effect. Please check the log file for details."); return; } } // Set up propagationBinauralEffect if (outputFormat.channelLayout == ChannelLayout.Stereo && reflectionEnabled && indirectBinauralEnabled && propagationBinauralEffect == IntPtr.Zero && binauralRenderer.GetBinauralRenderer() != IntPtr.Zero) { // Create ambisonics based binaural effect for indirect sound if the output format is stereo. if (PhononCore.iplCreateAmbisonicsBinauralEffect(binauralRenderer.GetBinauralRenderer(), ambisonicsFormat, ambisonicsBinauralFormat, ref propagationBinauralEffect) != Error.None) { Debug.Log("Unable to create propagation binaural effect. Please check the log file for details."); return; } } // Set up propagationAmbisonicsEffect if (reflectionEnabled && propagationAmbisonicsEffect == IntPtr.Zero && environmentalRenderer.GetEnvironmentalRenderer() != IntPtr.Zero) { string effectName = ""; if (sourceUpdate && sourceSimulationType == SourceSimulationType.BakedStaticSource) { effectName = uniqueIdentifier; } else if (sourceUpdate && sourceSimulationType == SourceSimulationType.BakedStaticListener) { if (phononStaticListener == null) { Debug.LogError("No Phonon Static Listener component found."); } else if (phononStaticListener.currentStaticListenerNode == null) { Debug.LogError("Current static listener node is not specified in Phonon Static Listener."); } else { effectName = phononStaticListener.currentStaticListenerNode.GetUniqueIdentifier(); } } else if (!sourceUpdate && reverbSimualtionType == ReverbSimulationType.BakedReverb) { effectName = "__reverb__"; } SimulationType simulationMode; if (sourceUpdate) { simulationMode = (sourceSimulationType == SourceSimulationType.Realtime) ? SimulationType.Realtime : SimulationType.Baked; } else { simulationMode = (reverbSimualtionType == ReverbSimulationType.RealtimeReverb) ? SimulationType.Realtime : SimulationType.Baked; } if (PhononCore.iplCreateConvolutionEffect(environmentalRenderer.GetEnvironmentalRenderer(), Common.ConvertString(effectName), simulationMode, inputFormat, ambisonicsFormat, ref propagationAmbisonicsEffect) != Error.None) { Debug.LogError("Unable to create propagation effect for object"); } } if (reflectionEnabled && wetData == null) { wetData = new float[renderingSettings.frameSize * outputFormat.numSpeakers]; } if (reflectionEnabled && wetAmbisonicsDataMarshal == null) { wetAmbisonicsDataMarshal = new IntPtr[ambisonicsFormat.numSpeakers]; for (int i = 0; i < ambisonicsFormat.numSpeakers; ++i) { wetAmbisonicsDataMarshal[i] = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(float)) * renderingSettings.frameSize); } } if (reflectionEnabled && wetDataMarshal == null) { wetDataMarshal = new IntPtr[outputFormat.numSpeakers]; for (int i = 0; i < outputFormat.numSpeakers; ++i) { wetDataMarshal[i] = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(float)) * renderingSettings.frameSize); } } #endif }
// // Courutine to update source and listener position and orientation at frame end. // Done this way to ensure correct update in VR setup. // private IEnumerator EndOfFrameUpdate() { while (true) { if (!initialized && propagationAmbisonicsEffect == IntPtr.Zero && environmentalRenderer != null && environmentalRenderer.GetEnvironmentalRenderer() != IntPtr.Zero && environment != null && environment.Environment().GetEnvironment() != IntPtr.Zero) { // Check for Baked Source or Baked Reverb component. string effectName = ""; if (simulationMode == SimulationType.Baked) { BakedSource bakedSource = GetComponent <BakedSource>(); BakedReverb bakedReverb = GetComponent <BakedReverb>(); if (bakedSource != null) { if (bakedSource.useBakedStaticListener) { effectName = "__staticlistener__" + bakedSource.bakedListenerIdentifier; } else { effectName = bakedSource.uniqueIdentifier; } } if (bakedReverb != null) { effectName = "__reverb__"; } } #if !UNITY_ANDROID if (PhononCore.iplCreateConvolutionEffect(environmentalRenderer.GetEnvironmentalRenderer(), effectName, simulationMode, inputFormat, ambisonicsFormat, ref propagationAmbisonicsEffect) != Error.None) { Debug.LogError("Unable to create propagation effect for object: " + gameObject.name); } #endif initialized = true; } if (!errorLogged && environment != null && environment.Scene().GetScene() == IntPtr.Zero && ((directOcclusionOption != OcclusionOption.None) || enableReflections)) { Debug.LogError("Scene not found. Make sure to pre-export the scene."); errorLogged = true; } if (!initialized && (directOcclusionOption == OcclusionOption.None) && !enableReflections) { initialized = true; } UpdateRelativeDirection(); if (phononMixer && phononMixer.enabled) { fourierMixingEnabled = true; } else { fourierMixingEnabled = false; } yield return(new WaitForEndOfFrame()); // Must yield after updating the relative direction. } }