Debian Codegraph @

src/engine/platform/sound/su.h

raw
1 /* su.cpp/su.h - Sound Unit emulator
2 * Copyright (C) 2015-2023 tildearrow
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in all
12 * copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 */
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <math.h>
25
26 class SoundUnit {
27 signed char SCsine[256];
28 signed char SCtriangle[256];
29 signed char SCpantabL[256];
30 signed char SCpantabR[256];
31 unsigned int ocycle[8];
32 unsigned int cycle[8];
33 int rcycle[8];
34 unsigned int lfsr[8];
35 signed char ns[8];
36 short fns[8];
37 short nsL[8];
38 short nsR[8];
39 short nslow[8];
40 short nshigh[8];
41 short nsband[8];
42 int tnsL, tnsR;
43 unsigned char ilBufPeriod;
44 unsigned short ilBufPos;
45 signed char ilFeedback0;
46 signed char ilFeedback1;
47 unsigned short oldfreq[8];
48 unsigned int pcmSize;
49 bool dsOut;
50 unsigned char dsChannel;
51 public:
52 unsigned short resetfreq[8];
53 unsigned short voldcycles[8];
54 unsigned short volicycles[8];
55 unsigned short fscycles[8];
56 unsigned char sweep[8];
57 unsigned short swvolt[8];
58 unsigned short swfreqt[8];
59 unsigned short swcutt[8];
60 unsigned short pcmdec[8];
61 struct SUChannel {
62 unsigned short freq;
63 signed char vol;
64 signed char pan;
65 unsigned char flags0;
66 unsigned char flags1;
67 unsigned short cutoff;
68 unsigned char duty;
69 unsigned char reson;
70 unsigned short pcmpos;
71 unsigned short pcmbnd;
72 unsigned short pcmrst;
73 struct {
74 unsigned short speed;
75 unsigned char amt;
76 unsigned char bound;
77 } swfreq;
78 struct {
79 unsigned short speed;
80 unsigned char amt;
81 unsigned char bound;
82 } swvol;
83 struct {
84 unsigned short speed;
85 unsigned char amt;
86 unsigned char bound;
87 } swcut;
88 unsigned char special1C;
89 unsigned char special1D;
90 unsigned short restimer;
91 } chan[8];
92 signed char pcm[65536];
93 bool muted[8];
94 void SetIL0(unsigned char addr);
95 void Write(unsigned char addr, unsigned char data);
96 void NextSample(short* l, short* r);
97 inline int GetSample(int ch) {
98 int ret=(nsL[ch]+nsR[ch])>>1;
99 if (ret<-32768) ret=-32768;
100 if (ret>32767) ret=32767;
101 return ret;
102 }
103 void Init(int sampleMemSize=8192, bool dsOutMode=false);
104 void Reset();
105 SoundUnit();
106 };