예제 #1
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;
                }
            }
        }