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 PCM_COMMON_H 24 #define PCM_COMMON_H 25 26 #include "common/scummsys.h" 27 28 // The SegaCD and the FM-Towns have (almost) the same PCM sound chip. And while each platform has low-level driver 29 // stuff going on top of that it still makes sense to identify and abstract some commmon code. 30 31 class PCMChannel_Base { 32 public: 33 PCMChannel_Base(); 34 virtual ~PCMChannel_Base(); 35 36 virtual void clear(); 37 38 void updateOutput(); 39 int32 currentSampleLeft(); 40 int32 currentSampleRight(); 41 42 virtual bool isPlaying() const = 0; 43 bool isActive() const; 44 void activate(); 45 void deactivate(); 46 47 protected: 48 void setData(const int8 *data, uint32 dataEnd, uint32 dataStart = 0); 49 void setVolume(uint8 vol); 50 void setPanPos(uint8 setPanPos); 51 void setupLoop(uint32 loopStart, uint32 loopLen); 52 void setRate(uint16 rate); 53 54 private: 55 virtual void stopInternal() = 0; 56 57 uint8 _panLeft; 58 uint8 _panRight; 59 uint8 _vol; 60 bool _activeOutput; 61 62 uint32 _loopStart; 63 uint32 _loopLen; 64 uint32 _dataEnd; 65 uint32 _pos; 66 uint16 _step; 67 const int8 *_data; 68 }; 69 70 class PCMDevice_Base { 71 public: 72 PCMDevice_Base(int samplingRate, int deviceVolume, int numChannels); 73 ~PCMDevice_Base(); 74 75 void assignChannel(uint8 id, PCMChannel_Base *const chan); 76 void setMusicVolume(uint16 vol); 77 void setSfxVolume(uint16 vol); 78 void setSfxChanMask(int mask); 79 80 void readBuffer(int32 *buffer, uint32 bufferSize); 81 82 private: 83 const uint32 _intRate; 84 const uint32 _extRate; 85 const int _deviceVolume; 86 uint32 _timer; 87 88 uint16 _musicVolume; 89 uint16 _sfxVolume; 90 int _pcmSfxChanMask; 91 92 PCMChannel_Base **_channels; 93 const int _numChannels; 94 }; 95 96 #endif 97