1 /*(LGPL) 2 --------------------------------------------------------------------------- 3 a_types.h - Commonly used types in the engine 4 --------------------------------------------------------------------------- 5 * Copyright (C) 2001, 2002, David Olofson 6 * 7 * This program is free software; you can redistribute it and/or modify it 8 * under the terms of the GNU Lesser General Public License as published by 9 * the Free Software Foundation; either version 2.1 of the License, or (at 10 * your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, but 13 * WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * Lesser General Public License for more details. 16 * 17 * You should have received a copy of the GNU Lesser General Public License 18 * along with this program; if not, write to the Free Software Foundation, 19 * Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 */ 21 22 #ifndef _A_TYPES_H_ 23 #define _A_TYPES_H_ 24 25 #include "glSDL.h" 26 27 /* Builtin patch drivers */ 28 typedef enum 29 { 30 PD_NONE = -1, /* No driver! */ 31 PD_MONO = 0, /* Basic monophonic */ 32 PD_POLY, /* Basic polyphonic */ 33 PD_MIDI, /* Basic MIDI player */ 34 PD_EEL /* User EEL code driver */ 35 } patch_drivers_t; 36 37 38 /* Voice tag special codes */ 39 typedef enum 40 { 41 AVT_FUTURE = -2, 42 AVT_ALL = -1 43 } audio_voice_tags_t; 44 45 46 /* 47 * DAHDSR envelope generator parameters: 48 * 49 * Level 50 * ^ 51 * | __L1__ 52 * | /| |\ 53 * | / | | \ 54 * |__L0__/ | | \__L2__ 55 * | | | | | |\ 56 * | D | A | H | D | S |R\ 57 * |_____|___|____|___|____|__\____\ 58 * | | | | | | | / Time 59 * DELAY T1 HOLD T2 T3 T4 60 * 61 * State by state description: 62 * 63 * D: Set to L0, and hold for DELAY seconds. 64 * A: Ramp to L1 over T1 seconds. 65 * H: Hold at L1 for HOLD seconds. 66 * D: Ramp to L2 over T2 seconds. 67 * S: if T3 < 0 68 * Hold at L2 until CE_STOP is received. 69 * else 70 * Hold at L2 for T3 seconds. 71 * R: Ramp to 0 over T3 seconds. 72 * 73 * If T3 is set to a negative value, sustain lasts until 74 * a CE_STOP event is received. If T3 is 0 of higher, 75 * sustain lasts for T3 seconds. 76 * 77 * The EG will *always* load L0, but from then on, if a 78 * phase has a zero duration, that phase is skipped. 79 * Note that skipping any of the A, D and R phases will 80 * produce clicks, unless the adjacent levels are 81 * identical. 82 * 83 * In some cases, it's desirable that the EG immediately 84 * skips to the release phase when a CE_STOP event is 85 * received, whereas in other cases, this would result 86 * in problems with very short notes. Therefore, there is 87 * a boolean control 'ENV_SKIP' that make it possible to 88 * specify which behavior is desired. 89 * '1' will make the EG skip to release upon receiving 90 * CE_STOP. '0' will result in the EG taking no action 91 * on CE_STOP until the sustain phase is reached the 92 * normal way. 93 * 'ENV_SKIP' has no effect if "timed sustain" is used; 94 * T3 must be < 0, or CE_STOP is entirely ignored. 95 * 96 TODO: 97 * Turn this into a generic EG, with "unlimited" 98 number of phases. The current way of marking 99 the sustain hold point would still work, 100 although one would have to replace the ramp/ 101 wait mechanism with a test for change in sc. 102 103 * Implement "quadratic taper" or similar non- 104 linear transform of the output. The EG will 105 have to generate a reasonably dense stream 106 of voice control events, since voice ramps 107 are still linear. 108 */ 109 110 /* Audio Patch Parameters */ 111 typedef enum 112 { 113 APP_FIRST = 0, 114 /* Patch Driver Plugin */ 115 APP_DRIVER = 0, /* (int) Patch driver index */ 116 117 /* Oscillator */ 118 APP_WAVE, /* (int) Waveform index */ 119 120 /* "Special" features */ 121 APP_RANDPITCH, /* (fixp) Random pitch depth */ 122 APP_RANDVOL, /* (fixp) Random volume depth */ 123 124 /* Envelope Generator */ 125 APP_ENV_SKIP, /* (bool) skip to sustain on CE_STOP */ 126 APP_ENV_L0, /* (fixp) envelope level 0 (initial) */ 127 APP_ENV_DELAY, /* (fixp) envelope delay-to-attack */ 128 APP_ENV_T1, /* (fixp) envelope attack time */ 129 APP_ENV_L1, /* (fixp) envelope hold level */ 130 APP_ENV_HOLD, /* (fixp) envelope hold time */ 131 APP_ENV_T2, /* (fixp) envelope decay time */ 132 APP_ENV_L2, /* (fixp) envelope sustain level */ 133 APP_ENV_T3, /* (fixp) envelope sustain time */ 134 APP_ENV_T4, /* (fixp) envelope release time */ 135 136 /* LFO Generator */ 137 APP_LFO_DELAY, /* (fixp) LFO delay-to-start */ 138 APP_LFO_ATTACK, /* (fixp) LFO attack time-to-full */ 139 APP_LFO_DECAY, /* (fixp) LFO decay time-to-zero */ 140 APP_LFO_RATE, /* (fixp) LFO frequency */ 141 APP_LFO_SHAPE, /* (int) LFO modulation waveform */ 142 143 /* Modulation Matrix */ 144 APP_ENV2PITCH, /* (fixp) */ 145 APP_ENV2VOL, /* (fixp) */ 146 APP_LFO2PITCH, /* (fixp) */ 147 APP_LFO2VOL, /* (fixp) */ 148 #if 0 149 APP_ENV2CUT, /* (fixp) */ 150 APP_LFO2CUT, /* (fixp) */ 151 TODO: 152 /* 153 * Controls for the resonant filter 154 * (Setting CUT to 0 disables the filter.) 155 */ 156 APP_FILT_CUT, /* (fixp) Filter cutoff */ 157 APP_FILT_RES, /* (fixp) Filter resonance */ 158 159 /* 160 * Distortion control 161 */ 162 APP_DIST_GAIN, /* (fixp) Pre-limiter gain */ 163 APP_DIST_CLIP, /* (fixp) Limiter clip threshold */ 164 APP_DIST_DRIVE, /* (fixp) Feedback from the clipped peaks */ 165 #endif 166 APP_COUNT, 167 APP_LAST = APP_COUNT - 1 168 } audio_pparams_t; 169 typedef int appbank_t[APP_COUNT]; 170 171 172 /* 173 * The voice structure: 174 * OSC -> VOL/PAN/SEND 175 * | | 176 * | : '-> o-> FX BUS 0 177 * '-----> o-> FX BUS 1 178 * : : ... ... 179 * : : o-> FX BUS N-1 180 * 181 * That's it! No filters, and just one oscillator. The 182 * interesting part is the output section. 183 * 184 * Every voice has two output bus selectors, each on 185 * referencing a stereo bus, on which further 186 * processing may be applied. By setting either bus 187 * selector to -1, or by pointing both at the same bus, 188 * only the Primary Output will be used, and some some 189 * CPU power is saved during mixing. :-) 190 * 191 * As opposed to most MIDI synths, this engine allows 192 * you to select one or two output busses for each 193 * voice, using one as the Primary Output (level set 194 * by CC7: Volume) and the other as the Secondary 195 * Output (level set by CC91: Reverb Depth, multiplied 196 * by CC7.) 197 * 198 * The MIDI implementation uses CC92 and CC94 to select 199 * Primary and Secondary Output busses, respectively. 200 */ 201 202 /* 203 * Audio Channel & Group Controls 204 FIXME: Channels use all, groups use a subset - which sucks! 205 FIXME: I've considered using the OpenGL approach with a single, 206 FIXME: global enum - but that can only provide runtime "enum 207 FIXME: type checking". Seems like only languages other than the 208 FIXME: native language of this engine can do it right... 209 FIXME: (Another reason to use EEL wherever possible.) 210 * 211 * The Priority System: 212 * Set ACC_PRIORITY to 0 to have a channel grab a 213 * voice, and have it excluded from the dynamic 214 * voice allocation system. 215 * 216 * Other values specify channel priority for voice 217 * stealing - higher values mean lower priority. 218 * Higher priority channels win when fighting for 219 * voices. Priority 0 voices cannot be stolen. 220 */ 221 222 typedef enum 223 { 224 ACC_FIRST = 0, 225 /*--- Controls that are NOT transformed ---*/ 226 ACC_GROUP = 0, /* mixer group */ 227 ACC_PRIORITY, /* Voice Allocation Priority */ 228 ACC_PATCH, /* (int) Patch index */ 229 230 ACC_PRIM_BUS, /* (int) target bus for ACC_VOLUME */ 231 ACC_SEND_BUS, /* (int) target bus for ACC_SEND */ 232 233 /*--- Controls that are transformed by adding ---*/ 234 ACC_PAN, /* (fixp[-1, 1]) pre-send pan */ 235 ACC_PITCH, /* (fixp) linear frequency; int <==> MIDI */ 236 237 /*--- Controls that are transformed by multiplying ---*/ 238 ACC_VOLUME, /* (fixp) primary "send" level */ 239 ACC_SEND, /* (fixp) secondary send level */ 240 241 /*--- Patch Controls (Not transformed) ---*/ 242 ACC_MOD1, /* (fixp) Modulation 1 depth */ 243 ACC_MOD2, /* (fixp) Modulation 2 depth */ 244 ACC_MOD3, /* (fixp) Modulation 3 depth */ 245 246 ACC_X, /* (fixp) X position */ 247 ACC_Y, /* (fixp) Y position */ 248 ACC_Z, /* (fixp) Z position */ 249 250 ACC_COUNT, 251 ACC_LAST = ACC_COUNT - 1 252 } audio_ctls_t; 253 typedef int accbank_t[ACC_COUNT]; 254 255 256 /* 257 * Bus Control: 258 * The first 8 MIDI channels can be used for controlling 259 * the signal processing done between the busses, and 260 * between the busses and the output buffer. 261 * 262 * A set of non-standard MIDI CCs are used for this: 263 * CC 39: Select Insert Slot for subsequent CCs. 264 * 265 * Slot 0 is used to access the dry/pre insert send level 266 * controls. Thus, CCs 40..45 are ignored for slot 0. 267 * 268 * The FX parameter CC range is mapped to according to 269 * [0, 128] ==> [0.0, 2.0]. (That is, you can't reach the 270 * exact value of 2.0, as the highest CC value is 127.) 271 * CC 40: Insert Effect Type 272 * CC 41: Insert Effect Parameter 1 (Time 1) 273 * CC 42: Insert Effect Parameter 2 (Time 2) 274 * CC 43: Insert Effect Parameter 3 (Depth 1) 275 * CC 44: Insert Effect Parameter 4 (Depth 2) 276 * CC 45: Insert Effect Parameter 5 (Rate) 277 * 278 * This one is not transformed at all - MIDI CCs 0..127 279 * are used directly. Obviously, it's preferred that 280 * plugins map integer parameters that fit in that range 281 * to Parameter 6. 282 * CC 46: Insert Effect Parameter 6 (Mode/Special) 283 * 284 * The following CC doubles as "dry send to master", when 285 * used on slot 0. 286 * CC 47: Post insert send to master ("Wet") 287 * 288 * The next set of CC are IMHO, a bit dodgy in the current 289 * implementation. Indeed, they work, but you have to 290 * accept that the engine processes the busses in a fixed 291 * order, meaning that you can only send from lower number 292 * busses to higher number busses - not the other way 293 * around. (In fact, the engine won't even consider the 294 * controls for the "broken" connections when mixing.) 295 * 296 * Note that when used on slot 0, these act as *dry* send 297 * levels, as there cannot be an insert in slot 0. 298 * CC 48: Post insert send to bus 1 299 * CC 49: Post insert send to bus 2 300 * CC 50: Post insert send to bus 3 301 * CC 51: Post insert send to bus 4 302 * CC 52: Post insert send to bus 5 303 * CC 53: Post insert send to bus 6 304 * CC 54: Post insert send to bus 7 305 * CC 55: Post insert send to bus 8 306 * 307 * Note that the post insert sends won't be considered 308 * if no effect is enabled. (They would just double the 309 * functionality of the pre insert sends, for extra cost 310 * and no use.) 311 */ 312 313 /* Audio Bus Controls */ 314 typedef enum 315 { 316 ABC_FIRST = 0, 317 318 /* NOTE: The ABC_FX_* controls of slot 0 are ignored! */ 319 ABC_FX_TYPE = 0, /* (int) */ 320 ABC_FX_PARAM_1, /* (fixp) Time/f/Amount 1 */ 321 ABC_FX_PARAM_2, /* (fixp) Time/f/Amount 2 */ 322 ABC_FX_PARAM_3, /* (fixp) Depth/Level 1 */ 323 ABC_FX_PARAM_4, /* (fixp) Depth/Level 2 */ 324 ABC_FX_PARAM_5, /* (fixp) Rate/Level */ 325 ABC_FX_PARAM_6, /* (int) Mode/Special */ 326 327 ABC_SEND_MASTER, /* (fixp) Post FX send to master */ 328 329 ABC_SEND_BUS_0, /* (fixp) Post FX send to bus 0 */ 330 ABC_SEND_BUS_1, /* (fixp) Post FX send to bus 1 */ 331 ABC_SEND_BUS_2, /* (fixp) Post FX send to bus 2 */ 332 ABC_SEND_BUS_3, /* (fixp) Post FX send to bus 3 */ 333 ABC_SEND_BUS_4, /* (fixp) Post FX send to bus 4 */ 334 ABC_SEND_BUS_5, /* (fixp) Post FX send to bus 5 */ 335 ABC_SEND_BUS_6, /* (fixp) Post FX send to bus 6 */ 336 ABC_SEND_BUS_7, /* (fixp) Post FX send to bus 7 */ 337 338 ABC_COUNT, 339 ABC_LAST = ABC_COUNT -1 340 } audio_busctls_t; 341 typedef int abcbank_t[ABC_COUNT]; 342 343 /* 344 * Generic Effect API - for busses and inserts. 345 */ 346 typedef enum 347 { 348 AFX_NONE = 0, 349 AFX_DELAY, /* 1: Tap 1 2: Tap 2 350 * 3: Gain 1 4: Gain 2 351 * 5: Feedback Level 352 */ 353 AFX_ECHO, /* 1: Ldelay 2: Rdelay 354 * 3: Lgain 4: Rgain 355 * 5: Feedback Delay 356 */ 357 AFX_REVERB, /* 1: Early reflections duration 358 * 2: Tail duration 359 * 3: Early reflections level 360 * 4: Tail Feedback Level 361 * 5: Feedback LP Cutoff 362 */ 363 AFX_CHORUS, /* 1: Left Vibrato Speed 364 * 2: Right Vibrato Speed 365 * 3: Left Vibrato Depth 366 * 4: Right Vibrato Depth 367 * 5: Feedback Level 368 */ 369 AFX_FLANGER, /* Same as chorus; only different scale. */ 370 AFX_FILTER, /* 1: Left Cut 2: Right Cut 371 * 3: Left Reso 4: Right Resonance 372 * 5: <unused> 373 */ 374 AFX_DIST, /* 1: Bass 2: Treble 375 * 3: Pre Gain 4: Post Gain 376 * 4: Drive 377 */ 378 AFX_WAH, /* 1: Low Limit 2: High Limit 379 * 3: Sensitivity 4: Gain 380 * 5: Resonance 381 */ 382 AFX_EQ, /* 1: Bass f 2: Treble f 383 * 3: Bass Gain 4: Treble Gain 384 * 4: Mid Gain 385 */ 386 AFX_ENHANCER, /* 1: Mid f 2: High f 387 * 3: Mid Sens. 4: High Sensitivity 388 * 5: Artificial Treble Strength 389 */ 390 AFX_COMPRESSOR, /* 1: Attack 2: Release 391 * 3: Gain 4: Threshold 392 * 5: Knee Softness 393 */ 394 AFX_MAXIMIZER /* 1: Low Split 2: High Split 395 * 3: Low Boost 4: High Boost 396 * 5: Mid Boost 397 */ 398 } audio_fxtypes_t; 399 400 401 typedef enum 402 { 403 AR_WORST = -3, 404 AR_MEDIUM = -2, 405 AR_BEST = -1, 406 407 AR_NEAREST = 0, /* Nearest sample ("useless") */ 408 AR_NEAREST_4X, /* Nearest with 4x oversampling */ 409 AR_LINEAR, /* Linear Interpolation */ 410 AR_LINEAR_2X_R, /* LI w/ 2x oversampling + ramp smoothing */ 411 AR_LINEAR_4X_R, /* LI w/ 4x oversampling + ramp smoothing */ 412 AR_LINEAR_8X_R, /* LI w/ 8x oversampling + ramp smoothing */ 413 AR_LINEAR_16X_R,/* LI w/ 16x oversampling + ramp smoothing */ 414 AR_CUBIC_R /* Cubic interpolation + ramp smoothing */ 415 } audio_resample_t; 416 417 418 typedef enum 419 { 420 AF_MONO8 = 0, /* Mono Sint8 */ 421 AF_STEREO8, /* Stereo Sint8 */ 422 AF_MONO16, /* Mono Sint16 */ 423 AF_STEREO16, /* Stereo Sint16 */ 424 AF_MONO32, /* Mono float32 */ 425 AF_STEREO32, /* Stereo float32 */ 426 AF_MIDI /* Midi sequence */ 427 } audio_formats_t; 428 429 430 typedef enum 431 { 432 AQ_VERY_LOW, /* Nearest, no oversampling */ 433 AQ_LOW, /* Nearest, 4x oversampling */ 434 AQ_NORMAL, /* Linear interpolation */ 435 AQ_HIGH, /* LI with adaptive oversampling 2x..8x */ 436 AQ_VERY_HIGH /* LI with fixed 16x oversampling */ 437 } audio_quality_t; 438 439 #undef A_USE_INT64 440 #ifdef SDL_HAS_64BIT_TYPE 441 # define A_USE_INT64 442 #endif 443 444 #endif /*_A_TYPES_H_*/ 445