Beispiel #1
0
        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);
        }
Beispiel #2
0
        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);
        }