public float CalculateVolume() { float num = AudioTools.DBToLinear(_volumeParameter.Get(FabricTimer.Get())); float linear = 1f - (1f - _gain * num); return(AudioTools.LinearToDB(linear)); }
protected override IBGCStream ApplyEffect(IBGCStream input) { using DisposableWaveProvider irFileReader = AudioTools.GetWaveProvider(reverbIRF.FilePath); IBGCStream filter = irFileReader.ToBGCStream().StereoStreamScaler(1.0 / reverbIRF.Gain).SafeCache(); return(input.EnsureMono().MultiConvolve(filter)); }
public void SetValue(float value) { AudioTools.Limit(ref value, _min, _max); float num = 1f / (_max - _min); value *= num; _seekTarget = value; }
public void StretchX(float factor) { for (int i = 0; i < _points.Length; i++) { _points[i]._x *= factor; AudioTools.Limit(ref _points[i]._x, _points[0]._x, _points[_points.Length - 1]._x); } }
public float CalculateNormalisedValue(float value) { AudioTools.Limit(ref value, _min, _max); float num = 1f / (_max - _min); value *= num; return(value); }
private static void DrawMeter(string name, float value, float length) { float db = AudioTools.LinearToDB(value); AudioTools.DBToNormalizedDB(db); GUILayout.BeginVertical("box"); GUILayout.Label(name + ":" + db.ToString("N0") + " dB"); GUILayout.EndVertical(); }
public static byte[] AudioClipRawToByte(float[] samples, bool increaseVolume = false, float volumeMultiplier = 1f) { if (increaseVolume) { samples = AudioTools.IncreaseVolume(samples, volumeMultiplier); } return(FloatToByte(samples)); }
private void Update() { if (!_isInitialised) { _groupComponents = FabricManager.Instance.gameObject.GetComponentsInChildren <GroupComponent>(); _isInitialised = true; } if (_presetList != null) { for (int i = 0; i < _presetList.Length; i++) { Preset preset = _presetList[i]; if (preset.HasEventNameSet() && preset.IsEventActive()) { AddPreset(preset); } } } if (_groupComponents == null) { return; } for (int j = 0; j < _groupComponents.Length; j++) { GroupComponent groupComponent = _groupComponents[j]; float num = 0f; float num2 = 1f; for (int k = 0; k < _activePresets.Count; k++) { Preset preset2 = _activePresets[k]; if (preset2.HasEventNameSet() && !preset2.IsEventActive() && !preset2.IsDeactivating) { preset2.Deactivate(); } if (preset2.IsActive()) { GroupPreset groupComponentByID = preset2.GetGroupComponentByID(groupComponent.GetInstanceID()); if (groupComponentByID != null) { num += groupComponentByID.CalculateVolume(); num2 *= groupComponentByID.CalculatePitch(); } } else { _activePresets.Remove(preset2); } } float value = AudioTools.DBToLinear(num); AudioTools.Limit(ref value, 0f, 1f); groupComponent.MixerVolume = value; groupComponent.MixerPitch = num2; } }
public static byte[] AudioClipToByte(AudioClip clip, bool increaseVolume = false, float volumeMultiplier = 1f) { var samples = new float[clip.samples]; clip.GetData(samples, 0); if (increaseVolume) { samples = AudioTools.IncreaseVolume(samples, volumeMultiplier); } return(FloatToByte(samples)); }
public void MixerSlot(string title, GroupComponent component) { GUILayout.BeginVertical(); GUILayout.BeginVertical(); DisplayCenterText("Pitch"); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); component.Pitch = GUILayout.HorizontalSlider(component.Pitch, -4f, 4f, GUILayout.MinWidth(50f)); GUILayout.Label(component.Pitch.ToString("F")); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUILayout.EndVertical(); GUILayout.BeginHorizontal(GUILayout.MaxHeight(GetActualSize(40f))); GUILayout.FlexibleSpace(); component.Mute = GUILayout.Toggle(component.Mute, "Mute", "button"); bool solo = component.Solo; component.Solo = GUILayout.Toggle(component.Solo, "Solo", "button"); if (component.Solo) { for (int i = 0; i < _soloComponents.Count; i++) { if (_soloComponents[i] != null && _soloComponents[i] != component) { _soloComponents[i].Mute = true; } } } else if (solo != component.Solo) { for (int j = 0; j < _soloComponents.Count; j++) { if (_soloComponents[j] != null && _soloComponents[j] != component) { _soloComponents[j].Mute = false; } } } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUILayout.BeginVertical(); DisplayCenterText("Volume"); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); component.Volume = GUILayout.VerticalSlider(component.Volume, 1f, 0f, GUILayout.MinHeight(100f)); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); DisplayCenterText(AudioTools.LinearToDB(component.Volume).ToString("F") + "dB"); GUILayout.EndVertical(); GUILayout.EndVertical(); }
public void Update() { profiler.Begin(); if (samples != null && audioComponents != null) { Array.Clear(samples, 0, samples.Length); for (int i = 0; i < audioComponents.Length; i++) { AudioComponent audioComponent = audioComponents[i]; if (!(audioComponent != null) || !audioComponent.IsPlaying() || !(audioComponent.AudioSource != null)) { continue; } AudioSource audioSource = audioComponent.AudioSource; if (!audioSource.isPlaying || !(audioComponent.ParentGameObject != null)) { continue; } float num = 0f; if (_is3D) { float distance = 0f; if (listener != null) { distance = (listener.transform.position - audioComponent.ParentGameObject.transform.position).magnitude; } num = distanceAttenuation(distance, audioSource.minDistance, audioSource.maxDistance, audioSource.rolloffMode) * audioSource.volume; } else { num = audioSource.volume; } for (int j = 0; j < 2; j++) { audioSource.GetOutputData(tempSamples, j); for (int k = 0; k < 256; k++) { samples[j, k] += tempSamples[k] * num; } } } VolumeMeterProcess(ref volumeMeterState); } if (_globalParameterName != null) { float db = AudioTools.LinearToDB(volumeMeterState.mRMS); EventManager.Instance._globalParameterManager.SetGlobalParameter(_globalParameterName, AudioTools.DBToNormalizedDB(db)); } profiler.End(); }
static void Main(string[] args) { if (args.Length < 0) { return; } PeakMeter peakMeter1 = new PeakMeter(); Amplifier amplifier = new Amplifier(AudioTools.dBFSToLinearf(12f)); PeakLimiter limiter = new PeakLimiter(20, 20, AudioTools.dBFSToLinearf(-3.0f)); PeakMeter peakMeter2 = new PeakMeter(); FilterChain filterChain = new FilterChain(); filterChain.Filters.Add(peakMeter1); filterChain.Filters.Add(amplifier); filterChain.Filters.Add(limiter); filterChain.Filters.Add(peakMeter2); WaveFileReader waveFileReader = new WaveFileReader(args[0]); waveFileReader.Position = 0; byte[] byteBuffer = new byte[10 * 1024]; float [] floatBuffer = null; int bytesRead = 0, samplesAvailable = 0; filterChain.Init(waveFileReader.WaveFormat.SampleRate, waveFileReader.WaveFormat.Channels); int processed = 0; while (true) { bytesRead = waveFileReader.Read(byteBuffer, 0, 10 * 1024); if (bytesRead == 0) { break; } AudioBufferConverter.ConvertByteArrayToFloatArray(byteBuffer, bytesRead, waveFileReader.WaveFormat.BitsPerSample, ref floatBuffer, ref samplesAvailable); filterChain.ProcessFrames(floatBuffer, samplesAvailable); processed += bytesRead; } System.Console.WriteLine("processed: " + processed); System.Console.WriteLine("peak1: " + peakMeter1.GlobalPeakSinceStartdBFS); System.Console.WriteLine("peak2: " + peakMeter2.GlobalPeakSinceStartdBFS); System.Console.ReadKey(); }
private void DrawSideChain(SideChain sideChain, float length) { GUILayout.BeginVertical("box"); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); GUILayout.Label("SideChain"); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); float db = AudioTools.LinearToDB(1f - sideChain._sideChainGain); AudioTools.DBToNormalizedDB(db); GUILayout.BeginVertical("box"); GUILayout.Label("Gain:" + db.ToString("N0") + " dB"); GUILayout.EndVertical(); GUILayout.EndVertical(); }
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 static void GenerateThumbnail(MediaViewModel mediaViewModel) { switch (mediaViewModel.MediaType) { case MediaType.Photo: ThreadPool.QueueUserWorkItem(delegate { PictureTools.GenerateThumbnailOfPicture(mediaViewModel.AbsoluteURL, mediaViewModel.ID_Media, setImage); }); break; case MediaType.Video: ThreadPool.QueueUserWorkItem(delegate { VideoTools.CaptureScreen(mediaViewModel.AbsoluteURL, mediaViewModel.ID_Media, new TimeSpan(0, 0, 30, 0), "Thumbnail", 0.5, null, setImage); }); break; case MediaType.Musique: ThreadPool.QueueUserWorkItem(delegate { AudioTools.ReadMP3CoverArt(mediaViewModel.AbsoluteURL, mediaViewModel.ID_Media, setImage); }); break; case MediaType.Autre: break; default: throw new ArgumentOutOfRangeException(); } }
void OnCollisionEnter(Collision other) { if (other.gameObject.name == "West Wall") { AudioSource otherAudio = other.gameObject.GetComponent <AudioSource>(); //use the static method FadeOut by passing in the AudioSource and a time for the fade to happen StartCoroutine(AudioTools.FadeOut(otherAudio, 3.0f)); //use the line below to just stop the sound abruptly // otherAudio.Stop (); } if (other.gameObject.name == "East Wall") { AudioSource otherAudio = other.gameObject.GetComponent <AudioSource>(); //use the static method FadeIn by passing in the AudioSource and a time for the fade to happen StartCoroutine(AudioTools.FadeIn(otherAudio, 3.0f)); //use the line below to just start the sound abruptly // otherAudio.Play (); } if (other.gameObject.name == "North Wall") { AudioSource otherAudio = other.gameObject.GetComponent <AudioSource>(); if (otherAudio.isPlaying) { otherAudio.Pause(); } else { otherAudio.Play(); } } }
public void UpdateInternal() { 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); }