Example #1
0
        internal static AudioListenerExtension AddSpatializerExtension(AudioListener listener)
        {
            AudioListenerExtension result;

            if (listener.spatializerExtension != null)
            {
                result = listener.spatializerExtension;
            }
            else
            {
                AudioExtensionManager.RegisterBuiltinDefinitions();
                foreach (AudioSpatializerExtensionDefinition audioSpatializerExtensionDefinition in AudioExtensionManager.m_ListenerSpatializerExtensionDefinitions)
                {
                    if (AudioSettings.GetSpatializerPluginName() == audioSpatializerExtensionDefinition.spatializerName || AudioSettings.GetAmbisonicDecoderPluginName() == audioSpatializerExtensionDefinition.spatializerName)
                    {
                        AudioListenerExtension audioListenerExtension = listener.AddExtension(audioSpatializerExtensionDefinition.definition.GetExtensionType());
                        if (audioListenerExtension != null)
                        {
                            audioListenerExtension.audioListener = listener;
                            listener.spatializerExtension        = audioListenerExtension;
                            AudioExtensionManager.WriteExtensionProperties(audioListenerExtension, audioSpatializerExtensionDefinition.definition.GetExtensionType().Name);
                            return(audioListenerExtension);
                        }
                    }
                }
                result = null;
            }
            return(result);
        }
Example #2
0
        internal static void Update()
        {
            AudioExtensionManager.RegisterBuiltinDefinitions();
            AudioListener audioListener = AudioExtensionManager.GetAudioListener() as AudioListener;

            if (audioListener != null)
            {
                AudioListenerExtension audioListenerExtension = AudioExtensionManager.AddSpatializerExtension(audioListener);
                if (audioListenerExtension != null)
                {
                    audioListenerExtension.ExtensionUpdate();
                }
            }
            for (int i = 0; i < AudioExtensionManager.m_SourceExtensionsToUpdate.Count; i++)
            {
                AudioExtensionManager.m_SourceExtensionsToUpdate[i].ExtensionUpdate();
            }
            AudioExtensionManager.m_NextStopIndex = ((AudioExtensionManager.m_NextStopIndex < AudioExtensionManager.m_SourceExtensionsToUpdate.Count) ? AudioExtensionManager.m_NextStopIndex : 0);
            int num = (AudioExtensionManager.m_SourceExtensionsToUpdate.Count <= 0) ? 0 : (1 + AudioExtensionManager.m_SourceExtensionsToUpdate.Count / 8);

            for (int j = 0; j < num; j++)
            {
                AudioSourceExtension audioSourceExtension = AudioExtensionManager.m_SourceExtensionsToUpdate[AudioExtensionManager.m_NextStopIndex];
                if (audioSourceExtension.audioSource == null || !audioSourceExtension.audioSource.enabled || !audioSourceExtension.audioSource.isPlaying)
                {
                    audioSourceExtension.Stop();
                    AudioExtensionManager.RemoveExtensionFromManager(audioSourceExtension);
                }
                else
                {
                    AudioExtensionManager.m_NextStopIndex++;
                    AudioExtensionManager.m_NextStopIndex = ((AudioExtensionManager.m_NextStopIndex < AudioExtensionManager.m_SourceExtensionsToUpdate.Count) ? AudioExtensionManager.m_NextStopIndex : 0);
                }
            }
        }
Example #3
0
        // Check to see if we need to add a spatializer extension to the audio listener.
        static internal AudioListenerExtension AddSpatializerExtension(AudioListener listener)
        {
            if (listener.spatializerExtension != null)
            {
                return(listener.spatializerExtension);
            }

            RegisterBuiltinDefinitions();

            foreach (AudioSpatializerExtensionDefinition extensionDefinition in m_ListenerSpatializerExtensionDefinitions)
            {
                if ((AudioSettings.GetSpatializerPluginName() == extensionDefinition.spatializerName) ||
                    (AudioSettings.GetAmbisonicDecoderPluginName() == extensionDefinition.spatializerName))
                {
                    AudioListenerExtension newExtension = listener.AddExtension(extensionDefinition.definition.GetExtensionType());
                    if (newExtension != null)
                    {
                        newExtension.audioListener    = listener;
                        listener.spatializerExtension = newExtension;

                        WriteExtensionProperties(newExtension, extensionDefinition.definition.GetExtensionType().Name);
                        return(newExtension);
                    }
                }
            }

            return(null);
        }
