[f40a309] | 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 |
|
---|
[7258c6a] | 20 | extern int16_t curwhrm;
|
---|
[f40a309] | 21 |
|
---|
[7258c6a] | 22 | extern int32_t hwave[NUMWPCAL];
|
---|
[f40a309] | 23 |
|
---|
[7258c6a] | 24 | extern int16_t offsets[NUMWPCAL];
|
---|
| 25 | extern int16_t vmtab[NUMHARM];
|
---|
| 26 | extern int16_t wsbuf[NUMWPCAL];
|
---|
[f40a309] | 27 |
|
---|
[7258c6a] | 28 | extern int32_t vknm[NUMHARM][NUMWPCAL];
|
---|
[f40a309] | 29 |
|
---|
| 30 | #include "knmtab.h" /* short knmtab[NUMHARM][NUMWPCAL]; */
|
---|
| 31 |
|
---|
[e225e77] | 32 | #include "memory.h"
|
---|
| 33 |
|
---|
[f40a309] | 34 | /* |
---|
| 35 |
|
---|
| 36 | */
|
---|
| 37 |
|
---|
| 38 | /*
|
---|
| 39 | =============================================================================
|
---|
| 40 | adj() -- adjust the coefficients in vknm[wshar][] for a new value
|
---|
| 41 | =============================================================================
|
---|
| 42 | */
|
---|
[7258c6a] | 43 |
|
---|
[f40a309] | 44 | void adj(int16_t wshar)
|
---|
[7258c6a] | 45 | {
|
---|
| 46 | register int16_t wspnt;
|
---|
| 47 | register int32_t harval;
|
---|
| 48 | register int16_t *kp;
|
---|
[f40a309] | 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 | =============================================================================
|
---|
[0580615] | 77 | */
|
---|
[f40a309] | 78 |
|
---|
[7258c6a] | 79 | void wadj(void)
|
---|
[f40a309] | 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 | =============================================================================
|
---|
[0580615] | 91 | */
|
---|
[f40a309] | 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
|
---|
[0580615] | 107 | =============================================================================
|
---|
[f40a309] | 108 | */
|
---|
[7258c6a] | 109 |
|
---|
| 110 | void wscalc(void)
|
---|
[f40a309] | 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 | }
|
---|
[7258c6a] | 133 |
|
---|
[f40a309] | 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 | }
|
---|