Esempio n. 1
0
        internal AudioListener()
        {
            Matrix3x4 matrix3x4 = Matrix3x4.Identity;
            AudioObjectTransformation audioObjectTransformation = new AudioObjectTransformation(matrix3x4);

            _cPtr = new System.Runtime.InteropServices.HandleRef(this, NativeAudioSystem.CreateAudioListener(audioObjectTransformation.NativePtr));
        }
Esempio n. 2
0
 /// <summary>
 /// Applies the transformation to any audio.
 /// </summary>
 /// <param name="matrix3x4"></param>
 public void SetTransformation(Matrix3x4 matrix3x4)
 {
     using (AudioObjectTransformation audioObjectTransformation = new AudioObjectTransformation(matrix3x4))             // can safely dispose this as the C++ implementation uses a copy
     {
         NativeAudioSystem.SetAudioListenerTransformation(_cPtr.Handle, audioObjectTransformation.NativePtr);
     }
 }
        private void Dispose(bool isDisposing)
        {
            if (_isDisposed)
            {
                return;
            }

            if (isDisposing)
            {
                _info.Dispose();
                _info = null;
                _requestListenersDelegates.Clear();
                _requestListenersDelegates = null;
                _indexTriggerIdToName.Clear();
                _indexTriggerIdToName = null;
                _triggerByName.Clear();
                _triggerByName = null;
            }

            //remove listener from c++
            IntPtr fnPtr = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate(_requestListener);

            NativeAudioSystem.RemoveAudioRequestListener(fnPtr);
            _requestListener = null;

            _isDisposed = true;
        }
Esempio n. 4
0
 /// <summary>
 /// Executes the specified trigger id on this audio object
 /// </summary>
 /// <param name="triggerId"></param>
 public void Play(AudioTriggerId triggerId)
 {
     if (triggerId.IsValid)
     {
         NativeAudioSystem.ExecuteAudioObjectTrigger(_cPtr.Handle, triggerId._id, false);
     }
 }
Esempio n. 5
0
 /// <summary>
 /// Stops the specified trigger id on this audio object
 /// </summary>
 /// <param name="triggerId"></param>
 public void Stop(AudioTriggerId triggerId)
 {
     if (triggerId.IsValid)
     {
         NativeAudioSystem.StopAudioObjectTrigger(_cPtr.Handle, triggerId._id, false);
     }
 }
Esempio n. 6
0
        private static void AddListener()
        {
            // Bind listener to c++
            _requestListener = OnAudioEvent;
            IntPtr fnPtr = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate(_requestListener);

            NativeAudioSystem.AddAudioRequestListener(fnPtr);
        }
Esempio n. 7
0
 /// <summary>
 /// Plays the audio specified by the trigger id. Returns true if the trigger id is valid
 /// </summary>
 /// <param name="triggerId"></param>
 /// <returns></returns>
 public static bool Play(AudioTriggerId triggerId)
 {
     if (triggerId.IsValid)
     {
         NativeAudioSystem.ExecuteTrigger(triggerId._id);
         return(true);
     }
     return(false);
 }
Esempio n. 8
0
 /// <summary>
 /// Stops the specified audio trigger. Only audio triggers that have been "played" can be stopped.
 /// </summary>
 /// <param name="triggerId"></param>
 /// <returns>True if the audio trigger is stopped</returns>
 public static bool Stop(AudioTriggerId triggerId)
 {
     if (triggerId.IsValid)
     {
         NativeAudioSystem.StopTrigger(triggerId._id);
         return(true);
     }
     return(false);
 }
Esempio n. 9
0
        /// <summary>
        /// Sets the specified audio parameter with the specified name to the specified value
        /// </summary>
        /// <param name="parameterName"></param>
        /// <param name="parameterVal"></param>
        public static void SetParameter(string parameterName, float parameterVal)
        {
            uint audioParameterId = NativeAudioSystem.GetAudioParameterId(parameterName);

            if (audioParameterId != Audio.InvalidControlId)
            {
                NativeAudioSystem.SetAudioParameter(audioParameterId, parameterVal);
            }
        }
