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

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

Added include files for global functions and variables.

  • Property mode set to 100644
File size: 2.8 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 "all.h"
9
10#define WAVESMAX 1023
11#define WAVESMIN 1023
12
13extern int16_t curwhrm;
14
15extern int32_t hwave[NUMWPCAL];
16
17extern int16_t offsets[NUMWPCAL];
18extern int16_t vmtab[NUMHARM];
19extern int16_t wsbuf[NUMWPCAL];
20
21extern int32_t vknm[NUMHARM][NUMWPCAL];
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*/
34
35void adj(int16_t wshar)
36{
37 register int16_t wspnt;
38 register int32_t harval;
39 register int16_t *kp;
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 =============================================================================
68*/
69
70void wadj(void)
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 =============================================================================
82*/
83
84void 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
98 =============================================================================
99*/
100
101void wscalc(void)
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 }
124
125 /* calculate the scale factor */
126
127 hfac = ((int32_t)WAVESMAX << 16) / hmax;
128
129 /* scale the waveshape */
130
131 for (wspnt = 0; wspnt < NUMWPCAL; wspnt++)
132 wsbuf[wspnt] = (hwave[wspnt] * hfac) >> 16;
133}
134
Note: See TracBrowser for help on using the repository browser.