ScummVM API documentation
ay8912.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_AY8912_H
23#define AUDIO_SOFTSYNTH_AY8912_H
24
25#include "audio/chip.h"
26#include "common/mutex.h"
27
28namespace Audio {
29
30class AY8912Stream : public EmulatedChip {
31public:
32 enum ChipType {
33 AY_TYPE_AY,
34 AY_TYPE_YM
35 };
36
37 enum StereoType {
38 AY_MONO = 0,
39 AY_ABC,
40 AY_ACB,
41 AY_BAC,
42 AY_BCA,
43 AY_CAB,
44 AY_CBA
45 };
46
47 AY8912Stream(int rate = 44100, int chipFreq = 1773400);
49
50 // AudioStream interface
51 int readBuffer(int16 *buffer, const int numSamples) override;
52 bool isStereo() const override { return true; }
53 bool endOfData() const override { return false; }
54 bool endOfStream() const override { return false; }
55 int getRate() const override { return _rate; }
56
57 void setReg(int reg, unsigned char value);
58 void setRegs(const unsigned char *regs);
59
60 AudioStream *toAudioStream() { return this; }
61
62protected:
63 // EmulatedChip interface
64 void generateSamples(int16 *buffer, int numSamples) override;
65
66private:
67 struct RegData {
68 int tone_a;
69 int tone_b;
70 int tone_c;
71 int noise;
72 int R7_tone_a;
73 int R7_tone_b;
74 int R7_tone_c;
75 int R7_noise_a;
76 int R7_noise_b;
77 int R7_noise_c;
78 int vol_a;
79 int vol_b;
80 int vol_c;
81 int env_a;
82 int env_b;
83 int env_c;
84 int env_freq;
85 int env_style;
86 };
87
88 Common::Mutex _mutex;
89 int _rate;
90 int _chipFreq;
91
92 // Emulator state
93 int _table[32];
94 int _eq[6];
95 RegData _regs;
96
97 int _bit_a, _bit_b, _bit_c, _bit_n;
98 int _cnt_a, _cnt_b, _cnt_c, _cnt_n, _cnt_e;
99 int _chipTactsPerOutcount;
100 int _ampGlobal;
101 int _vols[6][32];
102 int _envPos;
103 unsigned int _curSeed;
104
105 void prepareGeneration();
106 static void genEnv();
107 static bool _envGenInit;
108 static int _envelope[16][128];
109};
110
111} // End of namespace Audio
112
113#endif // AUDIO_SOFTSYNTH_AY8912_H
Definition: ay8912.h:30
bool endOfData() const override
Definition: ay8912.h:53
int readBuffer(int16 *buffer, const int numSamples) override
bool endOfStream() const override
Definition: ay8912.h:54
int getRate() const override
Definition: ay8912.h:55
bool isStereo() const override
Definition: ay8912.h:52
void generateSamples(int16 *buffer, int numSamples) override
Definition: audiostream.h:50
Definition: chip.h:112
Definition: mutex.h:67
Definition: system.h:39