Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Radio
- {
- public class Oscillator
- {
- private int _sampleRate;
- private int _frequency;
- private int _phase;
- private float _freqInRad;
- private float _outI;
- private float _outQ;
- public int SampleRate
- {
- get { return _sampleRate; }
- set
- {
- _sampleRate = value;
- _freqInRad = (float)((2.0f * Math.PI * _frequency) / _sampleRate);
- }
- }
- public int Frequency
- {
- get { return _frequency; }
- set
- {
- _frequency = value;
- _freqInRad = (float)((2.0f * Math.PI * _frequency) / _sampleRate);
- }
- }
- public float OutI
- {
- get { return _outI; }
- }
- public float OutQ
- {
- get { return _outQ; }
- }
- public Complex Out
- {
- get { return new Complex(_outI, _outQ); }
- }
- public void Tick()
- {
- _outI = (float) Math.Sin(_freqInRad * _phase);
- _outQ = (float) Math.Cos(_freqInRad * _phase);
- _phase++;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement