Advertisement
prog

Oscillator

Jul 24th, 2011
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.25 KB | None | 0 0
  1.  
  2. using System;
  3.  
  4. namespace Radio
  5. {
  6.     public class Oscillator
  7.     {
  8.         private int _sampleRate;
  9.         private int _frequency;
  10.         private int _phase;
  11.         private float _freqInRad;
  12.         private float _outI;
  13.         private float _outQ;
  14.  
  15.         public int SampleRate
  16.         {
  17.             get { return _sampleRate; }
  18.             set
  19.             {
  20.                 _sampleRate = value;
  21.                 _freqInRad = (float)((2.0f * Math.PI * _frequency) / _sampleRate);
  22.             }
  23.         }
  24.  
  25.         public int Frequency
  26.         {
  27.             get { return _frequency; }
  28.             set
  29.             {
  30.                 _frequency = value;
  31.                 _freqInRad = (float)((2.0f * Math.PI * _frequency) / _sampleRate);
  32.             }
  33.         }
  34.  
  35.         public float OutI
  36.         {
  37.             get { return _outI; }
  38.         }
  39.  
  40.         public float OutQ
  41.         {
  42.             get { return _outQ; }
  43.         }
  44.  
  45.         public Complex Out
  46.         {
  47.             get { return new Complex(_outI, _outQ); }
  48.         }
  49.  
  50.         public void Tick()
  51.         {
  52.             _outI = (float) Math.Sin(_freqInRad * _phase);
  53.             _outQ = (float) Math.Cos(_freqInRad * _phase);
  54.             _phase++;
  55.         }
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement