ScummVM API documentation
ym2149.h
1/* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22#ifndef AUDIO_SOFTSYNTH_YM2149_H
23#define AUDIO_SOFTSYNTH_YM2149_H
24
25#include "audio/ym2149.h"
26
27namespace Audio {
28
29class YM2149Emu : public YM2149::YM2149, public EmulatedChip {
30public:
31 YM2149Emu();
32 ~YM2149Emu() override;
33
34 bool init() override;
35 void reset() override;
36 void writeReg(int reg, uint8 value) override;
37 bool isStereo() const override { return false; }
38
39protected:
40 void generateSamples(int16 *buffer, int numSamples) override;
41
42private:
43 static const int YM_ATARI_CLOCK = 2000000;
44 static const int YM_ATARI_CLOCK_COUNTER = (YM_ATARI_CLOCK / 8);
45
46 static const int YM_BUFFER_250_SIZE = 32768;
47 static const int YM_BUFFER_250_SIZE_MASK = (YM_BUFFER_250_SIZE - 1);
48
49 static const uint32 YmVolume4to5[32];
50
51 static const int ENV_GODOWN = 0;
52 static const int ENV_GOUP = 1;
53 static const int ENV_DOWN = 2;
54 static const int ENV_UP = 3;
55 static const int YmEnvDef[16][3];
56
57 static uint16 YmEnvWaves[16][32 * 3];
58 static const uint16 volumeTable[16][16][16];
59 static uint16 ymout5_u16[32][32][32];
60 static int16 *ymout5;
61 static bool _tablesBuilt;
62
63 static const uint16 YM_MASK_1VOICE = 0x1f;
64 static const uint16 YM_MASK_A = 0x1f;
65 static const uint16 YM_MASK_B = (0x1f << 5);
66 static const uint16 YM_MASK_C = (0x1f << 10);
67
68 static const uint16 YM_SQUARE_UP = 0x1f;
69 static const uint16 YM_SQUARE_DOWN = 0x00;
70
71 uint16 _toneAPer, _toneACount, _toneAVal;
72 uint16 _toneBPer, _toneBCount, _toneBVal;
73 uint16 _toneCPer, _toneCCount, _toneCVal;
74 uint16 _noisePer, _noiseCount, _noiseVal;
75 uint16 _envPer, _envCount;
76
77 uint32 _envPos;
78 int _envShape;
79
80 uint32 _mixerTA, _mixerTB, _mixerTC;
81 uint32 _mixerNA, _mixerNB, _mixerNC;
82
83 uint32 _rndRack;
84 uint16 _freqDiv2;
85
86 uint16 _envMask3Voices;
87 uint16 _vol3Voices;
88
89 uint8 _soundRegs[14];
90
91 int16 _YMBuffer250[YM_BUFFER_250_SIZE];
92 int _YMBuffer250PosWrite;
93 int _YMBuffer250PosRead;
94
95 uint32 _posFractWeightedN;
96 int _rate;
97
98 void setOutputRate(int outputRate);
99 void generate(int16 *dst, int count);
100 static uint16 mergeVoice(uint16 c, uint16 b, uint16 a);
101 static void envBuild();
102 static void interpolateVolumetable(uint16 volumetable[32][32][32]);
103 static void normalise5bitTable(uint16 *in5bit, int16 *out5bit, unsigned int level);
104 static void initOnce();
105 static uint16 tonePer(uint8 rHigh, uint8 rLow);
106 static uint16 noisePer(uint8 rNoise);
107 static uint16 envPer(uint8 rHigh, uint8 rLow);
108 uint32 rndCompute();
109 void doSamples250(int samplesToGenerate250);
110 int16 nextSample();
111};
112
113} // End of namespace Audio
114
115#endif
Definition: chip.h:112
Definition: ym2149.h:29
void generateSamples(int16 *buffer, int numSamples) override
bool init() override
void writeReg(int reg, uint8 value) override
bool isStereo() const override
Definition: ym2149.h:37
void reset() override
Definition: ym2149.h:40
Definition: system.h:39