Esempio n. 10
0
        static AudioManager()
        {
            _requestListener = OnAudioEvent;

            //bind listener to c++
            IntPtr fnPtr = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate(_requestListener);

            NativeAudioSystem.AddAudioRequestListener(fnPtr);
        }
Esempio n. 11
0
        /// <summary>
        /// Stops the audio trigger by the specified name. Only audio triggers that have been "played" can be stopped.
        /// </summary>
        /// <param name="triggerName"></param>
        /// <returns>True if the audio trigger is stopped</returns>
        public static bool Stop(string triggerName)
        {
            uint triggerId = AudioManager.GetTriggerId(triggerName);

            if (triggerId != Audio.InvalidControlId)
            {
                NativeAudioSystem.StopTrigger(triggerId, false);
            }
            return(triggerId != InvalidControlId);
        }
Esempio n. 12
0
 /// <summary>
 /// Sets the transformation of the audio object
 /// </summary>
 /// <param name="matrix"></param>
 public void SetTransformation(Matrix3x4 matrix)
 {
     if (_audioTransformation != null)
     {
         _audioTransformation.Dispose();
         _audioTransformation = null;
     }
     _audioTransformation = new AudioObjectTransformation(matrix);
     NativeAudioSystem.SetAudioTransformation(_cPtr.Handle, _audioTransformation.NativePtr);
 }
Esempio n. 13
0
        /// <summary>
        /// Stops the specified trigger name on this audio object
        /// </summary>
        /// <param name="triggerName"></param>
        public void Stop(string triggerName)
        {
            uint triggerId = Audio.InvalidControlId;

            AudioManager.AddOrGetTrigger(triggerName, out triggerId);
            if (triggerId != Audio.InvalidControlId)
            {
                NativeAudioSystem.StopAudioObjectTrigger(_cPtr.Handle, triggerId, false);
            }
        }
Esempio n. 14
0
        /// <summary>
        /// Retrieves and executes the specified audio trigger by name
        /// </summary>
        /// <param name="triggerName"></param>
        /// <returns>Returns true if the audio trigger is executed. False otherwise</returns>
        public static bool Play(string triggerName)
        {
            uint triggerId = InvalidControlId;

            AudioManager.AddOrGetTrigger(triggerName, out triggerId);
            if (triggerId == InvalidControlId)
            {
                return(false);
            }
            NativeAudioSystem.ExecuteTrigger(triggerId);
            return(true);
        }
 public void SetTransform(Matrix3x4 matrix)
 {
     _matrix3x4 = matrix;
     //release old CObjectTransformation
     if (_objectTransformationPtr.Handle != IntPtr.Zero)
     {
         NativeAudioSystem.ReleaseAudioTransformation(_objectTransformationPtr.Handle);
     }
     _objectTransformationPtr = new System.Runtime.InteropServices.HandleRef(this, NativeAudioSystem.CreateAudioTransformation(_matrix3x4.m00, _matrix3x4.m01, _matrix3x4.m02, _matrix3x4.m03,
                                                                                                                               _matrix3x4.m10, _matrix3x4.m11, _matrix3x4.m12, _matrix3x4.m13,
                                                                                                                               _matrix3x4.m20, _matrix3x4.m21, _matrix3x4.m22, _matrix3x4.m23));
 }
Esempio n. 16
0
 internal AudioRequestInfo(IntPtr nativePtr, bool isCopy = false)
 {
     _isCopy = isCopy;
     _cPtr   = new System.Runtime.InteropServices.HandleRef(this, nativePtr);
     if (_isCopy)
     {
         _requestResult = NativeAudioSystem.SRIGetRequestResult(nativePtr);
         _flagsType     = NativeAudioSystem.SRIGetEnumFlagsType(nativePtr);
         _controlId     = NativeAudioSystem.SRIGetControlId(nativePtr);
         _audioObject   = NativeAudioSystem.SRIGetAudioObject(nativePtr);
     }
 }
 public void SetTransform(Matrix3x4 matrix)
 {
     _matrix3x4 = matrix;
     //release old CObjectTransformation
     if (_objectTransformationPtr.Handle != IntPtr.Zero)
     {
         NativeAudioSystem.ReleaseAudioTransformation(_objectTransformationPtr.Handle);
     }
     _objectTransformationPtr = new System.Runtime.InteropServices.HandleRef(this, NativeAudioSystem.CreateAudioTransformation(_matrix3x4[0, 0], _matrix3x4[0, 1], _matrix3x4[0, 2], _matrix3x4[0, 3],
                                                                                                                               _matrix3x4[1, 0], _matrix3x4[1, 1], _matrix3x4[1, 2], _matrix3x4[1, 3],
                                                                                                                               _matrix3x4[2, 0], _matrix3x4[2, 1], _matrix3x4[2, 2], _matrix3x4[2, 3]));
 }
