3 This routine implements a common fixed-frequency oscillator
5 This file is part of a program that implements a Software-Defined Radio.
7 Copyright (C) 2004 by Frank Brickle, AB2KT and Bob McGwier, N4HY
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 The authors can be reached by email at
31 The DTTS Microwave Society
38 #define HUGE_PHASE 1256637061.43593
45 if (OSCphase(p) > HUGE_PHASE) OSCphase(p) -= HUGE_PHASE;
47 z = Cmplx(cos(OSCphase(p)), sin(OSCphase(p))),
48 delta_z = Cmplx(cos(OSCfreq(p)), sin(OSCfreq(p)));
50 for (i = 0; i < OSCsize(p); i++)
51 z = CXBdata((CXB) OSCbase(p), i)
53 OSCphase(p) += OSCfreq(p);
60 if (OSCphase(p) > 1256637061.43593)
61 OSCphase(p) -= 1256637061.43593;
62 for (i = 0; i < OSCsize(p); i++) {
63 OSCreal(p, i) = cos(OSCphase(p));
64 OSCimag(p, i) = sin(OSCphase(p));
65 OSCphase(p) += OSCfreq(p);
71 _phasemod(REAL angle) {
72 while (angle >= TWOPI) angle -= TWOPI;
73 while (angle < 0.0) angle += TWOPI;
80 for (i = 0; i < OSCsize(p); i++) {
81 OSCRdata(p, i) = sin(OSCphase(p));
82 OSCphase(p) = _phasemod(OSCfreq(p) + OSCphase(p));
93 OSC p = (OSC) safealloc(1, sizeof(oscillator), tag);
94 if ((OSCtype(p) = TypeOsc) == ComplexTone)
95 OSCbase(p) = (void *) newCXB(size,
97 "complex buffer for oscillator output");
99 OSCbase(p) = (void *) newRLB(size,
101 "real buffer for oscillator output");
103 OSCfreq(p) = 2.0 * M_PI * Frequency / SampleRate;
110 if (p->OscillatorType == ComplexTone)
111 delCXB((CXB) p->signalpoints);
113 delRLB((RLB) p->signalpoints);
115 safefree((char *) p);