public float CalculateVolume() { float num = AudioTools.DBToLinear(_volumeParameter.Get(FabricTimer.Get())); float linear = 1f - (1f - _gain * num); return(AudioTools.LinearToDB(linear)); }
public void Deactivate() { _activeParameter.SetTarget(FabricTimer.Get(), 0f, _fadeOutTime, _fadeOutCurve); _volumeParameter.SetTarget(FabricTimer.Get(), 0f, _fadeOutTime, _fadeOutCurve); _pitchParameter.SetTarget(FabricTimer.Get(), 0f, _fadeOutTime, _fadeOutCurve); _isActive = false; }
public void Activate() { _activeParameter.SetTarget(FabricTimer.Get(), 1f, _fadeInTime, _fadeInCurve); _volumeParameter.SetTarget(FabricTimer.Get(), _volume, _fadeInTime, _fadeInCurve); _pitchParameter.SetTarget(FabricTimer.Get(), _pitch, _fadeInTime, _fadeInCurve); _isActive = true; }
public bool IsActive() { if (!_isActive) { return(!_activeParameter.HasReachedTarget(FabricTimer.Get())); } return(true); }
public void Set(Component component, float fadeInTime) { if (!(_audioSource == null)) { _fadeParameter.SetTarget(FabricTimer.Get(), 1f, fadeInTime, 0.5f); _audioSource.volume = 0f; _component = component; if (_vrAudio != null) { _vrAudio.Set(component); } _state = AudioVoiceState.Playing; } }
public override bool UpdateInternal(ref Context context) { if (_looped && _playMode == RandomComponentPlayMode.RandomNoRepeat && _triggerMode == RandomComponentTriggerMode.Retrigger) { float realtimeDelta = FabricTimer.GetRealtimeDelta(); _retriggerTimer += realtimeDelta; if (_retriggerTimer >= _retriggerTime) { _componentInstance._instance.SetPlayScheduled(_retriggerTimer - _retriggerTime, 0.0); PlayRandomomponent(_componentInstance); _retriggerTime = _delay + UnityEngine.Random.Range(_delayRandomization, _delayMaxRandomization); _retriggerTimer = 0f; } } return(base.UpdateInternal(ref context)); }
public void Stop(float fadeOutTime, bool callStop) { if (!(_audioSource == null)) { if (fadeOutTime > 0f) { _fadeParameter.SetTarget(FabricTimer.Get(), 0f, fadeOutTime, 0.5f); _volume = _audioSource.volume; _callStop = callStop; _state = AudioVoiceState.Stopping; } else { StopAudioVoice(); } } }
public void UpdateInternal() { profiler.Begin(); for (int i = 0; i < _eventQueue.Count; i++) { Event @event = _eventQueue[i]; if (@event.parentGameObject == null) { _eventQueue.RemoveAt(i); } else if (@event._delayTimer < @event._delay) { @event._delayTimer += FabricTimer.GetRealtimeDelta(); } else if (ProcessEvent(@event)) { _eventQueue.RemoveAt(i); } } _eventEditor.Update(); _globalParameterManager.Update(); if (Application.isEditor) { for (int j = 0; j < _activeEvents.Count; j++) { ActiveEvent activeEvent = _activeEvents[j]; if (activeEvent._component == null || !activeEvent._component.IsComponentActive()) { if (activeEvent._time == 0f) { activeEvent._time = _activeEventPersistenceTime; } else { activeEvent._time -= FabricTimer.GetRealtimeDelta(); } if (activeEvent._time <= 0f) { _activeEvents.Remove(activeEvent); activeEvent._time = 0f; } } } } profiler.End(); }
public void Update() { for (int i = 0; i < _eventQueue.Count; i++) { Event @event = _eventQueue[i]; if (@event._delayTimer < @event._delay) { @event._delayTimer += FabricTimer.GetRealtimeDelta(); continue; } ProcessEvent(@event); @event._delay = 0f; @event._delayTimer = 0f; @event.eventStatus = EventStatus.Handled; _eventQueue.RemoveAt(i); } }
public void SetValue(float value, float time = 0f, float curve = 0.5f, bool forceDirtyFlag = false) { if (value != _value || forceDirtyFlag) { _value = value; if (_value >= _max) { _value = _max; } if (_value <= _min) { _value = _min; } _interpolatedParameter.SetTarget(FabricTimer.Get(), value, time, curve); _isDirty = true; } }
private void Update() { profiler.Begin(); if (_useComponentIsPlayingFlag) { if (_componentToListen != null && _componentToListen.IsComponentActive()) { _sideChainGain = gain; } else { _sideChainGain = 1f; } } else { if (!(_volumeMeter != null)) { _sideChainGain = 1f; profiler.End(); return; } float mRMS = _volumeMeter.volumeMeterState.mRMS; float db = AudioTools.LinearToDB(mRMS); _sideChainGain = AudioTools.DBToNormalizedDB(db); } float currentTimeMS = FabricTimer.Get(); if (_sideChainGain > _envelope.GetCurrentValue()) { _envelope.SetTarget(currentTimeMS, _sideChainGain, fadeUpRate, 0.5f); } else { _envelope.SetTarget(currentTimeMS, _sideChainGain, fadeDownRate, 0.5f); } if (_useComponentIsPlayingFlag) { _sideChainGain = _envelope.Get(currentTimeMS); } else { _sideChainGain = 1f - _envelope.Get(currentTimeMS) * gain; } profiler.End(); }
public override void UpdateParameters() { if (!_FrontLeftChannel.HasReachedTarget() || !_FrontRightChannel.HasReachedTarget() || !_CenterChannel.HasReachedTarget() || !_RearLeftChannel.HasReachedTarget() || !_RearRightChannel.HasReachedTarget() || !_LFEChannel.HasReachedTarget()) { FabricTimer.Get(); if (_samplePlayerComponent != null) { _samplePlayerComponent._channelGains[0] = _FrontLeftChannel.GetValue(); _samplePlayerComponent._channelGains[1] = _FrontRightChannel.GetValue(); _samplePlayerComponent._channelGains[2] = _CenterChannel.GetValue(); _samplePlayerComponent._channelGains[3] = _LFEChannel.GetValue(); _samplePlayerComponent._channelGains[4] = _RearLeftChannel.GetValue(); _samplePlayerComponent._channelGains[5] = _RearRightChannel.GetValue(); } base.UpdateParameters(); } }
public override void UpdateParameters() { if (_distortionLevel.HasReachedTarget()) { return; } FabricTimer.Get(); for (int i = 0; i < _dspInstances.Count; i++) { AudioDistortionFilter audioDistortionFilter = _dspInstances[i] as AudioDistortionFilter; if ((bool)audioDistortionFilter) { audioDistortionFilter.distortionLevel = _distortionLevel.GetValue(); } } base.UpdateParameters(); }
public override void UpdateParameters() { if (_cutoffFrequency.HasReachedTarget() && _lowpassResonaceQ.HasReachedTarget()) { return; } FabricTimer.Get(); for (int i = 0; i < _dspInstances.Count; i++) { AudioLowPassFilter audioLowPassFilter = _dspInstances[i] as AudioLowPassFilter; if ((bool)audioLowPassFilter) { audioLowPassFilter.cutoffFrequency = _cutoffFrequency.GetValue(); audioLowPassFilter.lowpassResonanceQ = _lowpassResonaceQ.GetValue(); } } base.UpdateParameters(); }
public void UpdateInternal() { if (_audioSource == null) { return; } if (_vrAudio != null) { _vrAudio.Update(); } if (_state == AudioVoiceState.Stopping) { _audioSource.volume = _volume * _fadeParameter.Get(FabricTimer.Get()); if (_fadeParameter.HasReachedTarget()) { StopAudioVoice(); } } }
public override void UpdateParameters() { if (_delay.HasReachedTarget() && _decayRatio.HasReachedTarget() && _wetMix.HasReachedTarget() && _dryMix.HasReachedTarget()) { return; } FabricTimer.Get(); for (int i = 0; i < _dspInstances.Count; i++) { AudioEchoFilter audioEchoFilter = _dspInstances[i] as AudioEchoFilter; if ((bool)audioEchoFilter) { audioEchoFilter.delay = _delay.GetValue(); audioEchoFilter.decayRatio = _decayRatio.GetValue(); audioEchoFilter.wetMix = _wetMix.GetValue(); audioEchoFilter.dryMix = _dryMix.GetValue(); } } base.UpdateParameters(); }
public void Update() { profiler.Begin(); FabricTimer.Update(); EventManager.Instance.UpdateInternal(); for (int i = 0; i < _components.Count; i++) { _updateContext.Reset(); Component component = _components[i]; if (component.IsComponentActive()) { component.UpdateInternal(ref _updateContext); } } UpdateMusicTimeSettings(); UpdateGroupComponentProxies(ref _updateContext); if (AudioSourcePoolManager != null) { AudioSourcePoolManager.Update(); } profiler.End(); }
public override void UpdateParameters() { if (_dryMix.HasReachedTarget() && _wetMix1.HasReachedTarget() && _wetMix2.HasReachedTarget() && _wetMix3.HasReachedTarget() && _delay.HasReachedTarget() && _rate.HasReachedTarget() && _depth.HasReachedTarget() && _feedback.HasReachedTarget()) { return; } FabricTimer.Get(); for (int i = 0; i < _dspInstances.Count; i++) { AudioChorusFilter audioChorusFilter = _dspInstances[i] as AudioChorusFilter; if ((bool)audioChorusFilter) { audioChorusFilter.dryMix = _dryMix.GetValue(); audioChorusFilter.wetMix1 = _wetMix1.GetValue(); audioChorusFilter.wetMix2 = _wetMix2.GetValue(); audioChorusFilter.wetMix3 = _wetMix3.GetValue(); audioChorusFilter.delay = _delay.GetValue(); audioChorusFilter.rate = _rate.GetValue(); audioChorusFilter.depth = _depth.GetValue(); } } base.UpdateParameters(); }
public override void UpdateParameters() { if (!_FrontLeftChannel.HasReachedTarget() && !_FrontRightChannel.HasReachedTarget() && !_CenterChannel.HasReachedTarget() && !_SideLeftChannel.HasReachedTarget() && !_SideRightChannel.HasReachedTarget() && !_RearLeftChannel.HasReachedTarget() && !_RearRightChannel.HasReachedTarget() && !_LFEChannel.HasReachedTarget()) { return; } FabricTimer.Get(); for (int i = 0; i < _dspInstances.Count; i++) { AudioPanner audioPanner = _dspInstances[i] as AudioPanner; if ((bool)audioPanner) { audioPanner._channelGains[0] = _FrontLeftChannel.GetValue(); audioPanner._channelGains[1] = _FrontRightChannel.GetValue(); audioPanner._channelGains[2] = _CenterChannel.GetValue(); audioPanner._channelGains[3] = _LFEChannel.GetValue(); audioPanner._channelGains[4] = _RearLeftChannel.GetValue(); audioPanner._channelGains[5] = _RearRightChannel.GetValue(); audioPanner._channelGains[6] = _SideLeftChannel.GetValue(); audioPanner._channelGains[7] = _SideRightChannel.GetValue(); } } base.UpdateParameters(); }
public float GetValue() { return(_interpolatedParameter.Get(FabricTimer.Get())); }
bool GlobalSwitch.IListener.OnSwitch(GlobalSwitch.Switch _switch) { for (int i = 0; i < _componentInstances.Length; i++) { ComponentInstance componentInstance = _componentInstances[i]; if (componentInstance == null) { continue; } GlobalSwitchContainer globalSwitchContainer = GetGlobalSwitchContainer(_switch); if (globalSwitchContainer == null) { continue; } Component component = globalSwitchContainer._components[0]; if (!(component != null) || !(component != _selectedComponent)) { continue; } bool isComponentActive = _isComponentActive; if (_selectedComponent != null) { _selectedComponent.StopInternal(stopInstances: false, forceStop: false, 0f, 0.5f); } _selectedComponent = component; if (_startOnSwitch && isComponentActive && !IsMusicSyncEnabled()) { _componentInstance._instance.ResetPlayScheduled(); _selectedComponent.PlayInternal(_componentInstance, 0f, 0.5f); if (_componentStatus == ComponentStatus.Stopping) { StopInternal(stopInstances: false, forceStop: false, _fadeParameter.GetTimeRemaining(FabricTimer.Get()), _fadeOutCurve); } } if (HasValidEventNotifier()) { NotifyEvent(EventNotificationType.OnSwitch, _selectedComponent); } } return(true); }
private void SetSwitch(string name, bool ignoreActiveFlag = false) { for (int i = 0; i < _components.Count; i++) { Component component = _components[i]; if (!(component != null) || !(component.Name == name) || !(component != _selectedComponent)) { continue; } bool flag = ignoreActiveFlag || _isComponentActive; if (_selectedComponent != null) { _selectedComponent.StopInternal(stopInstances: false, forceStop: false, 0f, 0.5f); } _selectedComponent = component; if (_startOnSwitch && flag && !IsMusicSyncEnabled()) { _componentInstance._instance.ResetPlayScheduled(); _selectedComponent.PlayInternal(_componentInstance, 0f, 0.5f); if (_componentStatus == ComponentStatus.Stopping) { StopInternal(stopInstances: false, forceStop: false, _fadeParameter.GetTimeRemaining(FabricTimer.Get()), _fadeOutCurve); } } if (HasValidEventNotifier()) { NotifyEvent(EventNotificationType.OnSwitch, _selectedComponent); } break; } }
public void Update(Component component) { if (_parameters == null) { return; } for (int i = 0; i < _cachedValues.Length; i++) { _cachedValues[i] = 1f; } for (int j = 0; j < _parameters.Length; j++) { RTPParameterToProperty rTPParameterToProperty = _parameters[j]; rTPParameterToProperty._parameter.Update(); float num = 1f; _ = rTPParameterToProperty._property._min; _ = rTPParameterToProperty._property._max; if (rTPParameterToProperty._type == RTPParameterType.Distance || rTPParameterToProperty._parameter.Name == "Distance") { _ = 1f / (rTPParameterToProperty._parameter._max - rTPParameterToProperty._parameter._min); if (component.ParentGameObject != null) { if (FabricManager.Instance._audioListener != null) { num = Vector3.Distance(component.ParentGameObject.transform.position, FabricManager.Instance._audioListener.transform.position); } else if (Camera.main != null) { num = Vector3.Distance(component.ParentGameObject.transform.position, Camera.main.transform.position); } rTPParameterToProperty._parameter.SetValue(num); num = CalculateNewValue(rTPParameterToProperty, rTPParameterToProperty._parameter.GetCurrentValue()); } } else if (rTPParameterToProperty._type == RTPParameterType.Modulator) { RTPModulator rtpModulator = rTPParameterToProperty._rtpModulator; if (rtpModulator != null) { num = rtpModulator.GetValue(Time.time); rTPParameterToProperty._parameter.SetValue(num); num = CalculateNewValue(rTPParameterToProperty, rTPParameterToProperty._parameter.GetCurrentValue()); } } else if (rTPParameterToProperty._type == RTPParameterType.Listener_Angle) { if (component.ParentGameObject != null) { Vector3 from = default(Vector3); Vector3 to = default(Vector3); if (FabricManager.Instance._audioListener != null) { from = Vector3.forward; to = FabricManager.Instance._audioListener.transform.forward; } else if (Camera.main != null) { from = Vector3.forward; to = Camera.main.transform.forward; } num = Vector3.Angle(from, to); rTPParameterToProperty._parameter.SetValue(num); num = CalculateNewValue(rTPParameterToProperty, rTPParameterToProperty._parameter.GetCurrentValue()); } } else if (rTPParameterToProperty._type == RTPParameterType.Component_Angle) { if (component.ParentGameObject != null) { Vector3 from2 = default(Vector3); Vector3 to2 = default(Vector3); if (FabricManager.Instance._audioListener != null) { from2 = component.ParentGameObject.transform.position - FabricManager.Instance._audioListener.transform.position; to2 = component.ParentGameObject.transform.forward; } else if (Camera.main != null) { from2 = component.ParentGameObject.transform.position - Camera.main.transform.position; to2 = component.ParentGameObject.transform.forward; } num = Vector3.Angle(from2, to2); rTPParameterToProperty._parameter.SetValue(num); num = CalculateNewValue(rTPParameterToProperty, rTPParameterToProperty._parameter.GetCurrentValue()); } } else if (rTPParameterToProperty._type == RTPParameterType.Component_Velocity) { if (component.ParentGameObject != null) { num = (component.ParentGameObject.transform.position - rTPParameterToProperty._previousPosition).magnitude / FabricTimer.GetRealtimeDelta(); rTPParameterToProperty._parameter.SetValue(num); num = CalculateNewValue(rTPParameterToProperty, rTPParameterToProperty._parameter.GetCurrentValue()); rTPParameterToProperty._previousPosition = component.ParentGameObject.transform.position; } } else if (rTPParameterToProperty._type == RTPParameterType.Listener_Velocity) { if (FabricManager.Instance._audioListener != null) { num = (FabricManager.Instance._audioListener.transform.position - rTPParameterToProperty._previousPosition).magnitude / FabricTimer.GetRealtimeDelta(); rTPParameterToProperty._previousPosition = FabricManager.Instance._audioListener.transform.position; } else if (Camera.main != null) { num = (Camera.main.transform.position - rTPParameterToProperty._previousPosition).magnitude / FabricTimer.GetRealtimeDelta(); rTPParameterToProperty._previousPosition = Camera.main.transform.position; } rTPParameterToProperty._parameter.SetValue(num); num = CalculateNewValue(rTPParameterToProperty, rTPParameterToProperty._parameter.GetCurrentValue()); } else if (rTPParameterToProperty._type == RTPParameterType.Volume_Meter) { VolumeMeter volumeMeter = rTPParameterToProperty._volumeMeter; if (volumeMeter != null) { num = volumeMeter.volumeMeterState.mRMS; rTPParameterToProperty._parameter.SetValue(num); num = CalculateNewValue(rTPParameterToProperty, rTPParameterToProperty._parameter.GetCurrentValue()); } } else if (rTPParameterToProperty._type == RTPParameterType.Global_Parameter) { GlobalParameter globalParameter = EventManager.Instance._globalParameterManager._globalRTParameters.FindItem(rTPParameterToProperty._globalParameterName); if (globalParameter != null) { rTPParameterToProperty._parameter._max = globalParameter._max; rTPParameterToProperty._parameter._min = globalParameter._min; rTPParameterToProperty._parameter.SetValue(globalParameter.GetCurrentValue()); num = CalculateNewValue(rTPParameterToProperty, rTPParameterToProperty._parameter.GetCurrentValue()); } } else if (rTPParameterToProperty._type == RTPParameterType.Custom_Parameter) { ICustomRTPParameter customRTPParameter = FabricManager.Instance._customRTPParameter; if (customRTPParameter != null) { num = customRTPParameter.UpdateProperty(component, rTPParameterToProperty._property, rTPParameterToProperty._propertyType); num = CalculateNewValue(rTPParameterToProperty, num); rTPParameterToProperty._parameter.SetValue(num); } } else if (rTPParameterToProperty._type == RTPParameterType.Max_Instances) { num = ((!(component.ComponentHolder != null)) ? 0f : ((float)component.ComponentHolder.GetNumActiveComponentInstances() / (float)component.MaxInstances)); num = CalculateNewValue(rTPParameterToProperty, num); rTPParameterToProperty._parameter.SetValue(num); } else { num = CalculateNewValue(rTPParameterToProperty, rTPParameterToProperty._parameter.GetCurrentValue()); } rTPParameterToProperty._property._value = num; if ((object)component != null) { _ = rTPParameterToProperty._property._property; _cachedValues[rTPParameterToProperty._property._property] *= num; ((IRTPPropertyListener)component).UpdateProperty(rTPParameterToProperty._property, _cachedValues[rTPParameterToProperty._property._property], rTPParameterToProperty._propertyType); } } }
public float CalculatePitch() { return(1f + _pitchParameter.Get(FabricTimer.Get())); }
public void Update() { float realtimeDelta = FabricTimer.GetRealtimeDelta(); if (_direction > 0f) { _seekTarget += _velocity * realtimeDelta; } else { _seekTarget -= _velocity * realtimeDelta; } _markers.Update(_seekTarget, _direction); if (_markers.IsMarkerKeyOff()) { _seekTarget = _markers._keyOffMarker._value; } if (_velocity != 0f) { if (_seekTarget > MAX_NORMALISED_RANGE) { if (_loopBehaviour == ParameterLoopBehaviour.Loop) { _seekTarget -= MAX_NORMALISED_RANGE - MIN_NORMALISED_RANGE; } else if (_loopBehaviour == ParameterLoopBehaviour.OneShot) { _seekTarget = MAX_NORMALISED_RANGE; } else if (_loopBehaviour == ParameterLoopBehaviour.PingPong) { _direction = -1f; } else { _seekTarget = MAX_NORMALISED_RANGE; } _markers.Reset(); } else if (_seekTarget < MIN_NORMALISED_RANGE) { if (_loopBehaviour == ParameterLoopBehaviour.Loop) { _seekTarget += MAX_NORMALISED_RANGE - MIN_NORMALISED_RANGE; } else if (_loopBehaviour == ParameterLoopBehaviour.OneShot) { _seekTarget = MIN_NORMALISED_RANGE; } else if (_loopBehaviour == ParameterLoopBehaviour.PingPong) { _direction = 1f; } else { _seekTarget = MIN_NORMALISED_RANGE; } _markers.Reset(); } if (_seekTarget > MAX_NORMALISED_RANGE) { _seekTarget = MAX_NORMALISED_RANGE; } else if (_seekTarget < MIN_NORMALISED_RANGE) { _seekTarget = MIN_NORMALISED_RANGE; } } if (_seekSpeed != 0f) { float num = _seekSpeed * realtimeDelta; if (_seekTarget > _value) { _value += num; if (_value > _seekTarget) { _value = _seekTarget; } } else if (_seekTarget < _value) { _value -= num; if (_value < _seekTarget) { _value = _seekTarget; } } } else { _value = _seekTarget; } AudioTools.Limit(ref _value, 0f, 1f); }
private bool PlayNextEntry(double offset = 0.0, double scheduledStop = 0.0) { if (_playlist != null && _playlist.Length > 0) { int num = _playlist.Length - 1; if (_playingComponentIndex > num) { if (_sequencePlayMode != SequenceComponentPlayMode.Loop) { return(false); } _playingComponentIndex = 0; if (HasValidEventNotifier()) { NotifyEvent(EventNotificationType.OnSequenceEnd, this); } } if (_currentlyPlayingComponent != null && _sequenceType == SequenceComponentType.PlayOnAdvance) { _currentlyPlayingComponent.StopInternal(stopInstances: false, forceStop: false, 0f, 0.5f, scheduledStop); } _prevPlayingComponentIndex = _playingComponentIndex; _currentlyPlayingComponent = _playlist[_playingComponentIndex++]; if (HasValidEventNotifier()) { NotifyEvent(EventNotificationType.OnSequenceNextEntry, _currentlyPlayingComponent); } } if (_currentlyPlayingComponent != null && _componentInstance != null) { _currentlyPlayingComponent.PlayInternal(_componentInstance, 0f, 0.5f); if (_componentStatus == ComponentStatus.Stopping && _onlyStopOnce && _sequenceType != SequenceComponentType.PlayOnAdvance) { StopInternal(stopInstances: false, forceStop: false, _fadeParameter.GetTimeRemaining(FabricTimer.Get()), _fadeOutCurve); _onlyStopOnce = false; } } return(true); }