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