ScummVM API documentation
sfx_player.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 AWE_SFX_PLAYER_H
23 #define AWE_SFX_PLAYER_H
24 
25 #include "awe/intern.h"
26 #include "common/mutex.h"
27 
28 namespace Awe {
29 
30 struct SfxInstrument {
31  uint8 *data = nullptr;
32  uint16 volume = 0;
33 
34  void clear();
35 };
36 
37 struct SfxModule {
38  const uint8 *data = nullptr;
39  uint16 curPos = 0;
40  uint8 curOrder = 0;
41  uint8 numOrder = 0;
42  uint8 *orderTable = nullptr;
43  SfxInstrument samples[15];
44 
45  void clear();
46  void clearSamples();
47 };
48 
49 struct SfxPattern {
50  uint16 note_1 = 0;
51  uint16 note_2 = 0;
52  uint16 sampleStart = 0;
53  uint8 *sampleBuffer = nullptr;
54  uint16 sampleLen = 0;
55  uint16 loopPos = 0;
56  uint16 loopLen = 0;
57  uint16 sampleVolume = 0;
58 };
59 
60 struct SfxChannel {
61  uint8 *sampleData = nullptr;
62  uint16 sampleLen = 0;
63  uint16 sampleLoopPos = 0;
64  uint16 sampleLoopLen = 0;
65  uint16 volume = 0;
66  Frac pos;
67 };
68 
69 struct Resource;
70 
71 struct SfxPlayer {
72  enum {
73  NUM_CHANNELS = 4
74  };
75 
76  Resource *_res;
77 
78  uint16 _delay = 0;
79  uint16 _resNum = 0;
80  SfxModule _sfxMod;
81  int16 *_syncVar = nullptr;
82  bool _playing = false;
83  int _rate = 0;
84  int _samplesLeft = 0;
85  SfxChannel _channels[NUM_CHANNELS];
86 
87  Common::Mutex _mutex;
88 
89  SfxPlayer(Resource *res);
90 
91  void setEventsDelay(uint16 delay);
92  void loadSfxModule(uint16 resNum, uint16 delay, uint8 pos);
93  void prepareInstruments(const uint8 *p);
94  void play(int rate);
95  void mixSamples(int16 *buf, int len);
96  void readSamples(int16 *buf, int len);
97  void start();
98  void stop();
99  void handleEvents();
100  void handlePattern(uint8 channel, const uint8 *patternData);
101 };
102 
103 } // namespace Awe
104 
105 #endif
Definition: sfx_player.h:30
Definition: intern.h:99
Definition: mutex.h:67
Definition: resource.h:89
Definition: aifc_player.h:29
Definition: sfx_player.h:37
Definition: sfx_player.h:49
Definition: sfx_player.h:60
Definition: sfx_player.h:71