ScummVM API documentation
synthfile.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  * VGMTrans (c) 2002-2019
23  * Licensed under the zlib license,
24  * refer to the included VGMTrans_LICENSE.txt file
25  */
26 #ifndef AUDIO_SOUNDFONT_SYNTHFILE_H
27 #define AUDIO_SOUNDFONT_SYNTHFILE_H
28 
29 #include "common/scummsys.h"
30 #include "common/list.h"
31 #include "common/str.h"
32 #include "common/array.h"
33 #include "rifffile.h"
34 
35 struct Loop;
36 class VGMSamp;
37 
38 class SynthInstr;
39 class SynthRgn;
40 class SynthArt;
41 class SynthSampInfo;
42 class SynthWave;
43 
44 typedef enum {
45  no_transform, concave_transform
46 } Transform;
47 
48 class SynthFile {
49 public:
50  SynthFile(const Common::String synth_name = "Instrument Set");
51 
52  ~SynthFile();
53 
54  SynthInstr *AddInstr(uint32 bank, uint32 instrNum);
55  SynthWave *AddWave(uint16 formatTag, uint16 channels, int samplesPerSec, int aveBytesPerSec,
56  uint16 blockAlign, uint16 bitsPerSample, uint32 waveDataSize,
57  uint8 *waveData, Common::String name = "Unnamed Wave");
58 
59 public:
62  Common::String _name;
63 };
64 
65 class SynthInstr {
66 public:
67  SynthInstr(uint32 bank, uint32 instrument, Common::String instrName);
68  ~SynthInstr(void);
69 
70  SynthRgn *AddRgn(void);
71 
72 public:
73  uint32 _ulBank;
74  uint32 _ulInstrument;
75 
77  Common::String _name;
78 };
79 
80 class SynthRgn {
81 public:
82  SynthRgn()
83  : _usKeyLow(0),
84  _usKeyHigh(0),
85  _usVelLow(0),
86  _usVelHigh(0),
87  _sampinfo(NULL),
88  _art(NULL),
89  _fusOptions(0),
90  _usPhaseGroup(0),
91  _channel(0),
92  _tableIndex(0) {}
93 
94  ~SynthRgn();
95 
96  SynthArt *AddArt(void);
97  SynthSampInfo *AddSampInfo(void);
98  void SetRanges(uint16 keyLow = 0, uint16 keyHigh = 0x7F, uint16 velLow = 0,
99  uint16 velHigh = 0x7F);
100  void SetWaveLinkInfo(uint16 options, uint16 phaseGroup, uint32 theChannel,
101  uint32 theTableIndex);
102 
103 public:
104  uint16 _usKeyLow;
105  uint16 _usKeyHigh;
106  uint16 _usVelLow;
107  uint16 _usVelHigh;
108 
109  uint16 _fusOptions;
110  uint16 _usPhaseGroup;
111  uint32 _channel;
112  uint32 _tableIndex;
113 
114  SynthSampInfo *_sampinfo;
115  SynthArt *_art;
116 };
117 
118 class SynthArt {
119 public:
120  SynthArt() : _pan(0.0), _attack_time(0.0), _decay_time(0.0),
121  _sustain_lev(0.0), _sustain_time(0.0), _release_time(0.0),
122  _attack_transform(no_transform), _release_transform(no_transform) {}
123  ~SynthArt();
124 
125  void AddADSR(double attack, Transform atk_transform, double decay, double sustain_lev,
126  double sustain_time, double release_time, Transform rls_transform);
127  void AddPan(double pan);
128 
129  double _pan; // -100% = left channel 100% = right channel 0 = 50/50
130 
131  double _attack_time; // rate expressed as seconds from 0 to 100% level
132  double _decay_time; // rate expressed as seconds from 100% to 0% level, even though the sustain
133  // level isn't necessarily 0%
134  double _sustain_lev; // db of attenuation at sustain level
135  double _sustain_time; // this is part of the PSX envelope (and can actually be positive), but is
136  // not in DLS or SF2. from 100 to 0, like release
137  double _release_time; // rate expressed as seconds from 100% to 0% level, even though the
138  // sustain level may not be 100%
139  Transform _attack_transform;
140  Transform _release_transform;
141 
142 private:
143 };
144 
146 public:
147  SynthSampInfo() : _usUnityNote(0), _sFineTune(0), _attenuation(0.0),
148  _cSampleLoops(0), _ulLoopStart(0), _ulLoopLength(0) {}
149  ~SynthSampInfo() {}
150 
151  void SetLoopInfo(Loop &loop, VGMSamp *samp);
152  void SetPitchInfo(uint16 unityNote, int16 fineTune, double attenuation);
153 
154 public:
155  uint16 _usUnityNote;
156  int16 _sFineTune;
157  double _attenuation; // in decibels.
158  int8 _cSampleLoops;
159 
160  uint32 _ulLoopStart;
161  uint32 _ulLoopLength;
162 };
163 
164 class SynthWave {
165 public:
166  SynthWave(void) : _sampinfo(NULL), _data(NULL), _name("Untitled Wave") {
167  RiffFile::AlignName(_name);
168  }
169 
170  SynthWave(uint16 formatTag, uint16 channels, int samplesPerSec, int aveBytesPerSec,
171  uint16 blockAlign, uint16 bitsPerSample, uint32 waveDataSize, uint8 *waveData,
172  Common::String waveName = "Untitled Wave")
173  : _wFormatTag(formatTag),
174  _wChannels(channels),
175  _dwSamplesPerSec(samplesPerSec),
176  _dwAveBytesPerSec(aveBytesPerSec),
177  _wBlockAlign(blockAlign),
178  _wBitsPerSample(bitsPerSample),
179  _dataSize(waveDataSize),
180  _data(waveData),
181  _sampinfo(NULL),
182  _name(waveName) {
183  RiffFile::AlignName(_name);
184  }
185 
186  ~SynthWave(void);
187 
188  SynthSampInfo *AddSampInfo(void);
189  void ConvertTo16bitSigned();
190 
191 public:
192  SynthSampInfo *_sampinfo;
193 
194  uint16 _wFormatTag;
195  uint16 _wChannels;
196  uint32 _dwSamplesPerSec;
197  uint32 _dwAveBytesPerSec;
198  uint16 _wBlockAlign;
199  uint16 _wBitsPerSample;
200 
201  uint32 _dataSize;
202  uint8 *_data;
203 
204  Common::String _name;
205 };
206 
207 #endif // AUDIO_SOUNDFONT_SYNTHFILE_H
Definition: synthfile.h:118
Definition: str.h:59
Definition: synthfile.h:164
Definition: synthfile.h:48
Definition: synthfile.h:80
Definition: array.h:52
Definition: synthfile.h:65
Definition: vgmsamp.h:41
Definition: synthfile.h:145
Definition: common.h:36