Exemplo n.º 1
0
		public void Run()
		{
			/*var pm = new PlotModel();
			var xs = Enumerable.Range(0, 1000).Select(x => x / 1000.0).Select(x => -100 + x * 100).ToArray();
			var ys1 = xs.Select(x => Compress(x, ThresholdDb, UpperSlope, 3, true)).ToArray();
			var ys2 = xs.Select(x => Compress(x, ThresholdDb + 6, LowerSlope, 3, true)).ToArray();

			pm.AddLine(xs, ys1);
			pm.AddLine(xs, ys2);
			pm.Show();
			*/
			var pm = new PlotModel();
			pm.Axes.Add(new LinearAxis { Position = AxisPosition.Left, Key = "L" });
			pm.Axes.Add(new LinearAxis { Position = AxisPosition.Right, Key = "R" });
			
			var follower = new EnvelopeFollower(48000, 20);
			var expander = new Expander();
			var slewLimiter = new SlewLimiter(48000);
			follower.SetRelease(ReleaseMs);
			slewLimiter.UpdateDb60(2.0, ReleaseMs);
			expander.Update(ThresholdDb, ReductionDb, UpperSlope);
			var signalValues = new List<double>();
			var followerValues = new List<double>();
			var gainValues = new List<double>();

			var rand = new Random();
			Func<double> random = () => 2 * rand.NextDouble() - 1;
			double decay = 1.0;

			for (int i = 0; i < 20000; i++)
			{
				var x = (Math.Sin(i / fs * 2 * Math.PI * 300) + random() * 0.4) *decay;
				decay *= 0.9998;
				if (i < 1000)
					x = random() * 0.001;
				else if (i > 12000)
				{
					x = random() * 0.001;
				}
				
				signalValues.Add(x);
				follower.ProcessEnvelope(x);
				var env = follower.GetOutput();
				followerValues.Add(env);

				expander.Expand(Utils.Gain2Db(env));
				var gainDb = expander.GetOutput();
				gainDb = slewLimiter.Process(gainDb);
				var gain = Utils.Db2Gain(gainDb);
                gainValues.Add(gain);
			}

			var signalLine = pm.AddLine(signalValues);
			signalLine.Title = "Signal";
			signalLine.YAxisKey = "R";
			//pm.AddLine(followerValues.Select(Utils.Gain2Db)).Title = "followerValues";
			pm.AddLine(gainValues.Select(Utils.Gain2Db)).Title = "gainValues";

			pm.Show();
		}
Exemplo n.º 2
0
        public void TestMethod1()
        {
            var t = new PolyhedrusNative(48000, 12003, 12004);
            var data = t.GetWavetable(0);

            var pm = new PlotModel();
            pm.AddLine(data.WavetableData.Take(20000));
            pm.Show();
        }
Exemplo n.º 3
0
        public void TestMethodSlop()
        {
            var data = new double[48000];
            var dataF = new double[48000];
            var random = new Random(0);

            double sum = 0.0;
            double filter = 0.0;
            var fs = 4800;
            Func<double, double> fcToAlpha = fc => (2 * Math.PI * fc / fs) / (2 * Math.PI * fc / fs + 1);
            var freq = 1.0;
            var samplesPerPoint = (int)(fs / (freq * 10));

            var aHp = fcToAlpha(freq * 0.5);
            var aLp = fcToAlpha(freq * 0.2);

            var scale = 1.0 / samplesPerPoint;
            var sample = 0.0;
            var n = 0;
            for (int i = 0; i < data.Length; i++)
            {
                if (n <= 0)
                {
                    sample = (2 * random.NextDouble() - 1) * scale;
                    n = samplesPerPoint;
                }

                sum += sample;
                filter = filter * (1 - aLp) + aLp * sum;
                data[i] = sum;
                dataF[i] = filter;
                sum *= (1 - aHp);

                n--;
            }

            var pm = new PlotModel();
            pm.AddLine(data);
            pm.AddLine(dataF);
            pm.Show();
        }