//
        // Draws the inspector.
        //
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            PhononGUI.SectionHeader("Quality Preset");
            EditorGUILayout.PropertyField(serializedObject.FindProperty("Preset"));

            if (serializedObject.FindProperty("Preset").enumValueIndex < 3)
            {
                SimulationSettingsValue actualValue = ((SimulationSettings)target).Value;
                actualValue.CopyFrom(SimulationSettingsPresetList.PresetValue(serializedObject.FindProperty("Preset").enumValueIndex));
            }
            else
            {
                EditorGUILayout.PropertyField(serializedObject.FindProperty("Value"));

                if (Application.isEditor && EditorApplication.isPlayingOrWillChangePlaymode)
                {
                    SimulationSettingsValue actualValue = ((SimulationSettings)target).Value;
                    EnvironmentComponent    editorRuntimeEnvComponent = FindObjectOfType <EnvironmentComponent>();
                    if (editorRuntimeEnvComponent != null)
                    {
                        IntPtr environment = editorRuntimeEnvComponent.Environment().GetEnvironment();
                        PhononCore.iplSetNumBounces(environment, actualValue.RealtimeBounces);
                    }
                }
            }

            EditorGUILayout.Space();
            serializedObject.ApplyModifiedProperties();
        }
        public static void DrawPane()
        {
            if (targetObject == null || editor == null)
            {
                targetObject = PhononMaterialSettings.GetObject();
                editor       = Editor.CreateEditor(targetObject.GetComponent <PhononMaterial>());
            }

            editor.OnInspectorGUI();

            PhononGUI.SectionHeader("Export Phonon Geometry");
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.PrefixLabel(" ");

            if (GUILayout.Button("Export to OBJ"))
            {
                EnvironmentComponent.DumpScene();
            }

            if (GUILayout.Button("Pre-Export Scene"))
            {
                EnvironmentComponent.ExportScene();
            }

            EditorGUILayout.EndHorizontal();
        }
Exemple #3
0
        //
        // 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>();
            }
        }
Exemple #4
0
        //
        // 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.");
                }
            }
        }