Vector2 GetPointGaze() { float a = Mathf.Sign(_Gaze.GazePointNormalized.x - 0.5f) * Mathf.Pow(Mathf.Abs(_Gaze.GazePointNormalized.x - 0.5f) * 2, Exp); float b = Mathf.Sign(_Gaze.GazePointNormalized.y - 0.5f) * Mathf.Pow(Mathf.Abs(_Gaze.GazePointNormalized.y - 0.5f) * 2, Exp); _X += (_posX.Add(a, 0.5f)) * 1 * Time.deltaTime; _Y += (_posY.Add(b, 0.5f)) * 1.5f * Time.deltaTime; _X = Mathf.Clamp(_X, -1, 1); _Y = Mathf.Clamp(_Y, -1, 1); return(new Vector2(_X * 0.5f + 0.5f, _Y * 0.5f + 0.5f)); }
public override void SetWeight(float w) { W = _w.Add(w, 1.0f); base.SetWeight(W); _features.FillImage(1); _features.ConvertToTexture(_tmpTexture, true); _alpha += (w * _manager.LayersParameters.MaxAlpha - _alpha) * _manager.LayersParameters.AlphaScaler * Time.deltaTime; _alpha = Mathf.Clamp(_alpha, _manager.LayersParameters.MinAlpha, _manager.LayersParameters.MaxAlpha); //_mr.material.SetVector ("_Color", new Vector4(1,1,1,W+MinAlpha)); _renderProcessor.ProcessingMaterial.SetFloat("_MinAlpha", _manager.LayersParameters.MinAlpha); _renderProcessor.ProcessingMaterial.SetFloat("_MaxAlpha", _alpha); _renderProcessor.ProcessingMaterial.SetTexture("_TargetMask", _tmpTexture); _renderProcessor.ProcessingMaterial.SetFloat("_Strength", W); _blurProcessorH.ProcessingMaterial.SetFloat("_Size", _manager.LayersParameters.ImageBlurSize * (1 - W)); _blurProcessorV.ProcessingMaterial.SetFloat("_Size", _manager.LayersParameters.ImageBlurSize * (1 - W)); }
void ReadAudio(float[] data, int channels, bool modulate) { if (!Player.IsStarted() || _paused) { return; } uint length = 0; int timeout = 0; float average = 0; uint DataLength = (uint)data.Length; uint srcChannelsCount = 2; uint targetLength = DataLength; uint channelIndex = 0; uint stepSize = 1; while (length < DataLength) { AudioSamples p; lock (_dataMutex) { p = GetExistingPacket(); } if (p == null) { if (!_Process()) { WaitCount++; ++timeout; if (timeout > 20) { break; } } else { timeout = 0; } continue; } srcChannelsCount = (uint)p.channels; if (srcChannelsCount == 2 && this.Channel != SourceChannel.Both) { srcChannelsCount = 1; stepSize = 2; channelIndex = (uint)(this.Channel == SourceChannel.Left ? 0 : 1); } //calculate the left amount of data in this packet uint sz = (uint)Mathf.Max(0, p.samples.Length - p.startIndex); //determine the amount of data we going to use of this packet uint count = (uint)Mathf.Min(sz, Mathf.Max(0, data.Length - length) /*Remaining data to be filled*/); average += GstNetworkAudioPlayer.ProcessAudioPackets(p.samples, (int)p.startIndex, (int)channelIndex, (int)count, (int)stepSize, (int)srcChannelsCount, data, (int)length, (int)channels, modulate); lock (_dataMutex) { if (count + p.startIndex < p.samples.Length) { p.startIndex = (int)(count + p.startIndex); _packets.Insert(0, p); } else { RemovePacket(p); } } length += count; } average /= (float)targetLength; _movingAverage.Add(average, 0.5f); averageAudio = Mathf.Sqrt(_movingAverage.Value()); //20*Mathf.Log10(Mathf.Sqrt(_movingAverage.Value ()));// (_movingAverage.Value ()); //if(averageAudio<-100)averageAudio=-100; }
void ReadAudio(float[] data, int channels) { if (!Player.IsLoaded() || !Player.IsPlaying() || _paused) { return; } int length = 0; int timeout = 0; float average = 0; int DataLength = data.Length; int srcChannelsCount = 2; int targetLength = DataLength; int channelIndex = 0; int stepSize = 1; while (length < DataLength) { AudioPacket p; lock (_dataMutex) { p = GetExistingPacket(); } if (p == null) { if (!_Process()) { WaitCount++; ++timeout; if (timeout > 20) { break; } } else { timeout = 0; } continue; } srcChannelsCount = p.channelsCount; if (srcChannelsCount == 2 && this.Channel != SourceChannel.Both) { srcChannelsCount = 1; stepSize = 2; channelIndex = (this.Channel == SourceChannel.Left ? 0 : 1); } /* * if (channels == 2 && srcChannelsCount == 1 ) * targetLength = DataLength / 2; * else * targetLength = DataLength;*/ //calculate the left amount of data in this packet int sz = Mathf.Max(0, p.data.Length - p.startIndex); //determine the amount of data we going to use of this packet int count = Mathf.Min(sz, Mathf.Max(0, data.Length - length) /*Remaining data to be filled*/); /* * if (channels == srcChannelsCount) { * for (int i = 0,j=0; i < count; i+=stepSize,++j) { * data [j + length] *= p.data [p.startIndex + i+channelIndex]*Volume; * average += p.data [p.startIndex + i+channelIndex]*p.data [p.startIndex + i+channelIndex]; * } * } else if (channels == 2 && srcChannelsCount == 1) { * for (int i = 0,j=0; i < count;) { * data [2*j + length] *= p.data [p.startIndex + i+channelIndex]*Volume; * data [2*j+ length + 1] *= p.data [p.startIndex + i+channelIndex]*Volume; * average += p.data [p.startIndex + i+channelIndex]*p.data [p.startIndex + i+channelIndex]; * i += stepSize; * j++; * } * } else if (channels == 1 && srcChannelsCount == 2) { * for (int i = 0; i < count; i++) { * data [i + length] *= p.data [p.startIndex + 2 * i]*Volume; * average += p.data [p.startIndex + 2 *i]*p.data [p.startIndex + 2 *i]; * } * }*/ average += GstNetworkAudioPlayer.ProcessAudioPackets(p.data, p.startIndex, channelIndex, count, stepSize, srcChannelsCount, data, length, channels); lock (_dataMutex) { if (count + p.startIndex < p.data.Length) { p.startIndex = count + p.startIndex; _packets.Insert(0, p); } else { RemovePacket(p); } } length += count; } average /= (float)targetLength; _movingAverage.Add(average, 0.5f); averageAudio = Mathf.Sqrt(_movingAverage.Value()); //20*Mathf.Log10(Mathf.Sqrt(_movingAverage.Value ()));// (_movingAverage.Value ()); //if(averageAudio<-100)averageAudio=-100; }