コード例 #1
0
ファイル: PanComponent.cs プロジェクト: zwdesigns/alphaTab
        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.");
            }
        }
コード例 #2
0
ファイル: Tables.cs プロジェクト: zwdesigns/alphaSynth
        private static SampleArray CreateExponentialTable(int size, float coeff)
        {
            coeff = SynthHelper.ClampF(coeff, .001f, .9f);
            var graph = new SampleArray(size);
            var val   = 0.0;

            for (int x = 0; x < size; x++)
            {
                graph[x] = (float)val;
                val     += coeff * ((1 / 0.63) - val);
            }
            for (int x = 0; x < size; x++)
            {
                graph[x] = graph[x] / graph[graph.Length - 1];
            }
            return(graph);
        }
コード例 #3
0
ファイル: Tables.cs プロジェクト: zwdesigns/alphaSynth
        private static SampleArray CreateSquareTable(int size, int k)
        {//Uses Fourier Expansion up to k terms
            var FourOverPi  = 4 / Math.PI;
            var squaretable = new SampleArray(size);
            var inc         = 1.0 / size;
            var phase       = 0.0;

            for (int x = 0; x < size; x++)
            {
                var value = 0.0;
                for (int i = 1; i < k + 1; i++)
                {
                    var twokminus1 = (2 * i) - 1;
                    value += Math.Sin(SynthConstants.TwoPi * (twokminus1) * phase) / (twokminus1);
                }
                squaretable[x] = SynthHelper.ClampF((float)(FourOverPi * value), -1, 1);
                phase         += inc;
            }
            return(squaretable);
        }