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

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

Removed form-feed comments.

  • Property mode set to 100644
File size: 2.5 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 adj() -- adjust the coefficients in vknm[wshar][] for a new value
18 =============================================================================
19*/
20
21void adj(int16_t wshar)
22{
23 register int16_t wspnt;
24 register int32_t harval;
25 register int16_t *kp;
26 register int32_t *vp;
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
52void wadj(void)
53{
54 register int16_t wshar;
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
66void clrwsa(void)
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
79void wscalc(void)
80{
81 register int16_t wspnt, wshar;
82 register int32_t hfac, hmax, temp;
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
105 hfac = ((int32_t)WAVESMAX << 16) / hmax;
106
107 /* scale the waveshape */
108
109 for (wspnt = 0; wspnt < NUMWPCAL; wspnt++)
110 wsbuf[wspnt] = (hwave[wspnt] * hfac) >> 16;
111}
112
Note: See TracBrowser for help on using the repository browser.