source: buchla-68k/orig/RAM/WSCALC.C@ 4f508e6

Last change on this file since 4f508e6 was 3ae31e9, checked in by Thomas Lopatic <thomas@…>, 7 years ago

Imported original source code.

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