include: Add STORAGE_HOTPLUG_INFO structure.
[wine.git] / dlls / dmusic / soundfont.h
blobac71ba7909a30b173dc2086ffa16f45927b561a4
1 /*
2 * Copyright 2023 RĂ©mi Bernon for CodeWeavers
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include "stdarg.h"
20 #include "stddef.h"
22 #include "windef.h"
23 #include "winbase.h"
25 #include "wine/debug.h"
27 #include <pshpack1.h>
29 /* SoundFont 2.04 data structures, from http://www.synthfont.com/sfspec24.pdf */
31 struct sf_range
33 BYTE low;
34 BYTE high;
37 union sf_amount
39 struct sf_range range;
40 WORD value;
43 C_ASSERT(sizeof(union sf_amount) == 2);
45 enum
47 SF_SAMPLE_MONO = 1,
48 SF_SAMPLE_RIGHT = 2,
49 SF_SAMPLE_LEFT = 4,
50 SF_SAMPLE_LINKED = 8,
51 SF_SAMPLE_ROM_MONO = 0x8001,
52 SF_SAMPLE_ROM_RIGHT = 0x8002,
53 SF_SAMPLE_ROM_LEFT = 0x8004,
54 SF_SAMPLE_ROM_LINKED = 0x8008,
56 typedef WORD sf_sample_type;
58 enum
60 SF_GEN_START_ADDRS_OFFSET = 0,
61 SF_GEN_END_ADDRS_OFFSET = 1,
62 SF_GEN_STARTLOOP_ADDRS_OFFSET = 2,
63 SF_GEN_ENDLOOP_ADDRS_OFFSET = 3,
64 SF_GEN_START_ADDRS_COARSE_OFFSET = 4,
65 SF_GEN_MOD_LFO_TO_PITCH = 5,
66 SF_GEN_VIB_LFO_TO_PITCH = 6,
67 SF_GEN_MOD_ENV_TO_PITCH = 7,
68 SF_GEN_INITIAL_FILTER_FC = 8,
69 SF_GEN_INITIAL_FILTER_Q = 9,
70 SF_GEN_MOD_LFO_TO_FILTER_FC = 10,
71 SF_GEN_MOD_ENV_TO_FILTER_FC = 11,
72 SF_GEN_END_ADDRS_COARSE_OFFSET = 12,
73 SF_GEN_MOD_LFO_TO_VOLUME = 13,
75 SF_GEN_CHORUS_EFFECTS_SEND = 15,
76 SF_GEN_REVERB_EFFECTS_SEND = 16,
77 SF_GEN_PAN = 17,
79 SF_GEN_DELAY_MOD_LFO = 21,
80 SF_GEN_FREQ_MOD_LFO = 22,
81 SF_GEN_DELAY_VIB_LFO = 23,
82 SF_GEN_FREQ_VIB_LFO = 24,
83 SF_GEN_DELAY_MOD_ENV = 25,
84 SF_GEN_ATTACK_MOD_ENV = 26,
85 SF_GEN_HOLD_MOD_ENV = 27,
86 SF_GEN_DECAY_MOD_ENV = 28,
87 SF_GEN_SUSTAIN_MOD_ENV = 29,
88 SF_GEN_RELEASE_MOD_ENV = 30,
89 SF_GEN_KEYNUM_TO_MOD_ENV_HOLD = 31,
90 SF_GEN_KEYNUM_TO_MOD_ENV_DECAY = 32,
91 SF_GEN_DELAY_VOL_ENV = 33,
92 SF_GEN_ATTACK_VOL_ENV = 34,
93 SF_GEN_HOLD_VOL_ENV = 35,
94 SF_GEN_DECAY_VOL_ENV = 36,
95 SF_GEN_SUSTAIN_VOL_ENV = 37,
96 SF_GEN_RELEASE_VOL_ENV = 38,
97 SF_GEN_KEYNUM_TO_VOL_ENV_HOLD = 39,
98 SF_GEN_KEYNUM_TO_VOL_ENV_DECAY = 40,
99 SF_GEN_INSTRUMENT = 41,
101 SF_GEN_KEY_RANGE = 43,
102 SF_GEN_VEL_RANGE = 44,
103 SF_GEN_STARTLOOP_ADDRS_COARSE_OFFSET = 45,
104 SF_GEN_KEYNUM = 46,
105 SF_GEN_VELOCITY = 47,
106 SF_GEN_INITIAL_ATTENUATION = 48,
108 SF_GEN_ENDLOOP_ADDRS_COARSE_OFFSET = 50,
109 SF_GEN_COARSE_TUNE = 51,
110 SF_GEN_FINE_TUNE = 52,
111 SF_GEN_SAMPLE_ID = 53,
112 SF_GEN_SAMPLE_MODES = 54,
114 SF_GEN_SCALE_TUNING = 56,
115 SF_GEN_EXCLUSIVE_CLASS = 57,
116 SF_GEN_OVERRIDING_ROOT_KEY = 58,
118 SF_GEN_END_OPER = 60,
120 typedef WORD sf_generator;
122 static inline const char *debugstr_sf_generator(sf_generator oper)
124 switch (oper)
126 case SF_GEN_START_ADDRS_OFFSET: return "start_addrs_offset";
127 case SF_GEN_END_ADDRS_OFFSET: return "end_addrs_offset";
128 case SF_GEN_STARTLOOP_ADDRS_OFFSET: return "startloop_addrs_offset";
129 case SF_GEN_ENDLOOP_ADDRS_OFFSET: return "endloop_addrs_offset";
130 case SF_GEN_START_ADDRS_COARSE_OFFSET: return "start_addrs_coarse_offset";
131 case SF_GEN_MOD_LFO_TO_PITCH: return "mod_lfo_to_pitch";
132 case SF_GEN_VIB_LFO_TO_PITCH: return "vib_lfo_to_pitch";
133 case SF_GEN_MOD_ENV_TO_PITCH: return "mod_env_to_pitch";
134 case SF_GEN_INITIAL_FILTER_FC: return "initial_filter_fc";
135 case SF_GEN_INITIAL_FILTER_Q: return "initial_filter_q";
136 case SF_GEN_MOD_LFO_TO_FILTER_FC: return "mod_lfo_to_filter_fc";
137 case SF_GEN_MOD_ENV_TO_FILTER_FC: return "mod_env_to_filter_fc";
138 case SF_GEN_END_ADDRS_COARSE_OFFSET: return "end_addrs_coarse_offset";
139 case SF_GEN_MOD_LFO_TO_VOLUME: return "mod_lfo_to_volume";
140 case SF_GEN_CHORUS_EFFECTS_SEND: return "chorus_effects_send";
141 case SF_GEN_REVERB_EFFECTS_SEND: return "reverb_effects_send";
142 case SF_GEN_PAN: return "pan";
143 case SF_GEN_DELAY_MOD_LFO: return "delay_mod_lfo";
144 case SF_GEN_FREQ_MOD_LFO: return "freq_mod_lfo";
145 case SF_GEN_DELAY_VIB_LFO: return "delay_vib_lfo";
146 case SF_GEN_FREQ_VIB_LFO: return "freq_vib_lfo";
147 case SF_GEN_DELAY_MOD_ENV: return "delay_mod_env";
148 case SF_GEN_ATTACK_MOD_ENV: return "attack_mod_env";
149 case SF_GEN_HOLD_MOD_ENV: return "hold_mod_env";
150 case SF_GEN_DECAY_MOD_ENV: return "decay_mod_env";
151 case SF_GEN_SUSTAIN_MOD_ENV: return "sustain_mod_env";
152 case SF_GEN_RELEASE_MOD_ENV: return "release_mod_env";
153 case SF_GEN_KEYNUM_TO_MOD_ENV_HOLD: return "keynum_to_mod_env_hold";
154 case SF_GEN_KEYNUM_TO_MOD_ENV_DECAY: return "keynum_to_mod_env_decay";
155 case SF_GEN_DELAY_VOL_ENV: return "delay_vol_env";
156 case SF_GEN_ATTACK_VOL_ENV: return "attack_vol_env";
157 case SF_GEN_HOLD_VOL_ENV: return "hold_vol_env";
158 case SF_GEN_DECAY_VOL_ENV: return "decay_vol_env";
159 case SF_GEN_SUSTAIN_VOL_ENV: return "sustain_vol_env";
160 case SF_GEN_RELEASE_VOL_ENV: return "release_vol_env";
161 case SF_GEN_KEYNUM_TO_VOL_ENV_HOLD: return "keynum_to_vol_env_hold";
162 case SF_GEN_KEYNUM_TO_VOL_ENV_DECAY: return "keynum_to_vol_env_decay";
163 case SF_GEN_INSTRUMENT: return "instrument";
164 case SF_GEN_KEY_RANGE: return "key_range";
165 case SF_GEN_VEL_RANGE: return "vel_range";
166 case SF_GEN_STARTLOOP_ADDRS_COARSE_OFFSET: return "startloop_addrs_coarse_offset";
167 case SF_GEN_KEYNUM: return "keynum";
168 case SF_GEN_VELOCITY: return "velocity";
169 case SF_GEN_INITIAL_ATTENUATION: return "initial_attenuation";
170 case SF_GEN_ENDLOOP_ADDRS_COARSE_OFFSET: return "endloop_addrs_coarse_offset";
171 case SF_GEN_COARSE_TUNE: return "coarse_tune";
172 case SF_GEN_FINE_TUNE: return "fine_tune";
173 case SF_GEN_SAMPLE_ID: return "sample_id";
174 case SF_GEN_SAMPLE_MODES: return "sample_modes";
175 case SF_GEN_SCALE_TUNING: return "scale_tuning";
176 case SF_GEN_EXCLUSIVE_CLASS: return "exclusive_class";
177 case SF_GEN_OVERRIDING_ROOT_KEY: return "overriding_root_key";
178 case SF_GEN_END_OPER: return "end_oper";
181 return wine_dbg_sprintf("%u", oper);
184 enum
186 /* sf_modulator is a set of flags ored together */
188 SF_MOD_CTRL_GEN_NONE = 0,
189 SF_MOD_CTRL_GEN_VELOCITY = 0x2,
190 SF_MOD_CTRL_GEN_KEY = 0x3,
191 SF_MOD_CTRL_GEN_POLY_PRESSURE = 0xa,
192 SF_MOD_CTRL_GEN_CHAN_PRESSURE = 0xd,
193 SF_MOD_CTRL_GEN_PITCH_WHEEL = 0xe,
194 SF_MOD_CTRL_GEN_PITCH_WHEEL_SENSITIVITY = 0x10,
195 SF_MOD_CTRL_GEN_LINK = 0x7f,
197 SF_MOD_CTRL_GEN = 0 << 7,
198 SF_MOD_CTRL_MIDI = 1 << 7, /* with LSB: MIDI CC */
200 SF_MOD_DIR_INCREASING = 0 << 8,
201 SF_MOD_DIR_DECREASING = 1 << 8,
203 SF_MOD_POL_UNIPOLAR = 0 << 9,
204 SF_MOD_POL_BIPOLAR = 1 << 9,
206 SF_MOD_SRC_LINEAR = 0 << 10,
207 SF_MOD_SRC_CONCAVE = 1 << 10,
208 SF_MOD_SRC_CONVEX = 2 << 10,
209 SF_MOD_SRC_SWITCH = 3 << 10,
211 typedef WORD sf_modulator;
213 enum
215 SF_TRAN_LINEAR = 0,
216 SF_TRAN_ABSOLUTE = 2,
218 typedef WORD sf_transform;
220 struct sf_preset /* <phdr-rec> */
222 char name[20];
223 WORD preset;
224 WORD bank;
225 WORD bag_ndx;
226 DWORD library;
227 DWORD genre;
228 DWORD morphology;
231 C_ASSERT(sizeof(struct sf_preset) == 38);
233 struct sf_bag /* <pbag-rec> / <ibag-rec> */
235 WORD gen_ndx;
236 WORD mod_ndx;
239 C_ASSERT(sizeof(struct sf_bag) == 4);
241 struct sf_mod /* <pmod-rec> / <imod-rec> */
243 sf_modulator src_mod;
244 sf_generator dest_gen;
245 SHORT amount;
246 sf_modulator amount_src_mod;
247 sf_transform transform;
250 C_ASSERT(sizeof(struct sf_mod) == 10);
252 static inline const char *debugstr_sf_mod(struct sf_mod *mod)
254 const char *dest_name = debugstr_sf_generator(mod->dest_gen);
255 return wine_dbg_sprintf("%#x x %#x -> %s: %d (%#x)", mod->src_mod, mod->amount_src_mod, dest_name, mod->amount, mod->transform);
258 struct sf_gen /* <pgen-rec> / <igen-rec> */
260 sf_generator oper;
261 union sf_amount amount;
264 C_ASSERT(sizeof(struct sf_gen) == 4);
266 static inline const char *debugstr_sf_gen(struct sf_gen *gen)
268 const char *name = debugstr_sf_generator(gen->oper);
270 switch (gen->oper)
272 case SF_GEN_KEY_RANGE:
273 case SF_GEN_VEL_RANGE:
274 return wine_dbg_sprintf("%s: %u-%u", name, gen->amount.range.low, gen->amount.range.high);
275 default:
276 return wine_dbg_sprintf("%s: %u", name, gen->amount.value);
280 struct sf_instrument /* <inst-rec> */
282 char name[20];
283 WORD bag_ndx;
286 C_ASSERT(sizeof(struct sf_instrument) == 22);
288 struct sf_sample /* <shdr-rec> */
290 char name[20];
291 DWORD start;
292 DWORD end;
293 DWORD start_loop;
294 DWORD end_loop;
295 DWORD sample_rate;
296 BYTE original_key;
297 char correction;
298 WORD sample_link;
299 sf_sample_type sample_type;
302 C_ASSERT(sizeof(struct sf_sample) == 46);
304 #include <poppack.h>
306 struct soundfont
308 UINT preset_count;
309 struct sf_preset *phdr;
310 struct sf_bag *pbag;
311 struct sf_mod *pmod;
312 struct sf_gen *pgen;
314 UINT instrument_count;
315 struct sf_instrument *inst;
316 struct sf_bag *ibag;
317 struct sf_mod *imod;
318 struct sf_gen *igen;
320 UINT sample_count;
321 struct sf_sample *shdr;
322 BYTE *sdta;