[3ae31e9] | 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 | adj(wshar)
|
---|
| 43 | register short wshar;
|
---|
| 44 | {
|
---|
| 45 | register short wspnt;
|
---|
| 46 | register long harval;
|
---|
| 47 | register short *kp;
|
---|
| 48 | register long *vp;
|
---|
| 49 |
|
---|
| 50 | vp = &vknm[wshar][0];
|
---|
| 51 |
|
---|
| 52 | harval = vmtab[wshar];
|
---|
| 53 |
|
---|
| 54 | if (harval) {
|
---|
| 55 |
|
---|
| 56 | kp = &knmtab[wshar][0];
|
---|
| 57 |
|
---|
| 58 | for (wspnt = 0; wspnt < NUMWPCAL; wspnt++)
|
---|
| 59 | *vp++ = *kp++ * harval;
|
---|
| 60 |
|
---|
| 61 | } else {
|
---|
| 62 |
|
---|
| 63 | for (wspnt = 0; wspnt < NUMWPCAL; wspnt++)
|
---|
| 64 | *vp++ = 0;
|
---|
| 65 | }
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | /* |
---|
| 69 |
|
---|
| 70 | */
|
---|
| 71 |
|
---|
| 72 | /*
|
---|
| 73 | =============================================================================
|
---|
| 74 | wadj() -- adjust the coefficients for all harmonics
|
---|
| 75 | =============================================================================
|
---|
| 76 | */
|
---|
| 77 |
|
---|
| 78 | wadj()
|
---|
| 79 | {
|
---|
| 80 | register short wshar;
|
---|
| 81 |
|
---|
| 82 | for (wshar = 0; wshar < NUMHARM; wshar++)
|
---|
| 83 | adj(wshar);
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 | /*
|
---|
| 87 | =============================================================================
|
---|
| 88 | clrwsa() -- clear waveshape table harmonic work areas
|
---|
| 89 | =============================================================================
|
---|
| 90 | */
|
---|
| 91 |
|
---|
| 92 | clrwsa()
|
---|
| 93 | {
|
---|
| 94 | memsetw(offsets, 0, NUMWPCAL);
|
---|
| 95 | memsetw(vknm, 0, (NUMHARM * NUMWPCAL) << 1);
|
---|
| 96 | memsetw(vmtab, 0, NUMHARM);
|
---|
| 97 | }
|
---|
| 98 |
|
---|
| 99 | /* |
---|
| 100 |
|
---|
| 101 | */
|
---|
| 102 |
|
---|
| 103 | /*
|
---|
| 104 | =============================================================================
|
---|
| 105 | wscalc() -- calculate a waveshape from its harmonics and offsets
|
---|
| 106 | =============================================================================
|
---|
| 107 | */
|
---|
| 108 |
|
---|
| 109 | wscalc()
|
---|
| 110 | {
|
---|
| 111 | register short wspnt, wshar;
|
---|
| 112 | register long hfac, hmax, temp;
|
---|
| 113 |
|
---|
| 114 | hmax = WAVESMIN; /* set minimum scaling value */
|
---|
| 115 |
|
---|
| 116 | for (wspnt = 0; wspnt < NUMWPCAL; wspnt++) {
|
---|
| 117 |
|
---|
| 118 | temp = 0; /* sum up the harmonics */
|
---|
| 119 |
|
---|
| 120 | for (wshar = 0; wshar < NUMHARM; wshar++)
|
---|
| 121 | temp += vknm[wshar][wspnt];
|
---|
| 122 |
|
---|
| 123 | /* add in the offsets */
|
---|
| 124 |
|
---|
| 125 | hwave[wspnt] = (temp / 100) + offsets[wspnt];
|
---|
| 126 |
|
---|
| 127 | /* adjust the maximum value seen */
|
---|
| 128 |
|
---|
| 129 | if ((temp = abs(hwave[wspnt])) > hmax)
|
---|
| 130 | hmax = temp;
|
---|
| 131 | }
|
---|
| 132 |
|
---|
| 133 | /* calculate the scale factor */
|
---|
| 134 |
|
---|
| 135 | hfac = ((long)WAVESMAX << 16) / hmax;
|
---|
| 136 |
|
---|
| 137 | /* scale the waveshape */
|
---|
| 138 |
|
---|
| 139 | for (wspnt = 0; wspnt < NUMWPCAL; wspnt++)
|
---|
| 140 | wsbuf[wspnt] = (hwave[wspnt] * hfac) >> 16;
|
---|
| 141 | }
|
---|