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