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
25 #include "wine/debug.h"
29 /* SoundFont 2.04 data structures, from http://www.synthfont.com/sfspec24.pdf */
39 struct sf_range range
;
43 C_ASSERT(sizeof(union sf_amount
) == 2);
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
;
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,
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,
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
)
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
);
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
;
216 SF_TRAN_ABSOLUTE
= 2,
218 typedef WORD sf_transform
;
220 struct sf_preset
/* <phdr-rec> */
231 C_ASSERT(sizeof(struct sf_preset
) == 38);
233 struct sf_bag
/* <pbag-rec> / <ibag-rec> */
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
;
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> */
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
);
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
);
276 return wine_dbg_sprintf("%s: %u", name
, gen
->amount
.value
);
280 struct sf_instrument
/* <inst-rec> */
286 C_ASSERT(sizeof(struct sf_instrument
) == 22);
288 struct sf_sample
/* <shdr-rec> */
299 sf_sample_type sample_type
;
302 C_ASSERT(sizeof(struct sf_sample
) == 46);
309 struct sf_preset
*phdr
;
314 UINT instrument_count
;
315 struct sf_instrument
*inst
;
321 struct sf_sample
*shdr
;