예제 #1
0
        // Initializes Phonon Manager Component, in particular various Phonon API handles contained within Phonon
        // Manager Container. Initialize will be performed only once despite repeated calls to Initialize without
        // calls to Destroy.
        public void Initialize(bool initializeRenderer, PhononManager phononManager)
        {
            if (refCounter++ != 0)
            {
                return;
            }

            bool useOpenCL;
            int  numComputeUnits;
            ComputeDeviceType deviceType;

            deviceType = phononManager.ComputeDeviceSettings(out numComputeUnits, out useOpenCL);
            if (!initializeRenderer)
            {
                useOpenCL = false;
            }

            SimulationSettings simulationSettings = phononManager.SimulationSettings();
            GlobalContext      globalContext      = phononManager.GlobalContext();
            RenderingSettings  renderingSettings  = phononManager.RenderingSettings();

            try
            {
                computeDevice.Create(globalContext, useOpenCL, deviceType, numComputeUnits);
            }
            catch (Exception e)
            {
                throw e;
            }

            probeManager.Create();
            scene.Create(computeDevice, simulationSettings, globalContext);

            try
            {
                environment.Create(computeDevice, simulationSettings, scene, probeManager, globalContext);
            }
            catch (Exception e)
            {
                throw e;
            }

            if (initializeRenderer)
            {
                environmentRenderer.Create(environment, renderingSettings, simulationSettings, globalContext);
                binauralRenderer.Create(environment, renderingSettings, globalContext);
            }
        }
예제 #2
0
        public void Create(Environment environment, RenderingSettings renderingSettings, SimulationSettings simulationSettings, GlobalContext globalContext)
        {
            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(globalContext, environment.GetEnvironment(),
                                                                  renderingSettings, ambisonicsFormat, ref environmentalRenderer);

            if (error != Error.None)
            {
                throw new Exception("Unable to create environment renderer [" + error.ToString() + "]");
            }
        }
예제 #3
0
        public void Create(Environment environment, RenderingSettings renderingSettings, GlobalContext globalContext)
        {
            HRTFParams hrtfParams = new HRTFParams
            {
                type           = HRTFDatabaseType.Default,
                hrtfData       = IntPtr.Zero,
                numHrirSamples = 0,
                loadCallback   = null,
                unloadCallback = null,
                lookupCallback = null
            };

            var error = PhononCore.iplCreateBinauralRenderer(globalContext, renderingSettings, hrtfParams, ref binauralRenderer);

            if (error != Error.None)
            {
                throw new Exception("Unable to create binaural renderer [" + error.ToString() + "]");
            }
        }
예제 #4
0
        // Initializes various Phonon API objects in a lazy fashion.
        // Safe to call this every frame.
        public void LazyInitialize(BinauralRenderer binauralRenderer, bool directBinauralEnabled,
                                   RenderingSettings renderingSettings, EnvironmentalRenderer environmentalRenderer)
        {
            if (directBinauralEffect == IntPtr.Zero && outputFormat.channelLayout == ChannelLayout.Stereo &&
                directBinauralEnabled && binauralRenderer.GetBinauralRenderer() != IntPtr.Zero)
            {
                // Create object based binaural effect for direct sound if the output format is stereo.
                if (PhononCore.iplCreateBinauralEffect(binauralRenderer.GetBinauralRenderer(), outputFormat,
                                                       outputFormat, ref directBinauralEffect) != Error.None)
                {
                    Debug.Log("Unable to create binaural effect. Please check the log file for details.");
                    return;
                }
            }

            if (directSoundEffect == IntPtr.Zero && environmentalRenderer.GetEnvironmentalRenderer() != IntPtr.Zero)
            {
                if (PhononCore.iplCreateDirectSoundEffect(environmentalRenderer.GetEnvironmentalRenderer(), inputFormat,
                                                          outputFormat, ref directSoundEffect) != Error.None)
                {
                    Debug.Log("Unable to create direct sound effect. Please check the log file for details.");
                    return;
                }
            }

            if (directCustomPanningEffect == IntPtr.Zero && outputFormat.channelLayout == ChannelLayout.Custom &&
                !directBinauralEnabled && binauralRenderer.GetBinauralRenderer() != IntPtr.Zero)
            {
                // Panning effect for direct sound (used for rendering only for custom speaker layout,
                // otherwise use default Unity panning)
                if (PhononCore.iplCreatePanningEffect(binauralRenderer.GetBinauralRenderer(), outputFormat,
                                                      outputFormat, ref directCustomPanningEffect) != Error.None)
                {
                    Debug.Log("Unable to create custom panning effect. Please check the log file for details.");
                    return;
                }
            }
        }
예제 #5
0
 public static extern Error iplCreateSimulationData(SimulationSettings simulationSettings, RenderingSettings renderingSettings, [In, Out] ref IntPtr simulationData);
예제 #6
0
 public static extern Error iplCreateEnvironmentalRenderer(GlobalContext globalContext, IntPtr environment, RenderingSettings renderingSettings, AudioFormat outputFormat, [In, Out] ref IntPtr renderer);
예제 #7
0
 public static extern Error iplCreateBinauralRenderer(GlobalContext globalContext, RenderingSettings renderingSettings, Byte[] hrtfData, [In, Out] ref IntPtr renderer);
예제 #8
0
        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
        }
예제 #9
0
 public static extern Error iplCreateBinauralRenderer(GlobalContext globalContext, RenderingSettings renderingSettings, HRTFParams hrtfParams, [In, Out] ref IntPtr renderer);
예제 #10
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>();
            }
        }
예제 #11
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.");
                }
            }
        }