Esempio n. 18
0
        private static void RemoveListener()
        {
            if (_requestListener == null)
            {
                return;
            }

            // Remove listener from c++
            IntPtr fnPtr = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate(_requestListener);

            NativeAudioSystem.RemoveAudioRequestListener(fnPtr);
            _requestListener = null;
        }
Esempio n. 19
0
        /// <summary>
        /// Sets the Audio switch with the specified name to the specified state name
        /// </summary>
        /// <param name="switchName"></param>
        /// <param name="switchStateName"></param>
        public static void SetSwitchState(string switchName, string switchStateName)
        {
            uint switchId = NativeAudioSystem.GetAudioSwitchId(switchName);

            if (switchId != Audio.InvalidControlId)
            {
                uint switchStateId = NativeAudioSystem.GetAudioSwitchStateId(switchId, switchStateName);
                if (switchStateId != Audio.InvalidSwitchStateId)
                {
                    NativeAudioSystem.SetAudioSwitchState(switchId, switchStateId);
                }
            }
        }
Esempio n. 20
0
        private void Dispose(bool isDisposing)
        {
            if (_isDisposed)
            {
                return;
            }

            if (_cPtr.Handle != IntPtr.Zero && !_isCopy)
            {
                NativeAudioSystem.ReleaseSRequestInfo(_cPtr.Handle);
                _cPtr = new System.Runtime.InteropServices.HandleRef(null, IntPtr.Zero);
            }
            _isDisposed = true;
        }
Esempio n. 21
0
 /// <summary>
 /// Sets the transformation of the audio object
 /// </summary>
 /// <param name="position"></param>
 /// <param name="forward"></param>
 /// <param name="up"></param>
 public void SetTransformation(Vector3 position, Vector3 forward, Vector3 up)
 {
     // create managed matrix and once done call native method
     if (_audioTransformation != null)
     {
         _audioTransformation.Dispose();
         _audioTransformation = null;
     }
     _audioTransformation = new AudioObjectTransformation(new Matrix3x4(
                                                              0, forward.x, up.x, position.x,
                                                              0, forward.y, up.y, position.y,
                                                              0, forward.z, up.z, position.z
                                                              ));
     NativeAudioSystem.SetAudioTransformation(_cPtr.Handle, _audioTransformation.NativePtr);
 }
Esempio n. 22
0
        private void Dispose(bool isDisposing)
        {
            if (_isDisposed)
            {
                return;
            }

            if (isDisposing)
            {
                _audioFilePath = null;
            }
            if (_audioPlayFileInfoPtr.Handle != System.IntPtr.Zero)
            {
                NativeAudioSystem.ReleaseSPlayFileInfo(_audioPlayFileInfoPtr.Handle);
                _audioPlayFileInfoPtr = new System.Runtime.InteropServices.HandleRef(null, IntPtr.Zero);
            }
            _isDisposed = true;
        }
        private void Dispose(bool disposing)
        {
            if (_isDisposed)
            {
                return;
            }

            if (disposing)
            {
                _matrix3x4 = null;
            }
            if (_objectTransformationPtr.Handle != System.IntPtr.Zero)
            {
                NativeAudioSystem.ReleaseAudioTransformation(_objectTransformationPtr.Handle);
                _objectTransformationPtr = new System.Runtime.InteropServices.HandleRef(null, IntPtr.Zero);
            }
            _isDisposed = true;
        }
