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