ScummVM API documentation
player_nes.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_NES_H
23 #define SCUMM_PLAYERS_PLAYER_NES_H
24 
25 #include "common/scummsys.h"
26 #include "scumm/music.h"
27 #include "audio/audiostream.h"
28 #include "audio/mixer.h"
29 
30 namespace Scumm {
31 
32 class ScummEngine;
33 namespace APUe {
34 class APU;
35 }
36 
37 static const int MAXVOLUME = 0x7F;
38 static const int NUMSLOTS = 3;
39 static const int NUMCHANS = 4;
40 
44 class Player_NES : public Audio::AudioStream, public MusicEngine {
45 public:
46  Player_NES(ScummEngine *scumm, Audio::Mixer *mixer);
47  ~Player_NES() override;
48 
49  void setMusicVolume(int vol) override;
50  void startSound(int sound) override;
51  void stopSound(int sound) override;
52  void stopAllSounds() override;
53  int getSoundStatus(int sound) const override;
54 
55  // AudioStream API
56  int readBuffer(int16 *buffer, const int numSamples) override;
57  bool isStereo() const override { return false; }
58  bool endOfData() const override { return false; }
59  int getRate() const override { return _sampleRate; }
60 
61 private:
62 
63  void sound_play();
64  void playSFX(int nr);
65  void playMusic();
66  byte fetchSoundByte(int nr);
67  void chainCommand(int chan);
68  void checkSilenceChannels(int chan);
69 
70  void APU_writeChannel(int chan, int offset, byte value);
71  void APU_writeControl(byte value);
72  byte APU_readStatus();
73 
74  ScummEngine *_vm;
75  Audio::Mixer *_mixer;
76  Audio::SoundHandle _soundHandle;
77  APUe::APU *_apu;
78  int _sampleRate;
79  int _samples_per_frame;
80  int _current_sample;
81  int _maxvol;
82 
83  struct slot {
84  int framesleft;
85  int id;
86  int type;
87  byte *data;
88  int offset;
89  } _slot[NUMSLOTS];
90 
91  struct mchan {
92  int command;
93  int framedelay;
94  int pitch;
95  int volume;
96  int voldelta;
97  int envflags;
98  int cmdlock;
99  } _mchan[NUMCHANS];
100 
101  bool isSFXplaying, wasSFXplaying;
102 
103  byte *dataStart;
104  int numNotes;
105  byte *auxData1;
106  byte *auxData2;
107 
108  byte *soundptr;
109 };
110 
111 } // End of namespace Scumm
112 
113 #endif
Definition: music.h:40
bool isStereo() const override
Definition: player_nes.h:57
Definition: scumm.h:518
Definition: mixer.h:49
Definition: mixer.h:59
Definition: player_nes.h:44
Definition: audiostream.h:50
int getRate() const override
Definition: player_nes.h:59
Definition: actor.h:30
bool endOfData() const override
Definition: player_nes.h:58