ScummVM API documentation
mixer_intern.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_MIXER_INTERN_H
23 #define AUDIO_MIXER_INTERN_H
24 
25 #include "common/scummsys.h"
26 #include "common/mutex.h"
27 #include "audio/mixer.h"
28 
29 namespace Audio {
30 
58 class MixerImpl : public Mixer {
59 private:
60  enum {
61  NUM_CHANNELS = 32
62  };
63 
64  Common::Mutex _mutex;
65 
66  const uint _sampleRate;
67  const bool _stereo;
68  uint _outBufSize;
69  const uint _outBytesPerSample;
70  const bool _clamp;
71  bool _mixerReady;
72  uint32 _handleSeed;
73 
74  struct SoundTypeSettings {
75  SoundTypeSettings() : mute(false), volume(kMaxMixerVolume) {}
76 
77  bool mute;
78  int volume;
79  };
80 
81  SoundTypeSettings _soundTypeSettings[4];
82  Channel *_channels[NUM_CHANNELS];
83 
84 
85 public:
86 
87  MixerImpl(uint sampleRate, bool stereo = true, uint outBufSize = 0, uint outBytesPerSample = 2, bool clamp = true);
88  ~MixerImpl();
89 
90  bool isReady() const override { Common::StackLock lock(_mutex); return _mixerReady; }
91 
92  Common::Mutex &mutex() override { return _mutex; }
93 
94  void playStream(
95  SoundType type,
96  SoundHandle *handle,
97  AudioStream *input,
98  int id, byte volume, int8 balance,
99  DisposeAfterUse::Flag autofreeStream,
100  bool permanent,
101  bool reverseStereo) override;
102 
103  void stopAll() override;
104  void stopID(int id) override;
105  void stopHandle(SoundHandle handle) override;
106 
107  void pauseAll(bool paused) override;
108  void pauseID(int id, bool paused) override;
109  void pauseHandle(SoundHandle handle, bool paused) override;
110 
111  bool isSoundIDActive(int id) const override;
112  int getSoundID(SoundHandle handle) const override;
113 
114  bool isSoundHandleActive(SoundHandle handle) const override;
115 
116  void muteSoundType(SoundType type, bool mute) override;
117  bool isSoundTypeMuted(SoundType type) const override;
118 
119  void setChannelVolume(SoundHandle handle, byte volume) override;
120  byte getChannelVolume(SoundHandle handle) const override;
121  void setChannelBalance(SoundHandle handle, int8 balance) override;
122  int8 getChannelBalance(SoundHandle handle) const override;
123  void setChannelFaderL(SoundHandle handle, uint8 scaleL) override;
124  uint8 getChannelFaderL(SoundHandle handle) const override;
125  void setChannelFaderR(SoundHandle handle, uint8 scaleR) override;
126  uint8 getChannelFaderR(SoundHandle handle) const override;
127  void setChannelRate(SoundHandle handle, uint32 rate) override;
128  uint32 getChannelRate(SoundHandle handle) const override;
129  void resetChannelRate(SoundHandle handle) override;
130 
131  uint32 getSoundElapsedTime(SoundHandle handle) const override;
132  Timestamp getElapsedTime(SoundHandle handle) const override;
133 
134  void loopChannel(SoundHandle handle) override;
135 
136  bool hasActiveChannelOfType(SoundType type) const override;
137 
138  void setVolumeForSoundType(SoundType type, int volume) override;
139  int getVolumeForSoundType(SoundType type) const override;
140 
141  uint getOutputRate() const override;
142  bool getOutputStereo() const override;
143  uint getOutputBufSize() const override;
144  uint getOutputBytesPerSample() const override;
145  bool getClamping() const override;
146 
147 protected:
148  void insertChannel(SoundHandle *handle, Channel *chan);
149 
150 public:
154  void setOutputBufSize(uint outBufSize) { _outBufSize = outBufSize; }
155 
165  int mixCallback(byte *samples, uint len);
166 
172  void setReady(bool ready);
173 };
174 
176 } // End of namespace Audio
177 
178 #endif
Definition: mixer.h:83
uint getOutputBytesPerSample() const override
byte getChannelVolume(SoundHandle handle) const override
bool isSoundHandleActive(SoundHandle handle) const override
void resetChannelRate(SoundHandle handle) override
void loopChannel(SoundHandle handle) override
Timestamp getElapsedTime(SoundHandle handle) const override
uint getOutputBufSize() const override
void setVolumeForSoundType(SoundType type, int volume) override
int8 getChannelBalance(SoundHandle handle) const override
bool getClamping() const override
bool getOutputStereo() const override
uint32 getSoundElapsedTime(SoundHandle handle) const override
uint getOutputRate() const override
int mixCallback(byte *samples, uint len)
Definition: mutex.h:51
uint8 getChannelFaderR(SoundHandle handle) const override
uint32 getChannelRate(SoundHandle handle) const override
Definition: timestamp.h:83
void stopAll() override
bool isReady() const override
Definition: mixer_intern.h:90
void setChannelRate(SoundHandle handle, uint32 rate) override
void pauseHandle(SoundHandle handle, bool paused) override
bool isSoundIDActive(int id) const override
Definition: mixer_intern.h:58
Definition: mixer.h:49
SoundType
Definition: mixer.h:73
Definition: mixer.h:70
void setOutputBufSize(uint outBufSize)
Definition: mixer_intern.h:154
void setChannelVolume(SoundHandle handle, byte volume) override
bool isSoundTypeMuted(SoundType type) const override
uint8 getChannelFaderL(SoundHandle handle) const override
void pauseID(int id, bool paused) override
void playStream(SoundType type, SoundHandle *handle, AudioStream *input, int id, byte volume, int8 balance, DisposeAfterUse::Flag autofreeStream, bool permanent, bool reverseStereo) override
void pauseAll(bool paused) override
bool hasActiveChannelOfType(SoundType type) const override
int getSoundID(SoundHandle handle) const override
void muteSoundType(SoundType type, bool mute) override
Definition: mutex.h:67
Definition: audiostream.h:50
void setChannelFaderR(SoundHandle handle, uint8 scaleR) override
void stopHandle(SoundHandle handle) override
void setChannelFaderL(SoundHandle handle, uint8 scaleL) override
void stopID(int id) override
Common::Mutex & mutex() override
Definition: mixer_intern.h:92
void setReady(bool ready)
void setChannelBalance(SoundHandle handle, int8 balance) override
Definition: system.h:39
int getVolumeForSoundType(SoundType type) const override