ScummVM API documentation
player_sid.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 SCUMM_PLAYERS_PLAYER_SID_H
23 #define SCUMM_PLAYERS_PLAYER_SID_H
24 
25 #include "common/mutex.h"
26 #include "common/scummsys.h"
27 #include "scumm/music.h"
28 #include "audio/audiostream.h"
29 #include "audio/mixer.h"
30 #include "audio/softsynth/sid.h"
31 
32 namespace Scumm {
33 
34 // the "channel" parameters seem to be in fact SID register
35 // offsets. Should be replaced.
36 enum sid_reg_t {
37  FREQ_VOICE1,
38  FREQ_VOICE2,
39  FREQ_VOICE3,
40  FREQ_FILTER,
41  PULSE_VOICE1,
42  PULSE_VOICE2,
43  PULSE_VOICE3
44 };
45 
46 enum VideoStandard {
47  PAL,
48  NTSC
49 };
50 
51 class ScummEngine;
52 
53 class Player_SID : public Audio::AudioStream, public MusicEngine {
54 public:
55  Player_SID(ScummEngine *scumm, Audio::Mixer *mixer);
56  ~Player_SID() override;
57 
58  void setMusicVolume(int vol) override { _maxvol = vol; }
59  void startSound(int sound) override;
60  void stopSound(int sound) override;
61  void stopAllSounds() override;
62  int getSoundStatus(int sound) const override;
63  int getMusicTimer() override;
64 
65  // AudioStream API
66  int readBuffer(int16 *buffer, const int numSamples) override;
67  bool isStereo() const override { return false; }
68  bool endOfData() const override { return false; }
69  int getRate() const override { return _sampleRate; }
70 
71 private:
72  Resid::SID *_sid;
73  void SID_Write(int reg, uint8 data);
74  void initSID();
75  uint8 *getResource(int resID);
76 
77  // number of cpu cycles until next frame update
78  Resid::cycle_count _cpuCyclesLeft;
79 
80  ScummEngine *_vm;
81  Audio::Mixer *_mixer;
82  Audio::SoundHandle _soundHandle;
83  int _sampleRate;
84  int _maxvol;
85  Common::Mutex _mutex;
86 
87  VideoStandard _videoSystem;
88 
89  int _music_timer;
90  uint8* _music;
91 
92 private:
93  void initMusic(int songResIndex); // $7de6
94  int initSound(int soundResID); // $4D0A
95  void stopSound_intern(int soundResID); // $5093
96  void stopMusic_intern(); // $4CAA
97 
98  void resetSID(); // $48D8
99  void update(); // $481B
100  void handleMusicBuffer();
101  int setupSongFileData(); // $36cb
102  void func_3674(int channel); // $3674
103  void resetPlayerState(); // $48f7
104  void processSongData(int channel); // $4939
105  void readSetSIDFilterAndProps(int *offset, uint8* dataPtr); // $49e7
106  void saveSongPos(int y, int channel);
107  void updateFreq(int channel);
108  void resetFreqDelta(int channel);
109  void readSongChunk(int channel); // $4a6b
110  void setSIDFreqAS(int channel); // $4be6
111  void setSIDWaveCtrlReg(int channel); // $4C0D
112  int setupSongPtr(int channel); // $4C1C
113  void unlockResource(int chanResIndex); // $4CDA
114  void countFreeChannels(); // $4f26
115  void func_4F45(int channel); // $4F45
116  void safeUnlockResource(int resIndex); // $4FEA
117  void releaseResource(int resIndex); // $5031
118  void releaseResChannels(int resIndex); // $5070
119  void releaseResourceUnk(int resIndex); // $50A4
120  void releaseChannel(int channel);
121  void clearSIDWaveform(int channel);
122  void stopChannel(int channel);
123  void swapVars(int channel, int swapIndex); // $51a5
124  void resetSwapVars(); // $52d0
125  void prepareSwapVars(int channel); // $52E5
126  void useSwapVars(int channel); // $5342
127  void lockResource(int resIndex); // $4ff4
128  void reserveChannel(int channel, uint8 prioValue, int chanResIndex); // $4ffe
129  void unlockCodeLocation(); // $513e
130  void lockCodeLocation(); // $514f
131  void func_7eae(int channel, uint8* songFileDataPtr); // $7eae
132  void func_819b(int channel); // $819b
133  void buildStepTbl(int step); // $82B4
134  int reserveSoundFilter(uint8 value, uint8 chanResIndex); // $4ED0
135  int reserveSoundVoice(uint8 value, uint8 chanResIndex); // $4EB8
136  void findLessPrioChannels(uint8 soundPrio); // $4ED8
137  void releaseResourceBySound(int resID); // $5088
138  void readVec6Data(int x, int *offset, uint8 *songFilePtr, int chanResID); // $4E99
139 
140  void unused1(); // $50AF
141 
142  uint8 chanBuffer[3][45];
143 
144  int resID_song;
145 
146  // statusBits1A/1B are always equal
147  uint8 statusBits1A;
148  uint8 statusBits1B;
149 
150  uint8 busyChannelBits;
151 
152  uint8 SIDReg23;
153  uint8 SIDReg23Stuff;
154  uint8 SIDReg24;
155 
156  uint8* chanFileData[3];
157  uint16 chanDataOffset[3];
158  uint8* songPosPtr[7];
159 
160  // 0..2: freq value voice1/2/3
161  // 3: filter freq
162  // 4..6: pulse width
163  uint16 freqReg[7];
164 
165  // start offset[i] for songFileOrChanBufData to obtain songPosPtr[i]
166  // vec6[0..2] = 0x0008;
167  // vec6[4..6] = 0x0019;
168  uint16 vec6[7];
169 
170  // current offset[i] for songFileOrChanBufData to obtain songPosPtr[i] (starts with vec6[i], increased later)
171  uint16 songFileOrChanBufOffset[7];
172 
173  uint16 freqDelta[7];
174  int freqDeltaCounter[7];
175  uint8* swapSongPosPtr[3];
176  uint8* swapVec5[3];
177  uint16 swapVec8[3];
178  uint16 swapVec10[3];
179  uint16 swapFreqReg[3];
180  int swapVec11[3];
181 
182  // never read
183  //uint8* vec5[7];
184  // never read
185  //uint8 vec19[7];
186  // never read (needed by scumm engine?)
187  //bool curChannelActive;
188 
189  uint8* vec20[7];
190 
191  uint8* swapVec20[3];
192 
193  // resource status (never read)
194  // bit7: some flag
195  // bit6..0: counter (use-count?), maybe just bit0 as flag (used/unused?)
196  uint8 resStatus[70];
197 
198  uint8* songFileOrChanBufData;
199  uint8* actSongFileData;
200 
201  uint16 stepTbl[33];
202 
203  bool initializing;
204  bool _soundInQueue;
205  bool isVoiceChannel;
206 
207  bool isMusicPlaying;
208  bool swapVarLoaded;
209  bool bgSoundActive;
210  bool filterUsed;
211 
212  uint8 bgSoundResID;
213  uint8 freeChannelCount;
214 
215  // seems to be used for managing the three voices
216  // bit[0..2]: 0 -> unused, 1 -> already in use
217  uint8 usedChannelBits;
218  uint8 attackReg[3];
219  uint8 sustainReg[3];
220 
221  // -1/0/1
222  int var481A;
223 
224  // bit-array: 00000cba
225  // a/b/c: channel1/2/3
226  uint8 songChannelBits;
227 
228  bool pulseWidthSwapped;
229  bool swapPrepared;
230 
231  // never read
232  //uint8 var5163;
233 
234  bool filterSwapped;
235  uint8 SIDReg24_HiNibble;
236  bool keepSwapVars;
237 
238  uint8 phaseBit[3];
239  bool releasePhase[3];
240 
241  // values: a resID or -1
242  // resIDs: 3, 4, 5 or song-number
243  int _soundQueue[7];
244 
245  // values: a resID or 0
246  // resIDs: 3, 4, 5 or song-number
247  int channelMap[7];
248 
249  uint8 songPosUpdateCounter[7];
250 
251  // priortity of channel contents
252  // MM: 1: lowest .. 120: highest (1,2,A,64,6E,73,78)
253  // Zak: -???: lowest .. 120: highest (5,32,64,65,66,6E,78, A5,A6,AF,D7)
254  uint8 chanPrio[7];
255 
256  // only [0..2] used?
257  uint8 waveCtrlReg[7];
258 
259  uint8 swapAttack[2];
260  uint8 swapSustain[2];
261  uint8 swapSongPrio[3];
262  int swapVec479C[3];
263  uint8 swapVec19[3];
264  uint8 swapSongPosUpdateCounter[3];
265  uint8 swapWaveCtrlReg[3];
266 
267  bool actFilterHasLowerPrio;
268  uint8 chansWithLowerPrioCount;
269  uint8 minChanPrio;
270  uint8 minChanPrioIndex;
271 };
272 
273 } // End of namespace Scumm
274 
275 #endif
int readBuffer(int16 *buffer, const int numSamples) override
void setMusicVolume(int vol) override
Definition: player_sid.h:58
Definition: sid.h:305
int getRate() const override
Definition: player_sid.h:69
Definition: music.h:40
Definition: scumm.h:519
Definition: mixer.h:49
Definition: mixer.h:59
bool endOfData() const override
Definition: player_sid.h:68
Definition: player_sid.h:53
int getMusicTimer() override
Definition: mutex.h:67
Definition: audiostream.h:50
bool isStereo() const override
Definition: player_sid.h:67
void stopSound(int sound) override
void startSound(int sound) override
int getSoundStatus(int sound) const override
Definition: actor.h:30
void stopAllSounds() override