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