Esempio n. 24
0
        private void Dispose(bool isDisposing)
        {
            if (_isDisposed)
            {
                return;
            }

            if (isDisposing)
            {
                _audioTransformation.Dispose();
                _audioTransformation = null;
            }
            if (_cPtr.Handle != System.IntPtr.Zero)
            {
                NativeAudioSystem.ReleaseAudioObject(_cPtr.Handle);
                _cPtr = new System.Runtime.InteropServices.HandleRef(null, IntPtr.Zero);
            }
            _isDisposed = true;
        }
Esempio n. 25
0
        /// <summary>
        /// Removes the specified trigger with the specified name. Returns true if the trigger is removed
        /// </summary>
        /// <param name="triggerName"></param>
        /// <returns></returns>
        public static bool RemoveTrigger(string triggerName)
        {
            bool ret       = false;
            uint triggerId = Audio.InvalidControlId;

            if (_triggerByName.TryGetValue(triggerName, out triggerId))
            {
                NativeAudioSystem.StopTrigger(triggerId, false);
                ret = (triggerId != Audio.InvalidControlId);

                //update entries
                _triggerByName.Remove(triggerName);
                _indexTriggerIdToName.Remove(triggerId);

                //listeners should be removed manually by user
                ret = true;
            }
            return(ret);
        }
Esempio n. 26
0
        /// <summary>
        /// Add the specified trigger name and retrieves the trigger id. If trigger name is already existing, trigger id will be returned. Returns true if the trigger name is added
        /// </summary>
        /// <param name="triggerName"></param>
        /// <param name="triggerId"></param>
        /// <returns></returns>
        public static bool AddOrGetTrigger(string triggerName, out uint triggerId)
        {
            bool ret = false;

            triggerId = Audio.InvalidControlId;
            if (!_triggerByName.TryGetValue(triggerName, out triggerId))
            {
                triggerId = NativeAudioSystem.GetAudioTriggerId(triggerName);
                if (ret = (triggerId != Audio.InvalidControlId))
                {
                    _triggerByName[triggerName]      = triggerId;
                    _indexTriggerIdToName[triggerId] = triggerName;
                }
                ret = true;
            }
            else
            {
                triggerId = _triggerByName[triggerName];
            }
            return(ret);
        }
Esempio n. 27
0
 /// <summary>
 /// Creates an Audio object
 /// </summary>
 public AudioObject() : this(NativeAudioSystem.CreateAudioObject())
 {
 }
Esempio n. 28
0
 /// <summary>
 /// Returns the path in which audio configuration data is stored
 /// </summary>
 /// <returns></returns>
 public static string GetConfigurationPath()
 {
     return(NativeAudioSystem.GetConfigPath());
 }
 internal AudioObjectTransformation(Matrix3x4 managedMatrix)
 {
     _matrix3x4 = managedMatrix;
     _objectTransformationPtr = new System.Runtime.InteropServices.HandleRef(this, NativeAudioSystem.CreateAudioTransformation(_matrix3x4[0, 0], _matrix3x4[0, 1], _matrix3x4[0, 2], _matrix3x4[0, 3],
                                                                                                                               _matrix3x4[1, 0], _matrix3x4[1, 1], _matrix3x4[1, 2], _matrix3x4[1, 3],
                                                                                                                               _matrix3x4[2, 0], _matrix3x4[2, 1], _matrix3x4[2, 2], _matrix3x4[2, 3]));
 }
Esempio n. 30
0
 /// <summary>
 /// Constructor for an AudioRequestInfo object.
 /// </summary>
 /// <param name="eRequestResult"></param>
 /// <param name="audioSystemEvent"></param>
 /// <param name="CtrlId"></param>
 /// <param name="audioObject"></param>
 public AudioRequestInfo(uint eRequestResult, uint audioSystemEvent, uint CtrlId, AudioObject audioObject) : this(NativeAudioSystem.CreateSRequestInfo(eRequestResult, audioSystemEvent, CtrlId, audioObject.NativePtr))
 {
 }