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