ScummVM API documentation
sound_sarien.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_SARIEN_H
23 #define AGI_SOUND_SARIEN_H
24 
25 #include "audio/audiostream.h"
26 
27 namespace Agi {
28 
29 #define BUFFER_SIZE 410
30 
31 #define WAVEFORM_SIZE 64
32 #define ENV_ATTACK 10000
33 #define ENV_DECAY 1000
34 #define ENV_SUSTAIN 100
35 #define ENV_RELEASE 7500
36 #define NUM_CHANNELS 7
38 enum AgiSoundFlags {
39  AGI_SOUND_LOOP = 0x0001,
40  AGI_SOUND_ENVELOPE = 0x0002
41 };
42 enum AgiSoundEnv {
43  AGI_SOUND_ENV_ATTACK = 3,
44  AGI_SOUND_ENV_DECAY = 2,
45  AGI_SOUND_ENV_SUSTAIN = 1,
46  AGI_SOUND_ENV_RELEASE = 0
47 };
48 
49 
53 struct ChannelInfo {
54  AgiSoundEmuType type;
55  const uint8 *ptr; // Pointer to the AgiNote data
56  const int16 *ins;
57  int32 size;
58  uint32 phase;
59  uint32 flags; // ORs values from AgiSoundFlags
60  AgiSoundEnv adsr;
61  int32 timer;
62  uint32 end;
63  uint32 freq;
64  uint32 vol;
65  uint32 env;
66 };
67 
68 class SoundGenSarien : public SoundGen, public Audio::AudioStream {
69 public:
70  SoundGenSarien(AgiBase *vm, Audio::Mixer *pMixer);
71  ~SoundGenSarien() override;
72 
73  void play(int resnum) override;
74  void stop() override;
75 
76  // AudioStream API
77  int readBuffer(int16 *buffer, const int numSamples) override;
78 
79  bool isStereo() const override {
80  return false;
81  }
82 
83  bool endOfData() const override {
84  return false;
85  }
86 
87  int getRate() const override {
88  // FIXME: Ideally, we should use _sampleRate.
89  return 22050;
90  }
91 
92 private:
93  ChannelInfo _chn[NUM_CHANNELS];
94  uint8 _env;
95 
96  int16 *_sndBuffer;
97  const int16 *_waveform;
98 
99  bool _useChorus;
100 
101  bool _playing;
102  int _playingSound;
103 
104 private:
105  void playSound();
106  uint32 mixSound();
107  void fillAudio(int16 *stream, uint len);
108 
109  void stopNote(int i);
110  void playNote(int i, int freq, int vol);
111 
112 };
113 
114 } // End of namespace Agi
115 
116 #endif /* AGI_SOUND_SARIEN_H */
Definition: agi.h:713
Definition: sound.h:57
Definition: sound_sarien.h:53
Definition: sound_sarien.h:68
Definition: mixer.h:59
int getRate() const override
Definition: sound_sarien.h:87
Definition: audiostream.h:50
AgiSoundEmuType
Definition: sound.h:47
bool endOfData() const override
Definition: sound_sarien.h:83
Definition: agi.h:63
bool isStereo() const override
Definition: sound_sarien.h:79