public PanComponent(float value, PanFormulaEnum formula) { value = SynthHelper.Clamp(value, -1f, 1f); switch (formula) { case PanFormulaEnum.Neg3dBCenter: { double dvalue = Synthesizer.HalfPi * (value + 1f) / 2f; Left = (float)Math.Cos(dvalue); Right = (float)Math.Sin(dvalue); } break; case PanFormulaEnum.Neg6dBCenter: { Left = .5f + value * -.5f; Right = .5f + value * .5f; } break; case PanFormulaEnum.ZeroCenter: { double dvalue = Synthesizer.HalfPi * (value + 1.0) / 2.0; Left = (float)(Math.Cos(dvalue) / Synthesizer.InverseSqrtOfTwo); Right = (float)(Math.Sin(dvalue) / Synthesizer.InverseSqrtOfTwo); } break; default: throw new Exception("Invalid pan law selected."); } }
public void SetValue(float value, PanFormulaEnum formula) { value = SynthHelper.ClampF(value, -1, 1); double dvalue; switch (formula) { case PanFormulaEnum.Neg3dBCenter: dvalue = SynthConstants.HalfPi * (value + 1) / 2.0; Left = (float)Math.Cos(dvalue); Right = (float)Math.Sin(dvalue); break; case PanFormulaEnum.Neg6dBCenter: Left = (float)(.5 + value * -.5); Right = (float)(.5 + value * .5); break; case PanFormulaEnum.ZeroCenter: dvalue = SynthConstants.HalfPi * (value + 1.0) / 2.0; Left = (float)(Math.Cos(dvalue) / SynthConstants.InverseSqrtOfTwo); Right = (float)(Math.Sin(dvalue) / SynthConstants.InverseSqrtOfTwo); break; default: throw new Exception("Invalid pan law selected."); } }