ScummVM API documentation
smush_mixer.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 GRIM_MOVIE_SMUSH_MIXER_H
23#define GRIM_MOVIE_SMUSH_MIXER_H
24
25#include "common/scummsys.h"
26#include "common/mutex.h"
27#include "audio/audiostream.h"
28#include "audio/mixer.h"
29
30namespace Grim {
31
32#define SMUSH_RING_BLOCK_SIZE 6144
33
34// The demo decodes every IACT chunk into 1024 stereo 16 bit samples
35#define SMUSH_DEMO_AUDIO_BLOCK_SIZE 4096
36#define SMUSH_DEMO_AUDIO_RATE 22050
37#define SMUSH_DEMO_AUDIO_BYTES_PER_SECOND (SMUSH_DEMO_AUDIO_RATE * 2 * 2)
38
39// Milliseconds of audio in the demo driver ring, to buffer before playing,
40// and under which the driver stops to buffer again
41#define SMUSH_DEMO_DRIVER_BUFFER_MS 5000
42#define SMUSH_DEMO_DRIVER_START_MS 1000
43#define SMUSH_DEMO_DRIVER_LOW_MS 500
44
45class SmushTimer;
46class SmushSound;
47
49
50private:
51 int32 *_mixBuf;
52 int _mixBufSize;
53 int _outChannelCount;
54 byte _mixerTable[17 * 17];
55
56 void mixMono8(const uint8 *srcBuf, int32 inFrameCount, uint32 feedSize, int32 mixBufStartIndex, int leftAmp, int rightAmp);
57 void mixMono16(const int16 *srcBuf, int32 inFrameCount, uint32 feedSize, int32 mixBufStartIndex, int leftAmp, int rightAmp);
58 void mixStereo16(const int16 *srcBuf, int32 inFrameCount, uint32 feedSize, int32 mixBufStartIndex, int volume);
59
60public:
61 SmushMixer();
63
64 int souMixerInitialize(int outChannelCount, int mixBufSize);
65 int souMixerTerminate();
66 int souMixerStart();
67 void souMixerMix(const uint8 *srcBuf, int32 inFrameCount, int wordSize, int channelCount, uint32 feedSize, int32 mixBufStartIndex, int volume, int pan);
68 int souMixerEnd(int16 *destBuf, int frameCount);
69
70};
71
72class SmushDriver;
73
75
76private:
77 SmushDriver *_driver;
78
79public:
81
82 int readBuffer(int16 *buffer, const int numSamples) override;
83 bool isStereo() const override { return true; }
84 int getRate() const override;
85 bool endOfData() const override { return false; }
86
87};
88
90
91private:
92 SmushMixer _mixer;
93 SmushTimer *_timer;
94 SmushSound *_sound;
95 Audio::Mixer *_system;
96 Audio::SoundHandle _soundHandle;
97 Common::Mutex _ringMutex;
98 byte *_ring;
99 int _ringBlockCount;
100 int _ringPlayPosition;
101 int _lastBlock;
102 int _driverRate;
103 bool _remastered;
104 int _fillTimer;
105
106 int sndDrivOpenRing();
107 void sndDrivCloseRing();
108 int sndDrivGetPlayBlock();
109 int sndDrivMixerInitialize(int arg, int size);
110 void sndDrivMixerTerminate();
111 int sndDrivMixerEnd(int16 *destBuf, int frameCount);
112
113public:
114 SmushDriver(SmushTimer *timer, bool remastered);
115 ~SmushDriver();
116
117 int sndDrivInitialize(int rate, int channelCount, SmushSound *sound);
118 void sndDrivTerminate();
119 int sndDrivGetRate();
120 void sndDrivFillThread();
121 void sndDrivMix(const uint8 *srcBuf, int32 mixBufStartIndex, uint32 feedSize, int32 srcByteCount, int volume, int pan, int format);
122 static void sndDrivFillThreadCallback(int timer, void *context);
123
124 int ringRead(int16 *buffer, int numSamples);
125
126};
127
129 byte *data;
130 int produced;
131 int consumed;
132 int size;
133 bool opened;
134};
135
136class SmushDemoDriver;
137
139
140private:
141 SmushDemoDriver *_driver;
142
143public:
145
146 int readBuffer(int16 *buffer, const int numSamples) override;
147 bool isStereo() const override { return true; }
148 int getRate() const override { return 22050; }
149 bool endOfData() const override { return false; }
150
151};
152
154
155private:
156 Audio::Mixer *_system;
157 Audio::SoundHandle _soundHandle;
158 Common::Mutex _mutex;
159 byte *_buffer;
160 int _bufferSize;
161 int _playPosition;
162 bool _playing;
163 bool _created;
164 int _rate;
165 int _blockAlign;
166 int _written;
167 int _wrapCount;
168 int _lastPosition;
169 int _lastTime;
170 uint32 _lastMeasure;
171 int _lastReturned;
172 int _waiting;
173 int _paused;
174 int _threshold;
175 double _msPerByte;
176
177public:
180
181 void sndDrivCreate();
182 void sndDrivRelease();
183 int sndDrivOpen(int rate, int channels, int bits, SmushDemoAudio *audio);
184 void sndDrivClose(SmushDemoAudio *audio);
185 int sndDrivGetTime(SmushDemoAudio *audio);
186 int sndDrivPause(SmushDemoAudio *audio);
187 int sndDrivResume(SmushDemoAudio *audio);
188 void sndDrivFill(SmushDemoAudio *audio);
189
190 int ringRead(int16 *buffer, int numSamples);
191
192};
193
194} // End of namespace Grim
195#endif
Definition: audiostream.h:50
Definition: mixer.h:70
Definition: mixer.h:49
Definition: mutex.h:67
Definition: smush_mixer.h:153
Definition: smush_mixer.h:138
bool endOfData() const override
Definition: smush_mixer.h:149
int readBuffer(int16 *buffer, const int numSamples) override
bool isStereo() const override
Definition: smush_mixer.h:147
int getRate() const override
Definition: smush_mixer.h:148
Definition: smush_mixer.h:89
Definition: smush_mixer.h:74
int readBuffer(int16 *buffer, const int numSamples) override
bool endOfData() const override
Definition: smush_mixer.h:85
int getRate() const override
bool isStereo() const override
Definition: smush_mixer.h:83
Definition: smush_mixer.h:48
Definition: smush_sound.h:72
Definition: smush_timer.h:49
Definition: smush_mixer.h:128