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_SMUSH_CHANNEL_H 24 #define SCUMM_SMUSH_CHANNEL_H 25 26 #include "common/util.h" 27 28 namespace Common { 29 class SeekableReadStream; 30 } 31 32 namespace Scumm { 33 34 class SmushChannel { 35 protected: 36 int32 _track; ///< the track number 37 byte *_tbuffer; ///< data temporary buffer 38 int32 _tbufferSize; ///< temporary buffer size 39 byte *_sbuffer; ///< sound buffer 40 int32 _sbufferSize; ///< sound buffer size 41 42 int32 _dataSize; ///< remaining size of sound data in the iMUS buffer 43 44 bool _inData; 45 46 int32 _volume; 47 int32 _pan; 48 49 void processBuffer(); 50 51 virtual bool handleSubTags(int32 &offset) = 0; 52 53 public: 54 SmushChannel(int32 track); 55 virtual ~SmushChannel(); 56 virtual bool appendData(Common::SeekableReadStream &b, int32 size) = 0; 57 virtual bool setParameters(int32, int32, int32, int32, int32) = 0; 58 virtual bool checkParameters(int32, int32, int32, int32, int32) = 0; 59 virtual bool isTerminated() const = 0; 60 virtual byte *getSoundData() = 0; 61 virtual int32 getRate() = 0; 62 virtual bool getParameters(bool &stereo, bool &is_16bit, int32 &vol, int32 &pan) = 0; 63 getAvailableSoundDataSize()64 int32 getAvailableSoundDataSize() const { return _sbufferSize; } getTrackIdentifier()65 int32 getTrackIdentifier() const { return _track; } 66 }; 67 68 class SaudChannel : public SmushChannel { 69 private: 70 int32 _nbframes; 71 bool _markReached; 72 int32 _flags; 73 int32 _index; 74 bool _keepSize; 75 76 protected: 77 bool handleSubTags(int32 &offset) override; 78 79 public: 80 SaudChannel(int32 track); 81 bool isTerminated() const override; 82 bool setParameters(int32 duration, int32 flags, int32 vol1, int32 vol2, int32 index) override; 83 bool checkParameters(int32 index, int32 duration, int32 flags, int32 vol1, int32 vol2) override; 84 bool appendData(Common::SeekableReadStream &b, int32 size) override; 85 byte *getSoundData() override; getRate()86 int32 getRate() override { return 22050; } getParameters(bool & stereo,bool & is_16bit,int32 & vol,int32 & pan)87 bool getParameters(bool &stereo, bool &is_16bit, int32 &vol, int32 &pan) override { 88 stereo = false; 89 is_16bit = false; 90 vol = _volume; 91 pan = _pan; 92 return true; 93 } 94 }; 95 96 class ImuseChannel : public SmushChannel { 97 private: 98 int32 _srbufferSize; 99 100 int32 _bitsize; ///< the bitsize of the original data 101 int32 _rate; ///< the sampling rate of the original data 102 int32 _channels; ///< the number of channels of the original data 103 104 protected: 105 void decode(); 106 bool handleMap(byte *data); 107 bool handleSubTags(int32 &offset) override; 108 109 public: 110 ImuseChannel(int32 track); 111 bool isTerminated() const override; 112 bool setParameters(int32 nbframes, int32 size, int32 track_flags, int32 unk1, int32) override; 113 bool checkParameters(int32 index, int32 nbframes, int32 size, int32 track_flags, int32 unk1) override; 114 bool appendData(Common::SeekableReadStream &b, int32 size) override; 115 byte *getSoundData() override; getRate()116 int32 getRate() override { return _rate; } getParameters(bool & stereo,bool & is_16bit,int32 & vol,int32 & pan)117 bool getParameters(bool &stereo, bool &is_16bit, int32 &vol, int32 &pan) override { 118 stereo = (_channels == 2); 119 is_16bit = (_bitsize > 8); 120 vol = _volume; 121 pan = _pan; 122 return true; 123 } 124 }; 125 126 } // End of namespace Scumm 127 128 #endif 129