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