ScummVM API documentation
chip.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 AUDIO_CHIP_H
23 #define AUDIO_CHIP_H
24 
25 #include "common/func.h"
26 #include "common/ptr.h"
27 
28 #include "audio/audiostream.h"
29 
30 namespace Audio {
31 class SoundHandle;
32 
33 class Chip {
34 public:
35  virtual ~Chip() {}
36 
41 
45  void start(TimerCallback *callback, int timerFrequency);
46 
50  void stop();
51 
56  virtual void setCallbackFrequency(int timerFrequency) = 0;
57 
58 protected:
62  virtual void startCallbacks(int timerFrequency) = 0;
63 
67  virtual void stopCallbacks() = 0;
68 
73 };
74 
81 class RealChip : virtual public Chip {
82 public:
83  RealChip();
84  virtual ~RealChip();
85 
86  // Chip API
87  void setCallbackFrequency(int timerFrequency);
88 
89 protected:
90  // Chip API
91  void startCallbacks(int timerFrequency);
92  void stopCallbacks();
93  virtual void onTimer();
94 
95 private:
96  static void timerProc(void *refCon);
97 
98  uint _baseFreq;
99  uint _remainingTicks;
100 
101  enum {
102  kMaxFreq = 100
103  };
104 };
105 
112 class EmulatedChip : virtual public Chip, protected Audio::AudioStream {
113 protected:
114  static const int FIXP_SHIFT = 16;
115 
116 public:
117  EmulatedChip();
118  virtual ~EmulatedChip();
119 
120  // Chip API
121  void setCallbackFrequency(int timerFrequency) override;
122 
123  // AudioStream API
124  int readBuffer(int16 *buffer, const int numSamples) override;
125  int getRate() const override;
126  bool endOfData() const override { return false; }
127 
128 protected:
129  // Chip API
130  void startCallbacks(int timerFrequency) override final;
131  void stopCallbacks() override final;
132 
143  virtual void generateSamples(int16 *buffer, int numSamples) = 0;
144 
145 private:
146  int _baseFreq;
147 
148  int _nextTick;
149  int _samplesPerTick;
150 
151  Audio::SoundHandle *_handle;
152 };
153 
154 } // End of namespace Audio
155 
156 #endif
Common::Functor0< void > TimerCallback
Definition: chip.h:40
void start(TimerCallback *callback, int timerFrequency)
Definition: ptr.h:572
Definition: mixer.h:49
virtual void stopCallbacks()=0
Definition: chip.h:33
Common::ScopedPtr< TimerCallback > _callback
Definition: chip.h:72
bool endOfData() const override
Definition: chip.h:126
Definition: audiostream.h:50
virtual void startCallbacks(int timerFrequency)=0
Definition: chip.h:112
virtual void setCallbackFrequency(int timerFrequency)=0
Definition: chip.h:81
Definition: system.h:38