ScummVM API documentation
soundmixer.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  * This file is dual-licensed.
22  * In addition to the GPLv3 license mentioned above, this code is also
23  * licensed under LGPL 2.1. See LICENSES/COPYING.LGPL file for the
24  * full text of the license.
25  *
26  */
27 
28 #ifndef GOB_SOUND_SOUNDMIXER_H
29 #define GOB_SOUND_SOUNDMIXER_H
30 
31 #include "common/mutex.h"
32 #include "common/frac.h"
33 #include "audio/audiostream.h"
34 #include "audio/mixer.h"
35 
36 namespace Gob {
37 
38 class SoundDesc;
39 
41 public:
43  ~SoundMixer() override;
44 
45  virtual void play(SoundDesc &sndDesc, int16 repCount,
46  int16 frequency, int16 fadeLength = 0);
47  virtual void stop(int16 fadeLength);
48 
49  bool isPlaying() const;
50  char getPlayingSound() const;
51 
52  void setRepeating(int32 repCount);
53 
54  int readBuffer(int16 *buffer, const int numSamples) override;
55  bool isStereo() const override { return false; }
56  bool endOfData() const override { return _end; }
57  bool endOfStream() const override { return false; }
58  int getRate() const override { return _rate; }
59 
60 protected:
61  Audio::Mixer *_mixer;
62 
63  Audio::SoundHandle _handle;
64  Common::Mutex _mutex;
65 
66  bool _16bit;
67 
68  bool _end;
69  byte *_data;
70  uint32 _length;
71  uint32 _rate;
72  int32 _freq;
73  int32 _repCount;
74 
75  uint32 _offset;
76  frac_t _offsetFrac;
77  frac_t _offsetInc;
78 
79  int16 _cur;
80  int16 _last;
81 
82  bool _fade;
83  int32 _fadeVol;
84  int32 _fadeVolStep;
85  uint8 _fadeLength;
86  uint32 _fadeSamples;
87  uint32 _curFadeSamples;
88 
89  char _playingSound;
90 
91  virtual void setSample(SoundDesc &sndDesc, int16 repCount,
92  int16 frequency, int16 fadeLength);
93  virtual void checkEndSample();
94  virtual void endFade();
95 
96 private:
97  inline int16 getData(int offset);
98 };
99 
100 } // End of namespace Gob
101 
102 #endif // GOB_SOUND_SOUNDMIXER_H
bool endOfData() const override
Definition: soundmixer.h:56
Definition: mixer.h:49
bool endOfStream() const override
Definition: soundmixer.h:57
SoundType
Definition: mixer.h:62
Definition: mixer.h:59
Definition: anifile.h:40
int getRate() const override
Definition: soundmixer.h:58
Definition: mutex.h:67
Definition: audiostream.h:50
Definition: sounddesc.h:43
bool isStereo() const override
Definition: soundmixer.h:55
int readBuffer(int16 *buffer, const int numSamples) override
Definition: soundmixer.h:40
int32 frac_t
Definition: frac.h:52