source: buchla-68k/ram/wscalc.c@ b28a12e

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

Zero redundant declarations.

  • Property mode set to 100644
File size: 2.6 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 "ram.h"
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*/
24
25void adj(int16_t wshar)
26{
27 register int16_t wspnt;
28 register int32_t harval;
29 register int16_t *kp;
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 =============================================================================
58*/
59
60void wadj(void)
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 =============================================================================
72*/
73
74void 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
88 =============================================================================
89*/
90
91void wscalc(void)
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 }
114
115 /* calculate the scale factor */
116
117 hfac = ((int32_t)WAVESMAX << 16) / hmax;
118
119 /* scale the waveshape */
120
121 for (wspnt = 0; wspnt < NUMWPCAL; wspnt++)
122 wsbuf[wspnt] = (hwave[wspnt] * hfac) >> 16;
123}
124
Note: See TracBrowser for help on using the repository browser.