1 2 /* 3 * Diverse SLab audio routines. 4 * Copyright (c) by Nick Copeland <nickycopeland@hotmail.com> 1996,2012 5 * 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 SLAB_DEFS 23 #define SLAB_DEFS 24 25 #ifdef SECONDARY_FLAGS 26 #define SAMPLE_RATE_SYNC 1 27 #define DEV_DISABLE 2 28 29 #if (BRISTOL_HAS_ALSA == 1) 30 #define AUDIO_ALSA 4 31 #endif 32 #endif 33 34 #define AUDIO_DUMMY 0x8000 35 36 #ifdef CD_WRITE 37 #define ISO_OPTS_COUNT 7 38 #endif 39 40 #ifdef CD_RECORD 41 #define ISO_OPTS_COUNT 6 42 #endif 43 44 /* 45 * This is to link into the libaudio routines. libslabaudio is provided in 46 * source code to improve compatibility with different audio drivers. 47 */ 48 #ifdef AUDIO_API 49 #define SL_SETAUDIODEVPARAM SL_setAudioDevParam2(&controlBuffer->adiod[0], 50 #else 51 #define SL_SETAUDIODEVPARAM SL_setAudioDevParam( 52 #endif 53 54 #ifdef MASTERING 55 #define MASTERING_MASK 0x00ff00 56 #define MASTER_CDR 0x100/* output daemon support for cdr master files */ 57 #ifdef MASTERING_WAV 58 #define MASTER_WAV 0x200/* output daemon support for wav master files */ 59 #endif 60 #ifdef MASTERING_MP3 61 #define MASTER_MP3 0x400/* output daemon support for mp3 master files */ 62 #endif 63 #define MASTER_RES3 0x1000/* output daemon support for some master files */ 64 #define MASTER_RES4 0x2000/* output daemon support for some master files */ 65 #define MASTER_RES5 0x4000/* output daemon support for some master files */ 66 #define MASTER_RES6 0x8000/* output daemon support for some master files */ 67 #endif 68 #define CD_TRACK_COUNT 32 69 70 #ifndef NULL 71 #define NULL 0 72 #endif 73 74 /* 75 * The following are for the audio net tap 76 */ 77 #define SLAB_INPUT_TAP 1 78 #define SLAB_OUTPUT_TAP 2 79 80 typedef struct cBuff *ControlBuffer; 81 82 typedef struct CAlgo { 83 mixAlgo algo; 84 short factor; 85 short pad1; 86 } cAlgo; 87 88 /* 89 * This is not used. The intention is error checking, since a PC can only 90 * reasonably support 4 cards at the moment. 91 */ 92 #define MAX_USED_DEVICES 4 93 /* 94 * I want to remove all references to PRIMARY nd SECONDARY devs, and use code 95 * that does for (i=0;s<MAX_DEVICES;i++) 96 */ 97 #define PRIMARY_DEV 0 98 #define SECONDARY_DEV 1 99 #define TERTIARY_DEV 2 100 101 #define ALL_DEVICES(x) for (x = 0; x < MAX_DEVICES; x++) 102 #ifdef ADIOD_MULTI 103 #define IF_ACTIVE(y, x) if (y->adiod[x].PID > 1) 104 #define ALL_ACTIVE_DEVICES(y, x) for (x = 0; x < MAX_DEVICES; x++) \ 105 if (y->adiod[x].PID > 1) 106 #endif 107 #define ALL_SLAVE_DEVICES(x) for (x = 1; x < MAX_DEVICES; x++) 108 109 #define MAX_TRACK_COUNT 64 110 111 #ifdef FX_CHAINS 112 #ifdef FLOAT_PROC 113 /* 114 * Float proc uses a busTrack for internal processing as well 115 */ 116 #define BUS_TRACK_COUNT 512 /* up to 512 active operations, 8 per track */ 117 #else 118 #define BUS_TRACK_COUNT 64 /* up to 64 active effects */ 119 #endif 120 #else 121 #define BUS_TRACK_COUNT 16 122 #endif 123 #define BUS_REAL_COUNT 16 /* These are the actual external FX busses */ 124 125 #define SEND_TRACKS 8 /* 8 mono send busses */ 126 #define AUX_TRACKS 8 /* 8 mono aux busses */ 127 #define BUS_TRACKS 4 /* 4 stereo mixdown busses */ 128 #define DEV_TRACKS MAX_DEVICES * 2 /* 2 stereo devices */ 129 #define ALL_TRACKS MAX_TRACK_COUNT + BUS_TRACKS + SEND_TRACKS + \ 130 AUX_TRACKS + DEV_TRACKS + 3 131 132 #define ALL_TRACK_INDECES(x) for (x = 0; x < MAX_TRACK_COUNT; x++) 133 134 /* 135 * These are for array indices 136 */ 137 #define MASTER MAX_TRACK_COUNT 138 #define MASTER_LEFT MASTER + 1 139 #define MASTER_RIGHT MASTER + 2 140 #define MASTER_LEFT2 MASTER + 3 141 #define MASTER_RIGHT2 MASTER + 4 142 #define BUS_0 MASTER_RIGHT2 + 1 143 #define BUS_1 BUS_0 + 1 144 #define BUS_2 BUS_1 + 1 145 #define BUS_3 BUS_2 + 1 146 #define BUS_4 BUS_3 + 1 147 148 #define SEND_0_BUS BUS_4 + 1 /* Send zero is "direct" */ 149 #define SEND_1_BUS SEND_0_BUS + 1 150 #define SEND_2_BUS SEND_1_BUS + 1 151 #define SEND_3_BUS SEND_2_BUS + 1 152 #define SEND_4_BUS SEND_3_BUS + 1 153 #define SEND_5_BUS SEND_4_BUS + 1 154 #define SEND_6_BUS SEND_5_BUS + 1 155 #define SEND_7_BUS SEND_6_BUS + 1 156 #define SEND_8_BUS SEND_7_BUS + 1 157 158 #define AUX_0_BUS SEND_8_BUS + 1 159 #define AUX_1_BUS AUX_0_BUS + 1 160 #define AUX_2_BUS AUX_1_BUS + 1 161 #define AUX_3_BUS AUX_2_BUS + 1 162 #define AUX_4_BUS AUX_3_BUS + 1 163 #define AUX_5_BUS AUX_4_BUS + 1 164 #define AUX_6_BUS AUX_5_BUS + 1 165 #define AUX_7_BUS AUX_6_BUS + 1 166 167 #define INTERPOLATE_8K 0x01 168 #define INTERPOLATE_22K 0x02 169 #define INTERP_MONO 0x04 170 #define INTERPOLATE 0x07 /* Any of the above */ 171 #define RE_RECORD 0x10 /* Re-record the main out signal */ 172 173 #define TAPE_MEM_COUNT 8 174 175 /* 176 * Introduced enumerations to try and prevent assigning command to the status 177 * variables, and vice versa. GCC does not check for this condition, 178 * however, so the only gain now is that we do not need to specify the 179 * commands or statii values explicitly. 180 */ 181 #define MIX_C_RESET 0 /* return to start of disk, lose any state info */ 182 #define MIX_C_GO 1 /* start pre-load from current locn */ 183 #define MIX_C_RECORD 2 /* start pre-load from current locn for recording */ 184 #define MIX_C_GO_INPUT 3 /* start pre-load from current location */ 185 #define MIX_C_GO_OUTPUT 4 /* start pre-load from current location */ 186 #define MIX_C_GO_DUPLEX 5 /* start pre-load from current location */ 187 #define MIX_C_GOTO 6 /* start-preload from current startOffest */ 188 #define MIX_C_STOP 7 /* stop current operations */ 189 #define MIX_C_CLOSE 8 /* close the current data file */ 190 #define MIX_C_OPEN 9 /* open new file as specified in trackName[] */ 191 #define MIX_C_SLEEP 10 /* request daemon go sleep. Will signal to awaken */ 192 #define MIX_C_IDLE 11 /* request daemon go idle. */ 193 #define MIX_C_SYN_REQ 12 194 #define MIX_C_PEND 13 195 #define MIX_C_EXIT -1 /* cleanup and clear out */ 196 197 /* 198 * As with the commands I would prefer to make this into a set of #define's 199 * as well. 200 */ 201 enum mixIOstatus { 202 MIX_S_WAITING = 0, 203 MIX_S_RUNNING, 204 MIX_S_LOADING, 205 MIX_S_WRITING, 206 MIX_S_EOF, 207 MIX_S_CLOSED_WAIT, /* no data file currently opened */ 208 MIX_S_SLEEPING, 209 MIX_S_IDLING, 210 MIX_S_SUCCEEDED, 211 MIX_S_SUCCEED_SLEEP, 212 MIX_S_FAILED, 213 MIX_S_FAILED_SLEEP, 214 MIX_S_SKIP, 215 MIX_S_EXIT = -1 216 }; 217 218 /* 219 * Compression definitions, should be in seperate file? 220 * 8 classes available, at the moment, only 2 are implemented 221 */ 222 #define COMP_CLASS_SIZE 3 223 #define COMP_INDEX_SIZE 4 224 #define DECOMP_METHOD_SIZE 3 225 226 #define COMP_CLASS_NONE 0 227 #define COMP_CLASS_LOSSY_2_TO_1 1 228 #define COMP_CLASS_LOSSY_4_TO_1 2 229 #define COMP_CLASS_NON_LOSSY_FIXED 3 /* Not implemented yet */ 230 #define COMP_CLASS_NON_LOSSY_VAR 4 /* Not implemented yet */ 231 232 #define COMP_INDEX_AMPLITUDE 0 /* This has been made default. */ 233 #define COMP_INDEX_TIME_DOMAIN 1 234 #define COMP_INDEX_HYBRID 2 /* This _should_ be made default */ 235 #define COMP_INDEX_SHIFT 3 236 237 /* 238 * Some flag definitions for the busParams: 239 */ 240 #define BUS_TYPE_SYNC 0x1 241 #ifdef FLOAT_PROC 242 #define BUS_TYPE_FLOAT 0x2 243 #endif 244 #define BUS_TYPE_SYNC 0x1 245 #ifdef FLOAT_PROC 246 #define BUS_TYPE_INSERT 0x01000 /* to support insert busses */ 247 #endif 248 #define BUS_STEREO 0x10000 /* not used */ 249 #define BUS_ON 0x20000 /* to enable disable effect */ 250 #ifdef FX_TRIMMING 251 #define BUS_TRIM_IN 0x40000 252 #define BUS_TRIM_OUT 0x80000 253 #endif 254 255 enum DiskStatus { 256 MIX_TRACK_CLOSED = 0, 257 MIX_TRACK_OPEN, 258 MIX_TRACK_FAILED 259 }; 260 261 /* 262 * Textual status for IO daemon 263 */ 264 #define MIXIO_OKAY "okay" 265 #define MIXIO_OKAY_WAIT "waiting" 266 #define MIXIO_OKAY_LOAD "loading" 267 #define MIXIO_SLEEPING "sleeping" 268 269 #define REC1 1 270 #define REC2 2 271 272 #define AU_LEFT 0 273 #define AU_RIGHT 1 274 #define LEFT 1 275 #define RIGHT 2 276 #define LEFT2 4 277 #define RIGHT2 8 278 279 #define SET 1 280 #define GET 2 281 282 #ifdef SLAB_PIPO 283 /* 284 * Really want this to be a configurable parameter. 285 */ 286 #define X_RATE 256 287 #endif 288 289 /* 290 * Scratch types 291 */ 292 #define MONO_SCRATCH 0 293 #define STEREO_SCRATCH 1 294 #define HYBRID_SCRATCH 2 295 296 /* 297 * Pick a couple of arbitrary constants to identify our own shared 298 * memory segments. 299 * 300 * Should really make these contiguous: 301 * CONTROL_KEY 130465 302 * DISK_BUFFER_KEY CONTROL_KEY+1 303 * etc. 304 * This would allow management of multiple engines, each with its own shared 305 * memory and other segments. FFS. 306 */ 307 #define CONTROL_KEY 130465 308 #define AI_BUFFER_KEY 280364 309 #define AO_BUFFER_KEY 251265 310 #define AO2_BUFFER_KEY 251266 311 #define DISK_BUFFER_KEY 251264 312 #define BUS_BUFFER_KEY 251273 313 314 /* 315 * This should really be calculated. The problem with Sun is the MAX SHMEM 316 * segment appears to be 1MB. If the blockSampleSize is 8k, then we very soon 317 * sun out of space for diskbuffering of large track counts. The calculation 318 * should be something like 1MB/(trackCount*blockSampleSize)). FFS. 319 */ 320 #define BUS_BUFFER_WINDOW 4 321 #define DISK_BUFFER_WINDOW 8 322 323 #define OUTPUT_BUFFER_WINDOW 4 324 325 /* 326 * Set of commands for the "virtual tape" 327 */ 328 #define TAPE_STOP 0 329 #define TAPE_START 1 /* This is just a continue operation */ 330 #define TAPE_CONT 1 331 332 /* 333 * Track commands 334 */ 335 #define SAMPLE_RATE 0 336 #define RESOLUTION 1 337 #define TRACK_COUNT 2 338 #define BLK_SMPL_CNT 4 339 #define WRITE_SAMPLE_RATE 8 340 #define OUT_BUF_WIN 0x10 341 342 #define SLAB_MUTE 1 343 #define SLAB_SOLO 2 344 #define SLAB_BOOST 4 345 #define SLAB_ALTMUTE 8 346 347 #define SLAB_MERGE_CODE 0x1 348 #define SLAB_NORMALISE_CODE 0x2 349 #define SLAB_REVERSE_CODE 0x4 350 351 #define SLAB_MERGE SLAB_OPCODE_BIT | SLAB_MERGE_CODE 352 #define SLAB_NORMALISE SLAB_OPCODE_BIT | SLAB_NORMALISE_CODE 353 #define SLAB_REVERSE SLAB_OPCODE_BIT | SLAB_REVERSE_CODE 354 355 #define MONO_CAPABILITIES(x) controlBuffer->adiod[x].monoCaps 356 #define STEREO_CAPABILITIES(x) controlBuffer->adiod[x].stereoCaps 357 #define ALL_CAPABILITIES(x) \ 358 (controlBuffer->adiod[x].stereoCaps | controlBuffer->adiod[x].monoCaps) 359 #define ALL_DEV2_CAPABILITIES \ 360 (controlBuffer->adiod[x].stereoCaps | controlBuffer->adiod[x].monoCaps) 361 362 #define CLIP16(x) x>32767? 32767:x < -32767? -32767:x 363 #define CLIP24(x) x>8388607? 32767:x < -8388608? -32768:x>>8 364 #define CLIP32(x) CLIP24(x) 365 #define CLIPFLOAT(x) x>32767? 32767:x < -32768? -32768:x 366 367 /* 368 * This is for 24->8 internal format to 8bits external 369 * 370 * Any truncation algorithm is going to be noisy. The different resolutions 371 * will improve the signal to noise ratio, but some will introduce clipping 372 * rather than quantisation errors. 373 * 374 * Also, they will significantly alter the volume of the output signal unless 375 * shifted by 16 bits, which can be extremely annoying during recording. This 376 * is to be compensated by an automatic output volume adjustment on record 377 * start/stop? 378 * [This would not be advisable since it would also adjust the input instrument 379 * volume, we will have to go for a reduction in PCM level]. 380 */ 381 #define CLIP24_8(x) x>8388607? 127:x < -8388608? -128:x>>16 382 #define CLIP24_8_1(x) x>4194303? 127:x < -4194304? -128:x>>15 383 #define CLIP24_8_2(x) x>2097151? 127:x < -2097152? -128:x>>14 384 #define CLIP24_8_3(x) x>1048575? 127:x < -1048576? -128:x>>13 385 386 #define CLIPFLOAT_8(x) x>32767? 127:x < -32768? -128:x/128 387 #define CLIPFLOAT_8_1(x) x>16383? 127:x < -16384? -128:x/64 388 #define CLIPFLOAT_8_2(x) x>8191? 127:x < -8192? -128:x/32 389 #define CLIPFLOAT_8_3(x) x>4095? 127:x < -4096? -128:x/16 390 391 #define CHECK_MAX16(x, y) x = (y>=0)? (y>x? y:x): ((-y)>x)? -y:x; 392 #define CHECK_MAXFLOAT(x, y) x = (y>=0)? (y>x? y:x): ((-y)>x)? -y:x; 393 #define CHECK_MAX CHECK_MAX16 394 395 /* 396 * This looks ugly, but its just looks at the size of the delta. As delta (x) 397 * exceeds the limit (y) but increasing amounts, it is reduced but a respective 398 * Q factor. 399 * First uses BLim, second uses delta to be reduced. 400 */ 401 #define applyQfactor(x, y, z) (x > (y << 3)? y >> (z + 4): \ 402 x > (y << 2)? y >> (z + 3): x > (y << 1)? y >> (z + 1): x > y? y:x) 403 #define applyQfactor2(x, y, z) (x > (y << 3)? x >> (z + 4): \ 404 x > (y << 2)? x >> (z + 3): x > (y << 1)? x >> (z + 1): x > y? y:x) 405 406 #ifndef TEST 407 /* 408 * If doing TEST, this divide will error? 409 */ 410 #define MAKE_LOCN(x) x / (controlBuffer->trackDesc.trackCount * \ 411 (controlBuffer->trackDesc.resolution >> 3)) 412 #define MAKE_INTERNAL(x) ((x & ~(controlBuffer->blockSampleSize - 1)) * \ 413 controlBuffer->trackDesc.trackCount * \ 414 controlBuffer->trackDesc.resolution >> 3) 415 #else 416 #define MAKE_LOCN(x) x 417 #endif 418 419 #define MAKE_SAMPLE(x) x * (controlBuffer->trackDesc.trackCount * \ 420 (controlBuffer->trackDesc.resolution >> 3)) 421 422 #define E_FILTER_BIT 1 423 #define E_SEND1_BIT 2 424 #define E_SEND2_BIT 3 425 #define E_SEND3_BIT 4 426 #define E_SEND4_BIT 5 427 #define E_SEND5_BIT 6 428 #define E_SEND6_BIT 7 429 #define E_SEND7_BIT 8 430 #define E_SEND8_BIT 9 431 #define E_SEND9_BIT 10 432 #define E_SEND10_BIT 11 433 #define E_SEND11_BIT 12 434 #define E_SEND12_BIT 13 435 #define E_SEND13_BIT 14 436 #define E_SEND14_BIT 15 437 #define E_SEND15_BIT 16 438 #define E_SEND16_BIT 17 439 #define E_FIND_MAX_BIT 18 440 #define E_DYNAMICS_BIT 19 441 #define E_MIDI_BIT 20 442 443 #define E_FILTER (1<<E_FILTER_BIT) 444 #define E_SEND1 (1<<E_SEND1_BIT) 445 #define E_SEND2 (1<<E_SEND2_BIT) 446 #define E_SEND3 (1<<E_SEND3_BIT) 447 #define E_SEND4 (1<<E_SEND4_BIT) 448 #define E_SEND5 (1<<E_SEND5_BIT) 449 #define E_SEND6 (1<<E_SEND6_BIT) 450 #define E_SEND7 (1<<E_SEND7_BIT) 451 #define E_SEND8 (1<<E_SEND8_BIT) 452 #define E_SEND9 (1<<E_SEND9_BIT) 453 #define E_SEND10 (1<<E_SEND10_BIT) 454 #define E_SEND11 (1<<E_SEND11_BIT) 455 #define E_SEND12 (1<<E_SEND12_BIT) 456 #define E_SEND13 (1<<E_SEND13_BIT) 457 #define E_SEND14 (1<<E_SEND14_BIT) 458 #define E_SEND15 (1<<E_SEND15_BIT) 459 #define E_SEND16 (1<<E_SEND16_BIT) 460 #define E_FIND_MAX (1<<E_FIND_MAX_BIT) 461 #define E_DYNAMICS (1<<E_DYNAMICS_BIT) 462 #define E_MIDI (1<<E_MIDI_BIT) 463 464 #define MAKE_SENDMASK(x) (2<<(x)) 465 466 #define E_FILTER_MASK ~E_FILTER 467 #define E_SEND1_MASK ~E_SEND1_BIT 468 #define E_SEND2_MASK ~E_SEND2_BIT 469 #define E_SEND3_MASK ~E_SEND3_BIT 470 #define E_SEND4_MASK ~E_SEND4_BIT 471 #define E_SEND5_MASK ~E_SEND5_BIT 472 #define E_SEND6_MASK ~E_SEND6_BIT 473 #define E_SEND7_MASK ~E_SEND7_BIT 474 #define E_SEND8_MASK ~E_SEND8_BIT 475 #define E_SEND9_MASK ~E_SEND9_BIT 476 #define E_SEND10_MASK ~E_SEND10_BIT 477 #define E_SEND11_MASK ~E_SEND11_BIT 478 #define E_SEND12_MASK ~E_SEND12_BIT 479 #define E_SEND13_MASK ~E_SEND13_BIT 480 #define E_SEND14_MASK ~E_SEND14_BIT 481 #define E_SEND15_MASK ~E_SEND15_BIT 482 #define E_SEND16_MASK ~E_SEND16_BIT 483 484 /* 485 * A few file locations 486 */ 487 #define SLAB_HOME "SLAB_HOME" 488 489 #define DEFAULT_LOCATION "/usr/local/slab" 490 491 #define DIR_NAME_LEN 256 492 #define DATA_BASE "../dataBase" 493 #define CD_FILE_DIR "/tapes" 494 #define EFFECTS_DIR "/effects" 495 #define ENGINE_DIR "/bin" 496 #define TMP_DIR "/tmp" 497 498 #define FORMAT_BARS 1001 499 #define FORMAT_BEATS 1002 500 #define FORMAT_MINSEC 1003 501 502 #endif /* SLAB_DEFS */ 503 504