Advertisement
Guest User

Untitled

a guest
Sep 27th, 2013
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.98 KB | None | 0 0
  1. #region usings
  2. using System;
  3. using System.ComponentModel.Composition;
  4.  
  5. using VVVV.PluginInterfaces.V1;
  6. using VVVV.PluginInterfaces.V2;
  7. using VVVV.Utils.VColor;
  8. using VVVV.Utils.VMath;
  9.  
  10. using VVVV.Core.Logging;
  11. #endregion usings
  12.  
  13. namespace VVVV.Nodes
  14. {
  15.     public abstract class ValueFilterNode : IPluginEvaluate
  16.     {
  17.         [Input("Input")]
  18.         public ISpread<double> FInput;
  19.        
  20.         [Input("Period")]
  21.         public ISpread<double> FPeriodIn;
  22.  
  23.         [Output("Output")]
  24.         public ISpread<double> FOutput;
  25.  
  26.         [Import]
  27.         protected IHDEHost FHost;
  28.         private Spread<double> FPreviousInput = new Spread<double>(1);
  29.         private Spread<double> FPreviousOutput = new Spread<double>(1);
  30.         private double FTime;
  31.  
  32.         public void Evaluate(int spreadMax)
  33.         {
  34.             var time = FHost.FrameTime;
  35.             var deltaTime = (time - FTime) * 2 * Math.PI;
  36.             FTime = time;
  37.            
  38.             FOutput.SliceCount = spreadMax;
  39.             for (int i = 0; i < spreadMax; i++)
  40.             {
  41.                 FOutput[i] = Filter(
  42.                     deltaTime,
  43.                     FPeriodIn[i],
  44.                     FInput[i],
  45.                     FPreviousInput[i],
  46.                     FPreviousOutput[i]
  47.                 );
  48.             }
  49.            
  50.             FPreviousInput.AssignFrom(FInput);
  51.             FPreviousOutput.AssignFrom(FOutput);
  52.         }
  53.        
  54.         protected abstract double Filter(double deltaTime, double rc, double x, double oldX, double y);
  55.     }
  56.    
  57.     [PluginInfo(Name = "HighPassFilter", Category = "Value", Credits = "http://en.wikipedia.org/wiki/High-pass_filter")]
  58.     public class ValueHighPassFilterNode : ValueFilterNode
  59.     {
  60.         protected override double Filter(double deltaTime, double rc, double x, double oldX, double y)
  61.         {
  62.             var alpha = rc / (rc + deltaTime);
  63.             return alpha * (y + x - oldX);
  64.         }
  65.     }
  66.    
  67.     [PluginInfo(Name = "LowPassFilter", Category = "Value", Credits = "http://en.wikipedia.org/wiki/Low-pass_filter")]
  68.     public class ValueLowPassFilterNode : ValueFilterNode
  69.     {
  70.         protected override double Filter(double deltaTime, double rc, double x, double oldX, double y)
  71.         {
  72.             var alpha = deltaTime / (rc + deltaTime);
  73.             return y + alpha * (x - y);
  74.         }
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement