public void SetVolume(float targetVolume, float time) { volume = Mathf.Clamp(targetVolume, 0, 100); PDPlayerOld.SendValue(name + suffixes.setVolume, new [] { volume / 100, Mathf.Max(time, 0.05F) * 1000 }); }
IEnumerator ResumeAfterDelay(float delay = 0) { float counter = 0; while (counter < delay) { yield return(new WaitForSeconds(0)); counter += Time.deltaTime; } PDPlayerOld.SendValue(name + suffixes.resume, 1); }
IEnumerator StopAfterDelay(float delay = 0) { float counter = 0; while (counter < delay) { yield return(new WaitForSeconds(0)); counter += Time.deltaTime; } isPlaying = false; PDPlayerOld.SendValue(name + suffixes.stop, 0); }
void Spatialize() { if (source == null) { PDPlayerOld.SendValue(name + "_HRFLeft", 20000); PDPlayerOld.SendValue(name + "_HRFRight", 20000); PDPlayerOld.SendValue(name + "_PanLeft", 1); PDPlayerOld.SendValue(name + "_PanRight", 1); PDPlayerOld.SendValue(name + "_Attenuation", 1); } else { Vector3 listenerToSource = source.transform.position - Instance.listenerTransform.position; float angle = Vector3.Angle(Instance.listenerTransform.right, listenerToSource); float panLeft = (1 - panLevel) + panLevel * Mathf.Sin(Mathf.Max(180 - angle, 90) * Mathf.Deg2Rad); float panRight = (1 - panLevel) + panLevel * Mathf.Sin(Mathf.Max(angle, 90) * Mathf.Deg2Rad); const float fullFrequencyRange = 20000; const float hrfFactor = 1500; float behindFactor = 1 + 4 * (Mathf.Clamp(Vector3.Angle(listenerToSource, Instance.listenerTransform.forward), 90, 135) - 90) / (135 - 90); float hrfLeft = Mathf.Pow(panLeft, 2) * (fullFrequencyRange - hrfFactor) / behindFactor + hrfFactor; float hrfRight = Mathf.Pow(panRight, 2) * (fullFrequencyRange - hrfFactor) / behindFactor + hrfFactor; float distance = Vector3.Distance(source.transform.position, Instance.listenerTransform.position); float adjustedDistance = Mathf.Clamp01(Mathf.Max(distance - minDistance, 0) / Mathf.Max(maxDistance - minDistance, 0.001F)); float attenuation; if (volumeRolloff == RolloffMode.Linear) { attenuation = 1F - adjustedDistance; } else { const float curveDepth = 2; attenuation = Mathf.Pow((1F - Mathf.Pow(adjustedDistance, 1F / curveDepth)), curveDepth); } PDPlayerOld.SendValue(name + "_HRFLeft", hrfLeft); PDPlayerOld.SendValue(name + "_HRFRight", hrfRight); PDPlayerOld.SendValue(name + "_PanLeft", panLeft); PDPlayerOld.SendValue(name + "_PanRight", panRight); PDPlayerOld.SendValue(name + "_Attenuation", attenuation); PDPlayerOld.SendValue(name + "_SourcePosition", source.transform.position); PDPlayerOld.SendValue(name + "_ListenerAngle", angle); PDPlayerOld.SendValue(name + "_ListenerDistance", distance); } changed = false; }
void OnAudioFilterRead(float[] data, int channels) { for (int i = 0; i < data.Length; i++) { pVolume = Mathf.Lerp(pVolume, volume, 0.001F); data[i] *= pVolume; if (sendToPD && initialized) { dataToSend[sendName][i] += data[i]; data[i] = 0; } } if (sendToPD && initialized) { sendCount[sendName] += 1; if (sendCount[sendName] >= sendAmount[sendName]) { PDPlayerOld.SendValue(sendName, dataToSend[sendName]); dataToSend[sendName] = new float[data.Length]; sendCount[sendName] = 0; } } }
public bool SendValue(string sendSuffix, object toSend) { return(PDPlayerOld.SendValue(name + sendSuffix, toSend)); }
public void SetVolume(float targetVolume) { volume = Mathf.Clamp(targetVolume, 0, 100); PDPlayerOld.SendValue(name + suffixes.setVolume, volume / 100); }