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