ScummVM API documentation
sound_pcjr.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 AGI_SOUND_PCJR_H
23 #define AGI_SOUND_PCJR_H
24 
25 #include "audio/audiostream.h"
26 
27 namespace Agi {
28 
29 #define CHAN_MAX 4
30 
31 #define SAMPLE_RATE 22050
32 
33 enum GenType {
34  kGenSilence,
35  kGenTone,
36  kGenPeriod,
37  kGenWhite
38 };
39 
40 struct SndGenChan {
41  const byte *data;
42  uint16 duration;
43  uint16 avail; // turned on (1) but when the channel's data runs out, it's set to (0)
44  uint16 dissolveCount;
45  byte attenuation;
46  byte attenuationCopy;
47 
48  GenType genType;
49 
50  // for the sample mixer
51  int freqCount;
52 };
53 
54 struct ToneChan {
55  int avail;
56 
57  int noteCount; // length of tone.. duration
58 
59  int freqCount;
60  int freqCountPrev;
61  int atten; // volume
62 
63  GenType genType;
64  int genTypePrev;
65 
66  int count;
67  int scale;
68  int sign;
69  unsigned int noiseState; /* noise generator */
70  int feedback; /* noise feedback mask */
71 };
72 
73 class SoundGenPCJr : public SoundGen, public Audio::AudioStream {
74 public:
75  SoundGenPCJr(AgiBase *vm, Audio::Mixer *pMixer);
76  ~SoundGenPCJr() override;
77 
78  void play(int resnum) override;
79  void stop() override;
80 
81  // AudioStream API
82  int readBuffer(int16 *buffer, const int numSamples) override;
83 
84  bool isStereo() const override {
85  return false;
86  }
87 
88  bool endOfData() const override {
89  return false;
90  }
91 
92  int getRate() const override {
93  // FIXME: Ideally, we should use _sampleRate.
94  return 22050;
95  }
96 
97 private:
98  int getNextNote(int ch);
99  int getNextNote_v2(int ch);
100  int getNextNote_v1(int ch);
101  int volumeCalc(SndGenChan *chan);
102 
103  void writeData(uint8 val);
104 
105  int chanGen(int chan, int16 *stream, int len);
106 
107  int fillNoise(ToneChan *t, int16 *buf, int len);
108  int fillSquare(ToneChan *t, int16 *buf, int len);
109 
110 private:
111  Common::Mutex _mutex;
112 
113  SndGenChan _channel[CHAN_MAX];
114  ToneChan _tchannel[CHAN_MAX];
115  int16 *_chanData;
116  int _chanAllocated;
117 
118  int _dissolveMethod;
119 
120  uint8 *_v1data;
121  uint32 _v1size;
122  int _v1duration;
123 
124  int _reg;
125 };
126 
127 } // End of namespace Agi
128 
129 #endif /* AGI_SOUND_PCJR_H */
Definition: sound_pcjr.h:54
Definition: agi.h:713
bool isStereo() const override
Definition: sound_pcjr.h:84
Definition: sound.h:57
bool endOfData() const override
Definition: sound_pcjr.h:88
Graphics::Surface * scale(const Graphics::Surface &srcImage, int xSize, int ySize)
Definition: mixer.h:59
Definition: sound_pcjr.h:73
int getRate() const override
Definition: sound_pcjr.h:92
Definition: mutex.h:67
Definition: audiostream.h:50
Definition: agi.h:63
Definition: sound_pcjr.h:40