Example #4
0
 internal AudioListenerExtension AddExtension(Type extensionType)
 {
     if (this.spatializerExtension == null)
     {
         this.spatializerExtension = (ScriptableObject.CreateInstance(extensionType) as AudioListenerExtension);
     }
     return(this.spatializerExtension);
 }
Example #5
0
 internal static void WriteExtensionProperties(AudioListenerExtension extension, string extensionName)
 {
     if (AudioExtensionManager.m_ListenerSpatializerExtensionName == 0)
     {
         AudioExtensionManager.m_ListenerSpatializerExtensionName = extensionName;
     }
     for (int i = 0; i < extension.audioListener.GetNumExtensionProperties(); i++)
     {
         if (extension.audioListener.ReadExtensionName(i) == AudioExtensionManager.m_ListenerSpatializerExtensionName)
         {
             PropertyName propertyName  = extension.audioListener.ReadExtensionPropertyName(i);
             float        propertyValue = extension.audioListener.ReadExtensionPropertyValue(i);
             extension.WriteExtensionProperty(propertyName, propertyValue);
         }
     }
 }
Example #6
0
        static internal void WriteExtensionProperties(AudioListenerExtension extension, string extensionName)
        {
            if (m_ListenerSpatializerExtensionName == 0)
            {
                m_ListenerSpatializerExtensionName = extensionName;
            }

            for (int listenerIndex = 0; listenerIndex < extension.audioListener.GetNumExtensionProperties(); listenerIndex++)
            {
                if (extension.audioListener.ReadExtensionName(listenerIndex) == m_ListenerSpatializerExtensionName)
                {
                    PropertyName propertyName  = extension.audioListener.ReadExtensionPropertyName(listenerIndex);
                    float        propertyValue = extension.audioListener.ReadExtensionPropertyValue(listenerIndex);

                    extension.WriteExtensionProperty(propertyName, propertyValue);
                }
            }
        }
Example #7
0
        // This manager Update function calls ExtensionUpdate for all extensions on playing audio sources. It also goes through part of the list of
        // extensions to determine which ones have stopped and should be removed. The stop check is fairly expensive, so we handle it separately and lazily to
        // help keep ExtensionUpdate very cheap. Each extension's OnDestroy function is a fail-safe and will remove the extension from the manager's list so
        // we are never handling destroyed extensions here.
        static internal void Update()
        {
            RegisterBuiltinDefinitions();


            AudioListener listener = GetAudioListener() as AudioListener;

            if (listener != null)
            {
                AudioListenerExtension extension = AddSpatializerExtension(listener);
                if (extension != null)
                {
                    extension.ExtensionUpdate();
                }
            }

            for (int i = 0; i < m_SourceExtensionsToUpdate.Count; i++)
            {
                m_SourceExtensionsToUpdate[i].ExtensionUpdate();
            }

            m_NextStopIndex = (m_NextStopIndex >= m_SourceExtensionsToUpdate.Count) ? 0 : m_NextStopIndex;

            // Perform stop checks on roughly 1/8th of the list of playing audio source extensions. We're using that equation instead of a fixed maximum like 10 so
            // that we don't get into a situation where the game is playing more sounds every frame than we are stop-checking.
            int numStopChecks = (m_SourceExtensionsToUpdate.Count > 0) ? 1 + (m_SourceExtensionsToUpdate.Count / 8) : 0;

            for (int i = 0; i < numStopChecks; i++)
            {
                AudioSourceExtension extension = m_SourceExtensionsToUpdate[m_NextStopIndex];
                if ((extension.audioSource == null) || !extension.audioSource.enabled || !extension.audioSource.isPlaying)
                {
                    extension.Stop();
                    RemoveExtensionFromManager(extension);
                }
                else
                {
                    m_NextStopIndex++;
                    m_NextStopIndex = (m_NextStopIndex >= m_SourceExtensionsToUpdate.Count) ? 0 : m_NextStopIndex;
                }
            }
        }