1 | /*
|
---|
2 | =============================================================================
|
---|
3 | wscalc.c -- MIDAS-VII waveshape editor harmonic functions
|
---|
4 | Version 9 -- 1988-09-09 -- D.N. Lynx Crowe
|
---|
5 | =============================================================================
|
---|
6 | */
|
---|
7 |
|
---|
8 | #include "stddefs.h"
|
---|
9 | #include "hwdefs.h"
|
---|
10 | #include "graphdef.h"
|
---|
11 | #include "vsdd.h"
|
---|
12 | #include "macros.h"
|
---|
13 |
|
---|
14 | #include "midas.h"
|
---|
15 | #include "wsdsp.h"
|
---|
16 |
|
---|
17 | #define WAVESMAX 1023
|
---|
18 | #define WAVESMIN 1023
|
---|
19 |
|
---|
20 | extern short curwhrm;
|
---|
21 |
|
---|
22 | extern long hwave[NUMWPCAL];
|
---|
23 |
|
---|
24 | extern short offsets[NUMWPCAL];
|
---|
25 | extern short vmtab[NUMHARM];
|
---|
26 | extern short wsbuf[NUMWPCAL];
|
---|
27 |
|
---|
28 | extern long vknm[NUMHARM][NUMWPCAL];
|
---|
29 |
|
---|
30 | #include "knmtab.h" /* short knmtab[NUMHARM][NUMWPCAL]; */
|
---|
31 |
|
---|
32 | /* |
---|
33 |
|
---|
34 | */
|
---|
35 |
|
---|
36 | /*
|
---|
37 | =============================================================================
|
---|
38 | adj() -- adjust the coefficients in vknm[wshar][] for a new value
|
---|
39 | =============================================================================
|
---|
40 | */
|
---|
41 |
|
---|
42 | void adj(short wshar)
|
---|
43 | {
|
---|
44 | register short wspnt;
|
---|
45 | register long harval;
|
---|
46 | register short *kp;
|
---|
47 | register long *vp;
|
---|
48 |
|
---|
49 | vp = &vknm[wshar][0];
|
---|
50 |
|
---|
51 | harval = vmtab[wshar];
|
---|
52 |
|
---|
53 | if (harval) {
|
---|
54 |
|
---|
55 | kp = &knmtab[wshar][0];
|
---|
56 |
|
---|
57 | for (wspnt = 0; wspnt < NUMWPCAL; wspnt++)
|
---|
58 | *vp++ = *kp++ * harval;
|
---|
59 |
|
---|
60 | } else {
|
---|
61 |
|
---|
62 | for (wspnt = 0; wspnt < NUMWPCAL; wspnt++)
|
---|
63 | *vp++ = 0;
|
---|
64 | }
|
---|
65 | }
|
---|
66 |
|
---|
67 | /* |
---|
68 |
|
---|
69 | */
|
---|
70 |
|
---|
71 | /*
|
---|
72 | =============================================================================
|
---|
73 | wadj() -- adjust the coefficients for all harmonics
|
---|
74 | =============================================================================
|
---|
75 | */
|
---|
76 |
|
---|
77 | void wadj(void)
|
---|
78 | {
|
---|
79 | register short wshar;
|
---|
80 |
|
---|
81 | for (wshar = 0; wshar < NUMHARM; wshar++)
|
---|
82 | adj(wshar);
|
---|
83 | }
|
---|
84 |
|
---|
85 | /*
|
---|
86 | =============================================================================
|
---|
87 | clrwsa() -- clear waveshape table harmonic work areas
|
---|
88 | =============================================================================
|
---|
89 | */
|
---|
90 |
|
---|
91 | void clrwsa(void)
|
---|
92 | {
|
---|
93 | memsetw(offsets, 0, NUMWPCAL);
|
---|
94 | memsetw(vknm, 0, (NUMHARM * NUMWPCAL) << 1);
|
---|
95 | memsetw(vmtab, 0, NUMHARM);
|
---|
96 | }
|
---|
97 |
|
---|
98 | /* |
---|
99 |
|
---|
100 | */
|
---|
101 |
|
---|
102 | /*
|
---|
103 | =============================================================================
|
---|
104 | wscalc() -- calculate a waveshape from its harmonics and offsets
|
---|
105 | =============================================================================
|
---|
106 | */
|
---|
107 |
|
---|
108 | void wscalc(void)
|
---|
109 | {
|
---|
110 | register short wspnt, wshar;
|
---|
111 | register long hfac, hmax, temp;
|
---|
112 |
|
---|
113 | hmax = WAVESMIN; /* set minimum scaling value */
|
---|
114 |
|
---|
115 | for (wspnt = 0; wspnt < NUMWPCAL; wspnt++) {
|
---|
116 |
|
---|
117 | temp = 0; /* sum up the harmonics */
|
---|
118 |
|
---|
119 | for (wshar = 0; wshar < NUMHARM; wshar++)
|
---|
120 | temp += vknm[wshar][wspnt];
|
---|
121 |
|
---|
122 | /* add in the offsets */
|
---|
123 |
|
---|
124 | hwave[wspnt] = (temp / 100) + offsets[wspnt];
|
---|
125 |
|
---|
126 | /* adjust the maximum value seen */
|
---|
127 |
|
---|
128 | if ((temp = abs(hwave[wspnt])) > hmax)
|
---|
129 | hmax = temp;
|
---|
130 | }
|
---|
131 |
|
---|
132 | /* calculate the scale factor */
|
---|
133 |
|
---|
134 | hfac = ((long)WAVESMAX << 16) / hmax;
|
---|
135 |
|
---|
136 | /* scale the waveshape */
|
---|
137 |
|
---|
138 | for (wspnt = 0; wspnt < NUMWPCAL; wspnt++)
|
---|
139 | wsbuf[wspnt] = (hwave[wspnt] * hfac) >> 16;
|
---|
140 | }
|
---|