Atlas - SDL_audio_channel_converters.h

Home / ext / SDL / src / audio Lines: 1 | Size: 34167 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)]
[FILE BEGIN]
1/* 2 Simple DirectMedia Layer 3 Copyright (C) 1997-2025 Sam Lantinga <[email protected]> 4 5 This software is provided 'as-is', without any express or implied 6 warranty. In no event will the authors be held liable for any damages 7 arising from the use of this software. 8 9 Permission is granted to anyone to use this software for any purpose, 10 including commercial applications, and to alter it and redistribute it 11 freely, subject to the following restrictions: 12 13 1. The origin of this software must not be misrepresented; you must not 14 claim that you wrote the original software. If you use this software 15 in a product, an acknowledgment in the product documentation would be 16 appreciated but is not required. 17 2. Altered source versions must be plainly marked as such, and must not be 18 misrepresented as being the original software. 19 3. This notice may not be removed or altered from any source distribution. 20*/ 21 22// DO NOT EDIT, THIS FILE WAS GENERATED BY build-scripts/gen_audio_channel_conversion.c 23 24 25typedef void (*SDL_AudioChannelConverter)(float *dst, const float *src, int num_frames); 26 27static void SDL_ConvertMonoToStereo(float *dst, const float *src, int num_frames) 28{ 29 int i; 30 31 LOG_DEBUG_AUDIO_CONVERT("mono", "stereo"); 32 33 // convert backwards, since output is growing in-place. 34 src += (num_frames-1); 35 dst += (num_frames-1) * 2; 36 for (i = num_frames; i; i--, src--, dst -= 2) { 37 const float srcFC = src[0]; 38 dst[1] /* FR */ = srcFC; 39 dst[0] /* FL */ = srcFC; 40 } 41 42} 43 44static void SDL_ConvertMonoTo21(float *dst, const float *src, int num_frames) 45{ 46 int i; 47 48 LOG_DEBUG_AUDIO_CONVERT("mono", "2.1"); 49 50 // convert backwards, since output is growing in-place. 51 src += (num_frames-1); 52 dst += (num_frames-1) * 3; 53 for (i = num_frames; i; i--, src--, dst -= 3) { 54 const float srcFC = src[0]; 55 dst[2] /* LFE */ = 0.0f; 56 dst[1] /* FR */ = srcFC; 57 dst[0] /* FL */ = srcFC; 58 } 59 60} 61 62static void SDL_ConvertMonoToQuad(float *dst, const float *src, int num_frames) 63{ 64 int i; 65 66 LOG_DEBUG_AUDIO_CONVERT("mono", "quad"); 67 68 // convert backwards, since output is growing in-place. 69 src += (num_frames-1); 70 dst += (num_frames-1) * 4; 71 for (i = num_frames; i; i--, src--, dst -= 4) { 72 const float srcFC = src[0]; 73 dst[3] /* BR */ = 0.0f; 74 dst[2] /* BL */ = 0.0f; 75 dst[1] /* FR */ = srcFC; 76 dst[0] /* FL */ = srcFC; 77 } 78 79} 80 81static void SDL_ConvertMonoTo41(float *dst, const float *src, int num_frames) 82{ 83 int i; 84 85 LOG_DEBUG_AUDIO_CONVERT("mono", "4.1"); 86 87 // convert backwards, since output is growing in-place. 88 src += (num_frames-1); 89 dst += (num_frames-1) * 5; 90 for (i = num_frames; i; i--, src--, dst -= 5) { 91 const float srcFC = src[0]; 92 dst[4] /* BR */ = 0.0f; 93 dst[3] /* BL */ = 0.0f; 94 dst[2] /* LFE */ = 0.0f; 95 dst[1] /* FR */ = srcFC; 96 dst[0] /* FL */ = srcFC; 97 } 98 99} 100 101static void SDL_ConvertMonoTo51(float *dst, const float *src, int num_frames) 102{ 103 int i; 104 105 LOG_DEBUG_AUDIO_CONVERT("mono", "5.1"); 106 107 // convert backwards, since output is growing in-place. 108 src += (num_frames-1); 109 dst += (num_frames-1) * 6; 110 for (i = num_frames; i; i--, src--, dst -= 6) { 111 const float srcFC = src[0]; 112 dst[5] /* BR */ = 0.0f; 113 dst[4] /* BL */ = 0.0f; 114 dst[3] /* LFE */ = 0.0f; 115 dst[2] /* FC */ = 0.0f; 116 dst[1] /* FR */ = srcFC; 117 dst[0] /* FL */ = srcFC; 118 } 119 120} 121 122static void SDL_ConvertMonoTo61(float *dst, const float *src, int num_frames) 123{ 124 int i; 125 126 LOG_DEBUG_AUDIO_CONVERT("mono", "6.1"); 127 128 // convert backwards, since output is growing in-place. 129 src += (num_frames-1); 130 dst += (num_frames-1) * 7; 131 for (i = num_frames; i; i--, src--, dst -= 7) { 132 const float srcFC = src[0]; 133 dst[6] /* SR */ = 0.0f; 134 dst[5] /* SL */ = 0.0f; 135 dst[4] /* BC */ = 0.0f; 136 dst[3] /* LFE */ = 0.0f; 137 dst[2] /* FC */ = 0.0f; 138 dst[1] /* FR */ = srcFC; 139 dst[0] /* FL */ = srcFC; 140 } 141 142} 143 144static void SDL_ConvertMonoTo71(float *dst, const float *src, int num_frames) 145{ 146 int i; 147 148 LOG_DEBUG_AUDIO_CONVERT("mono", "7.1"); 149 150 // convert backwards, since output is growing in-place. 151 src += (num_frames-1); 152 dst += (num_frames-1) * 8; 153 for (i = num_frames; i; i--, src--, dst -= 8) { 154 const float srcFC = src[0]; 155 dst[7] /* SR */ = 0.0f; 156 dst[6] /* SL */ = 0.0f; 157 dst[5] /* BR */ = 0.0f; 158 dst[4] /* BL */ = 0.0f; 159 dst[3] /* LFE */ = 0.0f; 160 dst[2] /* FC */ = 0.0f; 161 dst[1] /* FR */ = srcFC; 162 dst[0] /* FL */ = srcFC; 163 } 164 165} 166 167static void SDL_ConvertStereoToMono(float *dst, const float *src, int num_frames) 168{ 169 int i; 170 171 LOG_DEBUG_AUDIO_CONVERT("stereo", "mono"); 172 173 for (i = num_frames; i; i--, src += 2, dst++) { 174 dst[0] /* FC */ = (src[0] * 0.500000000f) + (src[1] * 0.500000000f); 175 } 176 177} 178 179static void SDL_ConvertStereoTo21(float *dst, const float *src, int num_frames) 180{ 181 int i; 182 183 LOG_DEBUG_AUDIO_CONVERT("stereo", "2.1"); 184 185 // convert backwards, since output is growing in-place. 186 src += (num_frames-1) * 2; 187 dst += (num_frames-1) * 3; 188 for (i = num_frames; i; i--, src -= 2, dst -= 3) { 189 dst[2] /* LFE */ = 0.0f; 190 dst[1] /* FR */ = src[1]; 191 dst[0] /* FL */ = src[0]; 192 } 193 194} 195 196static void SDL_ConvertStereoToQuad(float *dst, const float *src, int num_frames) 197{ 198 int i; 199 200 LOG_DEBUG_AUDIO_CONVERT("stereo", "quad"); 201 202 // convert backwards, since output is growing in-place. 203 src += (num_frames-1) * 2; 204 dst += (num_frames-1) * 4; 205 for (i = num_frames; i; i--, src -= 2, dst -= 4) { 206 dst[3] /* BR */ = 0.0f; 207 dst[2] /* BL */ = 0.0f; 208 dst[1] /* FR */ = src[1]; 209 dst[0] /* FL */ = src[0]; 210 } 211 212} 213 214static void SDL_ConvertStereoTo41(float *dst, const float *src, int num_frames) 215{ 216 int i; 217 218 LOG_DEBUG_AUDIO_CONVERT("stereo", "4.1"); 219 220 // convert backwards, since output is growing in-place. 221 src += (num_frames-1) * 2; 222 dst += (num_frames-1) * 5; 223 for (i = num_frames; i; i--, src -= 2, dst -= 5) { 224 dst[4] /* BR */ = 0.0f; 225 dst[3] /* BL */ = 0.0f; 226 dst[2] /* LFE */ = 0.0f; 227 dst[1] /* FR */ = src[1]; 228 dst[0] /* FL */ = src[0]; 229 } 230 231} 232 233static void SDL_ConvertStereoTo51(float *dst, const float *src, int num_frames) 234{ 235 int i; 236 237 LOG_DEBUG_AUDIO_CONVERT("stereo", "5.1"); 238 239 // convert backwards, since output is growing in-place. 240 src += (num_frames-1) * 2; 241 dst += (num_frames-1) * 6; 242 for (i = num_frames; i; i--, src -= 2, dst -= 6) { 243 dst[5] /* BR */ = 0.0f; 244 dst[4] /* BL */ = 0.0f; 245 dst[3] /* LFE */ = 0.0f; 246 dst[2] /* FC */ = 0.0f; 247 dst[1] /* FR */ = src[1]; 248 dst[0] /* FL */ = src[0]; 249 } 250 251} 252 253static void SDL_ConvertStereoTo61(float *dst, const float *src, int num_frames) 254{ 255 int i; 256 257 LOG_DEBUG_AUDIO_CONVERT("stereo", "6.1"); 258 259 // convert backwards, since output is growing in-place. 260 src += (num_frames-1) * 2; 261 dst += (num_frames-1) * 7; 262 for (i = num_frames; i; i--, src -= 2, dst -= 7) { 263 dst[6] /* SR */ = 0.0f; 264 dst[5] /* SL */ = 0.0f; 265 dst[4] /* BC */ = 0.0f; 266 dst[3] /* LFE */ = 0.0f; 267 dst[2] /* FC */ = 0.0f; 268 dst[1] /* FR */ = src[1]; 269 dst[0] /* FL */ = src[0]; 270 } 271 272} 273 274static void SDL_ConvertStereoTo71(float *dst, const float *src, int num_frames) 275{ 276 int i; 277 278 LOG_DEBUG_AUDIO_CONVERT("stereo", "7.1"); 279 280 // convert backwards, since output is growing in-place. 281 src += (num_frames-1) * 2; 282 dst += (num_frames-1) * 8; 283 for (i = num_frames; i; i--, src -= 2, dst -= 8) { 284 dst[7] /* SR */ = 0.0f; 285 dst[6] /* SL */ = 0.0f; 286 dst[5] /* BR */ = 0.0f; 287 dst[4] /* BL */ = 0.0f; 288 dst[3] /* LFE */ = 0.0f; 289 dst[2] /* FC */ = 0.0f; 290 dst[1] /* FR */ = src[1]; 291 dst[0] /* FL */ = src[0]; 292 } 293 294} 295 296static void SDL_Convert21ToMono(float *dst, const float *src, int num_frames) 297{ 298 int i; 299 300 LOG_DEBUG_AUDIO_CONVERT("2.1", "mono"); 301 302 for (i = num_frames; i; i--, src += 3, dst++) { 303 dst[0] /* FC */ = (src[0] * 0.333333343f) + (src[1] * 0.333333343f) + (src[2] * 0.333333343f); 304 } 305 306} 307 308static void SDL_Convert21ToStereo(float *dst, const float *src, int num_frames) 309{ 310 int i; 311 312 LOG_DEBUG_AUDIO_CONVERT("2.1", "stereo"); 313 314 for (i = num_frames; i; i--, src += 3, dst += 2) { 315 const float srcLFE = src[2]; 316 dst[0] /* FL */ = (src[0] * 0.800000012f) + (srcLFE * 0.200000003f); 317 dst[1] /* FR */ = (src[1] * 0.800000012f) + (srcLFE * 0.200000003f); 318 } 319 320} 321 322static void SDL_Convert21ToQuad(float *dst, const float *src, int num_frames) 323{ 324 int i; 325 326 LOG_DEBUG_AUDIO_CONVERT("2.1", "quad"); 327 328 // convert backwards, since output is growing in-place. 329 src += (num_frames-1) * 3; 330 dst += (num_frames-1) * 4; 331 for (i = num_frames; i; i--, src -= 3, dst -= 4) { 332 const float srcLFE = src[2]; 333 dst[3] /* BR */ = (srcLFE * 0.111111112f); 334 dst[2] /* BL */ = (srcLFE * 0.111111112f); 335 dst[1] /* FR */ = (srcLFE * 0.111111112f) + (src[1] * 0.888888896f); 336 dst[0] /* FL */ = (srcLFE * 0.111111112f) + (src[0] * 0.888888896f); 337 } 338 339} 340 341static void SDL_Convert21To41(float *dst, const float *src, int num_frames) 342{ 343 int i; 344 345 LOG_DEBUG_AUDIO_CONVERT("2.1", "4.1"); 346 347 // convert backwards, since output is growing in-place. 348 src += (num_frames-1) * 3; 349 dst += (num_frames-1) * 5; 350 for (i = num_frames; i; i--, src -= 3, dst -= 5) { 351 dst[4] /* BR */ = 0.0f; 352 dst[3] /* BL */ = 0.0f; 353 dst[2] /* LFE */ = src[2]; 354 dst[1] /* FR */ = src[1]; 355 dst[0] /* FL */ = src[0]; 356 } 357 358} 359 360static void SDL_Convert21To51(float *dst, const float *src, int num_frames) 361{ 362 int i; 363 364 LOG_DEBUG_AUDIO_CONVERT("2.1", "5.1"); 365 366 // convert backwards, since output is growing in-place. 367 src += (num_frames-1) * 3; 368 dst += (num_frames-1) * 6; 369 for (i = num_frames; i; i--, src -= 3, dst -= 6) { 370 dst[5] /* BR */ = 0.0f; 371 dst[4] /* BL */ = 0.0f; 372 dst[3] /* LFE */ = src[2]; 373 dst[2] /* FC */ = 0.0f; 374 dst[1] /* FR */ = src[1]; 375 dst[0] /* FL */ = src[0]; 376 } 377 378} 379 380static void SDL_Convert21To61(float *dst, const float *src, int num_frames) 381{ 382 int i; 383 384 LOG_DEBUG_AUDIO_CONVERT("2.1", "6.1"); 385 386 // convert backwards, since output is growing in-place. 387 src += (num_frames-1) * 3; 388 dst += (num_frames-1) * 7; 389 for (i = num_frames; i; i--, src -= 3, dst -= 7) { 390 dst[6] /* SR */ = 0.0f; 391 dst[5] /* SL */ = 0.0f; 392 dst[4] /* BC */ = 0.0f; 393 dst[3] /* LFE */ = src[2]; 394 dst[2] /* FC */ = 0.0f; 395 dst[1] /* FR */ = src[1]; 396 dst[0] /* FL */ = src[0]; 397 } 398 399} 400 401static void SDL_Convert21To71(float *dst, const float *src, int num_frames) 402{ 403 int i; 404 405 LOG_DEBUG_AUDIO_CONVERT("2.1", "7.1"); 406 407 // convert backwards, since output is growing in-place. 408 src += (num_frames-1) * 3; 409 dst += (num_frames-1) * 8; 410 for (i = num_frames; i; i--, src -= 3, dst -= 8) { 411 dst[7] /* SR */ = 0.0f; 412 dst[6] /* SL */ = 0.0f; 413 dst[5] /* BR */ = 0.0f; 414 dst[4] /* BL */ = 0.0f; 415 dst[3] /* LFE */ = src[2]; 416 dst[2] /* FC */ = 0.0f; 417 dst[1] /* FR */ = src[1]; 418 dst[0] /* FL */ = src[0]; 419 } 420 421} 422 423static void SDL_ConvertQuadToMono(float *dst, const float *src, int num_frames) 424{ 425 int i; 426 427 LOG_DEBUG_AUDIO_CONVERT("quad", "mono"); 428 429 for (i = num_frames; i; i--, src += 4, dst++) { 430 dst[0] /* FC */ = (src[0] * 0.250000000f) + (src[1] * 0.250000000f) + (src[2] * 0.250000000f) + (src[3] * 0.250000000f); 431 } 432 433} 434 435static void SDL_ConvertQuadToStereo(float *dst, const float *src, int num_frames) 436{ 437 int i; 438 439 LOG_DEBUG_AUDIO_CONVERT("quad", "stereo"); 440 441 for (i = num_frames; i; i--, src += 4, dst += 2) { 442 const float srcBL = src[2]; 443 const float srcBR = src[3]; 444 dst[0] /* FL */ = (src[0] * 0.421000004f) + (srcBL * 0.358999997f) + (srcBR * 0.219999999f); 445 dst[1] /* FR */ = (src[1] * 0.421000004f) + (srcBL * 0.219999999f) + (srcBR * 0.358999997f); 446 } 447 448} 449 450static void SDL_ConvertQuadTo21(float *dst, const float *src, int num_frames) 451{ 452 int i; 453 454 LOG_DEBUG_AUDIO_CONVERT("quad", "2.1"); 455 456 for (i = num_frames; i; i--, src += 4, dst += 3) { 457 const float srcBL = src[2]; 458 const float srcBR = src[3]; 459 dst[0] /* FL */ = (src[0] * 0.421000004f) + (srcBL * 0.358999997f) + (srcBR * 0.219999999f); 460 dst[1] /* FR */ = (src[1] * 0.421000004f) + (srcBL * 0.219999999f) + (srcBR * 0.358999997f); 461 dst[2] /* LFE */ = 0.0f; 462 } 463 464} 465 466static void SDL_ConvertQuadTo41(float *dst, const float *src, int num_frames) 467{ 468 int i; 469 470 LOG_DEBUG_AUDIO_CONVERT("quad", "4.1"); 471 472 // convert backwards, since output is growing in-place. 473 src += (num_frames-1) * 4; 474 dst += (num_frames-1) * 5; 475 for (i = num_frames; i; i--, src -= 4, dst -= 5) { 476 dst[4] /* BR */ = src[3]; 477 dst[3] /* BL */ = src[2]; 478 dst[2] /* LFE */ = 0.0f; 479 dst[1] /* FR */ = src[1]; 480 dst[0] /* FL */ = src[0]; 481 } 482 483} 484 485static void SDL_ConvertQuadTo51(float *dst, const float *src, int num_frames) 486{ 487 int i; 488 489 LOG_DEBUG_AUDIO_CONVERT("quad", "5.1"); 490 491 // convert backwards, since output is growing in-place. 492 src += (num_frames-1) * 4; 493 dst += (num_frames-1) * 6; 494 for (i = num_frames; i; i--, src -= 4, dst -= 6) { 495 dst[5] /* BR */ = src[3]; 496 dst[4] /* BL */ = src[2]; 497 dst[3] /* LFE */ = 0.0f; 498 dst[2] /* FC */ = 0.0f; 499 dst[1] /* FR */ = src[1]; 500 dst[0] /* FL */ = src[0]; 501 } 502 503} 504 505static void SDL_ConvertQuadTo61(float *dst, const float *src, int num_frames) 506{ 507 int i; 508 509 LOG_DEBUG_AUDIO_CONVERT("quad", "6.1"); 510 511 // convert backwards, since output is growing in-place. 512 src += (num_frames-1) * 4; 513 dst += (num_frames-1) * 7; 514 for (i = num_frames; i; i--, src -= 4, dst -= 7) { 515 const float srcBL = src[2]; 516 const float srcBR = src[3]; 517 dst[6] /* SR */ = (srcBR * 0.796000004f); 518 dst[5] /* SL */ = (srcBL * 0.796000004f); 519 dst[4] /* BC */ = (srcBR * 0.500000000f) + (srcBL * 0.500000000f); 520 dst[3] /* LFE */ = 0.0f; 521 dst[2] /* FC */ = 0.0f; 522 dst[1] /* FR */ = (src[1] * 0.939999998f); 523 dst[0] /* FL */ = (src[0] * 0.939999998f); 524 } 525 526} 527 528static void SDL_ConvertQuadTo71(float *dst, const float *src, int num_frames) 529{ 530 int i; 531 532 LOG_DEBUG_AUDIO_CONVERT("quad", "7.1"); 533 534 // convert backwards, since output is growing in-place. 535 src += (num_frames-1) * 4; 536 dst += (num_frames-1) * 8; 537 for (i = num_frames; i; i--, src -= 4, dst -= 8) { 538 dst[7] /* SR */ = 0.0f; 539 dst[6] /* SL */ = 0.0f; 540 dst[5] /* BR */ = src[3]; 541 dst[4] /* BL */ = src[2]; 542 dst[3] /* LFE */ = 0.0f; 543 dst[2] /* FC */ = 0.0f; 544 dst[1] /* FR */ = src[1]; 545 dst[0] /* FL */ = src[0]; 546 } 547 548} 549 550static void SDL_Convert41ToMono(float *dst, const float *src, int num_frames) 551{ 552 int i; 553 554 LOG_DEBUG_AUDIO_CONVERT("4.1", "mono"); 555 556 for (i = num_frames; i; i--, src += 5, dst++) { 557 dst[0] /* FC */ = (src[0] * 0.200000003f) + (src[1] * 0.200000003f) + (src[2] * 0.200000003f) + (src[3] * 0.200000003f) + (src[4] * 0.200000003f); 558 } 559 560} 561 562static void SDL_Convert41ToStereo(float *dst, const float *src, int num_frames) 563{ 564 int i; 565 566 LOG_DEBUG_AUDIO_CONVERT("4.1", "stereo"); 567 568 for (i = num_frames; i; i--, src += 5, dst += 2) { 569 const float srcLFE = src[2]; 570 const float srcBL = src[3]; 571 const float srcBR = src[4]; 572 dst[0] /* FL */ = (src[0] * 0.374222219f) + (srcLFE * 0.111111112f) + (srcBL * 0.319111109f) + (srcBR * 0.195555553f); 573 dst[1] /* FR */ = (src[1] * 0.374222219f) + (srcLFE * 0.111111112f) + (srcBL * 0.195555553f) + (srcBR * 0.319111109f); 574 } 575 576} 577 578static void SDL_Convert41To21(float *dst, const float *src, int num_frames) 579{ 580 int i; 581 582 LOG_DEBUG_AUDIO_CONVERT("4.1", "2.1"); 583 584 for (i = num_frames; i; i--, src += 5, dst += 3) { 585 const float srcBL = src[3]; 586 const float srcBR = src[4]; 587 dst[0] /* FL */ = (src[0] * 0.421000004f) + (srcBL * 0.358999997f) + (srcBR * 0.219999999f); 588 dst[1] /* FR */ = (src[1] * 0.421000004f) + (srcBL * 0.219999999f) + (srcBR * 0.358999997f); 589 dst[2] /* LFE */ = src[2]; 590 } 591 592} 593 594static void SDL_Convert41ToQuad(float *dst, const float *src, int num_frames) 595{ 596 int i; 597 598 LOG_DEBUG_AUDIO_CONVERT("4.1", "quad"); 599 600 for (i = num_frames; i; i--, src += 5, dst += 4) { 601 const float srcLFE = src[2]; 602 dst[0] /* FL */ = (src[0] * 0.941176474f) + (srcLFE * 0.058823530f); 603 dst[1] /* FR */ = (src[1] * 0.941176474f) + (srcLFE * 0.058823530f); 604 dst[2] /* BL */ = (srcLFE * 0.058823530f) + (src[3] * 0.941176474f); 605 dst[3] /* BR */ = (srcLFE * 0.058823530f) + (src[4] * 0.941176474f); 606 } 607 608} 609 610static void SDL_Convert41To51(float *dst, const float *src, int num_frames) 611{ 612 int i; 613 614 LOG_DEBUG_AUDIO_CONVERT("4.1", "5.1"); 615 616 // convert backwards, since output is growing in-place. 617 src += (num_frames-1) * 5; 618 dst += (num_frames-1) * 6; 619 for (i = num_frames; i; i--, src -= 5, dst -= 6) { 620 dst[5] /* BR */ = src[4]; 621 dst[4] /* BL */ = src[3]; 622 dst[3] /* LFE */ = src[2]; 623 dst[2] /* FC */ = 0.0f; 624 dst[1] /* FR */ = src[1]; 625 dst[0] /* FL */ = src[0]; 626 } 627 628} 629 630static void SDL_Convert41To61(float *dst, const float *src, int num_frames) 631{ 632 int i; 633 634 LOG_DEBUG_AUDIO_CONVERT("4.1", "6.1"); 635 636 // convert backwards, since output is growing in-place. 637 src += (num_frames-1) * 5; 638 dst += (num_frames-1) * 7; 639 for (i = num_frames; i; i--, src -= 5, dst -= 7) { 640 const float srcBL = src[3]; 641 const float srcBR = src[4]; 642 dst[6] /* SR */ = (srcBR * 0.796000004f); 643 dst[5] /* SL */ = (srcBL * 0.796000004f); 644 dst[4] /* BC */ = (srcBR * 0.500000000f) + (srcBL * 0.500000000f); 645 dst[3] /* LFE */ = src[2]; 646 dst[2] /* FC */ = 0.0f; 647 dst[1] /* FR */ = (src[1] * 0.939999998f); 648 dst[0] /* FL */ = (src[0] * 0.939999998f); 649 } 650 651} 652 653static void SDL_Convert41To71(float *dst, const float *src, int num_frames) 654{ 655 int i; 656 657 LOG_DEBUG_AUDIO_CONVERT("4.1", "7.1"); 658 659 // convert backwards, since output is growing in-place. 660 src += (num_frames-1) * 5; 661 dst += (num_frames-1) * 8; 662 for (i = num_frames; i; i--, src -= 5, dst -= 8) { 663 dst[7] /* SR */ = 0.0f; 664 dst[6] /* SL */ = 0.0f; 665 dst[5] /* BR */ = src[4]; 666 dst[4] /* BL */ = src[3]; 667 dst[3] /* LFE */ = src[2]; 668 dst[2] /* FC */ = 0.0f; 669 dst[1] /* FR */ = src[1]; 670 dst[0] /* FL */ = src[0]; 671 } 672 673} 674 675static void SDL_Convert51ToMono(float *dst, const float *src, int num_frames) 676{ 677 int i; 678 679 LOG_DEBUG_AUDIO_CONVERT("5.1", "mono"); 680 681 for (i = num_frames; i; i--, src += 6, dst++) { 682 dst[0] /* FC */ = (src[0] * 0.166666672f) + (src[1] * 0.166666672f) + (src[2] * 0.166666672f) + (src[3] * 0.166666672f) + (src[4] * 0.166666672f) + (src[5] * 0.166666672f); 683 } 684 685} 686 687static void SDL_Convert51ToStereo(float *dst, const float *src, int num_frames) 688{ 689 int i; 690 691 LOG_DEBUG_AUDIO_CONVERT("5.1", "stereo"); 692 693 for (i = num_frames; i; i--, src += 6, dst += 2) { 694 const float srcFC = src[2]; 695 const float srcLFE = src[3]; 696 const float srcBL = src[4]; 697 const float srcBR = src[5]; 698 dst[0] /* FL */ = (src[0] * 0.294545442f) + (srcFC * 0.208181813f) + (srcLFE * 0.090909094f) + (srcBL * 0.251818180f) + (srcBR * 0.154545456f); 699 dst[1] /* FR */ = (src[1] * 0.294545442f) + (srcFC * 0.208181813f) + (srcLFE * 0.090909094f) + (srcBL * 0.154545456f) + (srcBR * 0.251818180f); 700 } 701 702} 703 704static void SDL_Convert51To21(float *dst, const float *src, int num_frames) 705{ 706 int i; 707 708 LOG_DEBUG_AUDIO_CONVERT("5.1", "2.1"); 709 710 for (i = num_frames; i; i--, src += 6, dst += 3) { 711 const float srcFC = src[2]; 712 const float srcBL = src[4]; 713 const float srcBR = src[5]; 714 dst[0] /* FL */ = (src[0] * 0.324000001f) + (srcFC * 0.229000002f) + (srcBL * 0.277000010f) + (srcBR * 0.170000002f); 715 dst[1] /* FR */ = (src[1] * 0.324000001f) + (srcFC * 0.229000002f) + (srcBL * 0.170000002f) + (srcBR * 0.277000010f); 716 dst[2] /* LFE */ = src[3]; 717 } 718 719} 720 721static void SDL_Convert51ToQuad(float *dst, const float *src, int num_frames) 722{ 723 int i; 724 725 LOG_DEBUG_AUDIO_CONVERT("5.1", "quad"); 726 727 for (i = num_frames; i; i--, src += 6, dst += 4) { 728 const float srcFC = src[2]; 729 const float srcLFE = src[3]; 730 dst[0] /* FL */ = (src[0] * 0.558095276f) + (srcFC * 0.394285709f) + (srcLFE * 0.047619049f); 731 dst[1] /* FR */ = (src[1] * 0.558095276f) + (srcFC * 0.394285709f) + (srcLFE * 0.047619049f); 732 dst[2] /* BL */ = (srcLFE * 0.047619049f) + (src[4] * 0.558095276f); 733 dst[3] /* BR */ = (srcLFE * 0.047619049f) + (src[5] * 0.558095276f); 734 } 735 736} 737 738static void SDL_Convert51To41(float *dst, const float *src, int num_frames) 739{ 740 int i; 741 742 LOG_DEBUG_AUDIO_CONVERT("5.1", "4.1"); 743 744 for (i = num_frames; i; i--, src += 6, dst += 5) { 745 const float srcFC = src[2]; 746 dst[0] /* FL */ = (src[0] * 0.586000025f) + (srcFC * 0.414000005f); 747 dst[1] /* FR */ = (src[1] * 0.586000025f) + (srcFC * 0.414000005f); 748 dst[2] /* LFE */ = src[3]; 749 dst[3] /* BL */ = (src[4] * 0.586000025f); 750 dst[4] /* BR */ = (src[5] * 0.586000025f); 751 } 752 753} 754 755static void SDL_Convert51To61(float *dst, const float *src, int num_frames) 756{ 757 int i; 758 759 LOG_DEBUG_AUDIO_CONVERT("5.1", "6.1"); 760 761 // convert backwards, since output is growing in-place. 762 src += (num_frames-1) * 6; 763 dst += (num_frames-1) * 7; 764 for (i = num_frames; i; i--, src -= 6, dst -= 7) { 765 const float srcBL = src[4]; 766 const float srcBR = src[5]; 767 dst[6] /* SR */ = (srcBR * 0.796000004f); 768 dst[5] /* SL */ = (srcBL * 0.796000004f); 769 dst[4] /* BC */ = (srcBR * 0.500000000f) + (srcBL * 0.500000000f); 770 dst[3] /* LFE */ = src[3]; 771 dst[2] /* FC */ = (src[2] * 0.939999998f); 772 dst[1] /* FR */ = (src[1] * 0.939999998f); 773 dst[0] /* FL */ = (src[0] * 0.939999998f); 774 } 775 776} 777 778static void SDL_Convert51To71(float *dst, const float *src, int num_frames) 779{ 780 int i; 781 782 LOG_DEBUG_AUDIO_CONVERT("5.1", "7.1"); 783 784 // convert backwards, since output is growing in-place. 785 src += (num_frames-1) * 6; 786 dst += (num_frames-1) * 8; 787 for (i = num_frames; i; i--, src -= 6, dst -= 8) { 788 dst[7] /* SR */ = 0.0f; 789 dst[6] /* SL */ = 0.0f; 790 dst[5] /* BR */ = src[5]; 791 dst[4] /* BL */ = src[4]; 792 dst[3] /* LFE */ = src[3]; 793 dst[2] /* FC */ = src[2]; 794 dst[1] /* FR */ = src[1]; 795 dst[0] /* FL */ = src[0]; 796 } 797 798} 799 800static void SDL_Convert61ToMono(float *dst, const float *src, int num_frames) 801{ 802 int i; 803 804 LOG_DEBUG_AUDIO_CONVERT("6.1", "mono"); 805 806 for (i = num_frames; i; i--, src += 7, dst++) { 807 dst[0] /* FC */ = (src[0] * 0.143142849f) + (src[1] * 0.143142849f) + (src[2] * 0.143142849f) + (src[3] * 0.142857149f) + (src[4] * 0.143142849f) + (src[5] * 0.143142849f) + (src[6] * 0.143142849f); 808 } 809 810} 811 812static void SDL_Convert61ToStereo(float *dst, const float *src, int num_frames) 813{ 814 int i; 815 816 LOG_DEBUG_AUDIO_CONVERT("6.1", "stereo"); 817 818 for (i = num_frames; i; i--, src += 7, dst += 2) { 819 const float srcFC = src[2]; 820 const float srcLFE = src[3]; 821 const float srcBC = src[4]; 822 const float srcSL = src[5]; 823 const float srcSR = src[6]; 824 dst[0] /* FL */ = (src[0] * 0.247384623f) + (srcFC * 0.174461529f) + (srcLFE * 0.076923080f) + (srcBC * 0.174461529f) + (srcSL * 0.226153851f) + (srcSR * 0.100615382f); 825 dst[1] /* FR */ = (src[1] * 0.247384623f) + (srcFC * 0.174461529f) + (srcLFE * 0.076923080f) + (srcBC * 0.174461529f) + (srcSL * 0.100615382f) + (srcSR * 0.226153851f); 826 } 827 828} 829 830static void SDL_Convert61To21(float *dst, const float *src, int num_frames) 831{ 832 int i; 833 834 LOG_DEBUG_AUDIO_CONVERT("6.1", "2.1"); 835 836 for (i = num_frames; i; i--, src += 7, dst += 3) { 837 const float srcFC = src[2]; 838 const float srcBC = src[4]; 839 const float srcSL = src[5]; 840 const float srcSR = src[6]; 841 dst[0] /* FL */ = (src[0] * 0.268000007f) + (srcFC * 0.188999996f) + (srcBC * 0.188999996f) + (srcSL * 0.245000005f) + (srcSR * 0.108999997f); 842 dst[1] /* FR */ = (src[1] * 0.268000007f) + (srcFC * 0.188999996f) + (srcBC * 0.188999996f) + (srcSL * 0.108999997f) + (srcSR * 0.245000005f); 843 dst[2] /* LFE */ = src[3]; 844 } 845 846} 847 848static void SDL_Convert61ToQuad(float *dst, const float *src, int num_frames) 849{ 850 int i; 851 852 LOG_DEBUG_AUDIO_CONVERT("6.1", "quad"); 853 854 for (i = num_frames; i; i--, src += 7, dst += 4) { 855 const float srcFC = src[2]; 856 const float srcLFE = src[3]; 857 const float srcBC = src[4]; 858 const float srcSL = src[5]; 859 const float srcSR = src[6]; 860 dst[0] /* FL */ = (src[0] * 0.463679999f) + (srcFC * 0.327360004f) + (srcLFE * 0.040000003f) + (srcSL * 0.168960005f); 861 dst[1] /* FR */ = (src[1] * 0.463679999f) + (srcFC * 0.327360004f) + (srcLFE * 0.040000003f) + (srcSR * 0.168960005f); 862 dst[2] /* BL */ = (srcLFE * 0.040000003f) + (srcBC * 0.327360004f) + (srcSL * 0.431039989f); 863 dst[3] /* BR */ = (srcLFE * 0.040000003f) + (srcBC * 0.327360004f) + (srcSR * 0.431039989f); 864 } 865 866} 867 868static void SDL_Convert61To41(float *dst, const float *src, int num_frames) 869{ 870 int i; 871 872 LOG_DEBUG_AUDIO_CONVERT("6.1", "4.1"); 873 874 for (i = num_frames; i; i--, src += 7, dst += 5) { 875 const float srcFC = src[2]; 876 const float srcBC = src[4]; 877 const float srcSL = src[5]; 878 const float srcSR = src[6]; 879 dst[0] /* FL */ = (src[0] * 0.483000010f) + (srcFC * 0.340999991f) + (srcSL * 0.175999999f); 880 dst[1] /* FR */ = (src[1] * 0.483000010f) + (srcFC * 0.340999991f) + (srcSR * 0.175999999f); 881 dst[2] /* LFE */ = src[3]; 882 dst[3] /* BL */ = (srcBC * 0.340999991f) + (srcSL * 0.449000001f); 883 dst[4] /* BR */ = (srcBC * 0.340999991f) + (srcSR * 0.449000001f); 884 } 885 886} 887 888static void SDL_Convert61To51(float *dst, const float *src, int num_frames) 889{ 890 int i; 891 892 LOG_DEBUG_AUDIO_CONVERT("6.1", "5.1"); 893 894 for (i = num_frames; i; i--, src += 7, dst += 6) { 895 const float srcBC = src[4]; 896 const float srcSL = src[5]; 897 const float srcSR = src[6]; 898 dst[0] /* FL */ = (src[0] * 0.611000001f) + (srcSL * 0.223000005f); 899 dst[1] /* FR */ = (src[1] * 0.611000001f) + (srcSR * 0.223000005f); 900 dst[2] /* FC */ = (src[2] * 0.611000001f); 901 dst[3] /* LFE */ = src[3]; 902 dst[4] /* BL */ = (srcBC * 0.432000011f) + (srcSL * 0.568000019f); 903 dst[5] /* BR */ = (srcBC * 0.432000011f) + (srcSR * 0.568000019f); 904 } 905 906} 907 908static void SDL_Convert61To71(float *dst, const float *src, int num_frames) 909{ 910 int i; 911 912 LOG_DEBUG_AUDIO_CONVERT("6.1", "7.1"); 913 914 // convert backwards, since output is growing in-place. 915 src += (num_frames-1) * 7; 916 dst += (num_frames-1) * 8; 917 for (i = num_frames; i; i--, src -= 7, dst -= 8) { 918 const float srcBC = src[4]; 919 dst[7] /* SR */ = src[6]; 920 dst[6] /* SL */ = src[5]; 921 dst[5] /* BR */ = (srcBC * 0.707000017f); 922 dst[4] /* BL */ = (srcBC * 0.707000017f); 923 dst[3] /* LFE */ = src[3]; 924 dst[2] /* FC */ = src[2]; 925 dst[1] /* FR */ = src[1]; 926 dst[0] /* FL */ = src[0]; 927 } 928 929} 930 931static void SDL_Convert71ToMono(float *dst, const float *src, int num_frames) 932{ 933 int i; 934 935 LOG_DEBUG_AUDIO_CONVERT("7.1", "mono"); 936 937 for (i = num_frames; i; i--, src += 8, dst++) { 938 dst[0] /* FC */ = (src[0] * 0.125125006f) + (src[1] * 0.125125006f) + (src[2] * 0.125125006f) + (src[3] * 0.125000000f) + (src[4] * 0.125125006f) + (src[5] * 0.125125006f) + (src[6] * 0.125125006f) + (src[7] * 0.125125006f); 939 } 940 941} 942 943static void SDL_Convert71ToStereo(float *dst, const float *src, int num_frames) 944{ 945 int i; 946 947 LOG_DEBUG_AUDIO_CONVERT("7.1", "stereo"); 948 949 for (i = num_frames; i; i--, src += 8, dst += 2) { 950 const float srcFC = src[2]; 951 const float srcLFE = src[3]; 952 const float srcBL = src[4]; 953 const float srcBR = src[5]; 954 const float srcSL = src[6]; 955 const float srcSR = src[7]; 956 dst[0] /* FL */ = (src[0] * 0.211866662f) + (srcFC * 0.150266662f) + (srcLFE * 0.066666670f) + (srcBL * 0.181066677f) + (srcBR * 0.111066669f) + (srcSL * 0.194133341f) + (srcSR * 0.085866667f); 957 dst[1] /* FR */ = (src[1] * 0.211866662f) + (srcFC * 0.150266662f) + (srcLFE * 0.066666670f) + (srcBL * 0.111066669f) + (srcBR * 0.181066677f) + (srcSL * 0.085866667f) + (srcSR * 0.194133341f); 958 } 959 960} 961 962static void SDL_Convert71To21(float *dst, const float *src, int num_frames) 963{ 964 int i; 965 966 LOG_DEBUG_AUDIO_CONVERT("7.1", "2.1"); 967 968 for (i = num_frames; i; i--, src += 8, dst += 3) { 969 const float srcFC = src[2]; 970 const float srcBL = src[4]; 971 const float srcBR = src[5]; 972 const float srcSL = src[6]; 973 const float srcSR = src[7]; 974 dst[0] /* FL */ = (src[0] * 0.226999998f) + (srcFC * 0.160999998f) + (srcBL * 0.194000006f) + (srcBR * 0.119000003f) + (srcSL * 0.208000004f) + (srcSR * 0.092000000f); 975 dst[1] /* FR */ = (src[1] * 0.226999998f) + (srcFC * 0.160999998f) + (srcBL * 0.119000003f) + (srcBR * 0.194000006f) + (srcSL * 0.092000000f) + (srcSR * 0.208000004f); 976 dst[2] /* LFE */ = src[3]; 977 } 978 979} 980 981static void SDL_Convert71ToQuad(float *dst, const float *src, int num_frames) 982{ 983 int i; 984 985 LOG_DEBUG_AUDIO_CONVERT("7.1", "quad"); 986 987 for (i = num_frames; i; i--, src += 8, dst += 4) { 988 const float srcFC = src[2]; 989 const float srcLFE = src[3]; 990 const float srcSL = src[6]; 991 const float srcSR = src[7]; 992 dst[0] /* FL */ = (src[0] * 0.466344833f) + (srcFC * 0.329241365f) + (srcLFE * 0.034482758f) + (srcSL * 0.169931039f); 993 dst[1] /* FR */ = (src[1] * 0.466344833f) + (srcFC * 0.329241365f) + (srcLFE * 0.034482758f) + (srcSR * 0.169931039f); 994 dst[2] /* BL */ = (srcLFE * 0.034482758f) + (src[4] * 0.466344833f) + (srcSL * 0.433517247f); 995 dst[3] /* BR */ = (srcLFE * 0.034482758f) + (src[5] * 0.466344833f) + (srcSR * 0.433517247f); 996 } 997 998} 999 1000static void SDL_Convert71To41(float *dst, const float *src, int num_frames) 1001{ 1002 int i; 1003 1004 LOG_DEBUG_AUDIO_CONVERT("7.1", "4.1"); 1005 1006 for (i = num_frames; i; i--, src += 8, dst += 5) { 1007 const float srcFC = src[2]; 1008 const float srcSL = src[6]; 1009 const float srcSR = src[7]; 1010 dst[0] /* FL */ = (src[0] * 0.483000010f) + (srcFC * 0.340999991f) + (srcSL * 0.175999999f); 1011 dst[1] /* FR */ = (src[1] * 0.483000010f) + (srcFC * 0.340999991f) + (srcSR * 0.175999999f); 1012 dst[2] /* LFE */ = src[3]; 1013 dst[3] /* BL */ = (src[4] * 0.483000010f) + (srcSL * 0.449000001f); 1014 dst[4] /* BR */ = (src[5] * 0.483000010f) + (srcSR * 0.449000001f); 1015 } 1016 1017} 1018 1019static void SDL_Convert71To51(float *dst, const float *src, int num_frames) 1020{ 1021 int i; 1022 1023 LOG_DEBUG_AUDIO_CONVERT("7.1", "5.1"); 1024 1025 for (i = num_frames; i; i--, src += 8, dst += 6) { 1026 const float srcSL = src[6]; 1027 const float srcSR = src[7]; 1028 dst[0] /* FL */ = (src[0] * 0.518000007f) + (srcSL * 0.188999996f); 1029 dst[1] /* FR */ = (src[1] * 0.518000007f) + (srcSR * 0.188999996f); 1030 dst[2] /* FC */ = (src[2] * 0.518000007f); 1031 dst[3] /* LFE */ = src[3]; 1032 dst[4] /* BL */ = (src[4] * 0.518000007f) + (srcSL * 0.481999993f); 1033 dst[5] /* BR */ = (src[5] * 0.518000007f) + (srcSR * 0.481999993f); 1034 } 1035 1036} 1037 1038static void SDL_Convert71To61(float *dst, const float *src, int num_frames) 1039{ 1040 int i; 1041 1042 LOG_DEBUG_AUDIO_CONVERT("7.1", "6.1"); 1043 1044 for (i = num_frames; i; i--, src += 8, dst += 7) { 1045 const float srcBL = src[4]; 1046 const float srcBR = src[5]; 1047 dst[0] /* FL */ = (src[0] * 0.541000009f); 1048 dst[1] /* FR */ = (src[1] * 0.541000009f); 1049 dst[2] /* FC */ = (src[2] * 0.541000009f); 1050 dst[3] /* LFE */ = src[3]; 1051 dst[4] /* BC */ = (srcBL * 0.287999988f) + (srcBR * 0.287999988f); 1052 dst[5] /* SL */ = (srcBL * 0.458999991f) + (src[6] * 0.541000009f); 1053 dst[6] /* SR */ = (srcBR * 0.458999991f) + (src[7] * 0.541000009f); 1054 } 1055 1056} 1057 1058static const SDL_AudioChannelConverter channel_converters[8][8] = { // [from][to] 1059 { NULL, SDL_ConvertMonoToStereo, SDL_ConvertMonoTo21, SDL_ConvertMonoToQuad, SDL_ConvertMonoTo41, SDL_ConvertMonoTo51, SDL_ConvertMonoTo61, SDL_ConvertMonoTo71 }, 1060 { SDL_ConvertStereoToMono, NULL, SDL_ConvertStereoTo21, SDL_ConvertStereoToQuad, SDL_ConvertStereoTo41, SDL_ConvertStereoTo51, SDL_ConvertStereoTo61, SDL_ConvertStereoTo71 }, 1061 { SDL_Convert21ToMono, SDL_Convert21ToStereo, NULL, SDL_Convert21ToQuad, SDL_Convert21To41, SDL_Convert21To51, SDL_Convert21To61, SDL_Convert21To71 }, 1062 { SDL_ConvertQuadToMono, SDL_ConvertQuadToStereo, SDL_ConvertQuadTo21, NULL, SDL_ConvertQuadTo41, SDL_ConvertQuadTo51, SDL_ConvertQuadTo61, SDL_ConvertQuadTo71 }, 1063 { SDL_Convert41ToMono, SDL_Convert41ToStereo, SDL_Convert41To21, SDL_Convert41ToQuad, NULL, SDL_Convert41To51, SDL_Convert41To61, SDL_Convert41To71 }, 1064 { SDL_Convert51ToMono, SDL_Convert51ToStereo, SDL_Convert51To21, SDL_Convert51ToQuad, SDL_Convert51To41, NULL, SDL_Convert51To61, SDL_Convert51To71 }, 1065 { SDL_Convert61ToMono, SDL_Convert61ToStereo, SDL_Convert61To21, SDL_Convert61ToQuad, SDL_Convert61To41, SDL_Convert61To51, NULL, SDL_Convert61To71 }, 1066 { SDL_Convert71ToMono, SDL_Convert71ToStereo, SDL_Convert71To21, SDL_Convert71ToQuad, SDL_Convert71To41, SDL_Convert71To51, SDL_Convert71To61, NULL } 1067}; 1068 1069
[FILE END]
(C) 2025 0x4248 (C) 2025 4248 Media and 4248 Systems, All part of 0x4248 See LICENCE files for more information. Not all files are by 0x4248 always check Licencing.