| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 state1_ = malloc(sizeof(WebRtcSpl_State22khzTo16khz)); | 394 state1_ = malloc(sizeof(WebRtcSpl_State22khzTo16khz)); |
| 395 WebRtcSpl_ResetResample22khzTo16khz((WebRtcSpl_State22khzTo16khz *)s
tate1_); | 395 WebRtcSpl_ResetResample22khzTo16khz((WebRtcSpl_State22khzTo16khz *)s
tate1_); |
| 396 break; | 396 break; |
| 397 | 397 |
| 398 } | 398 } |
| 399 | 399 |
| 400 return 0; | 400 return 0; |
| 401 } | 401 } |
| 402 | 402 |
| 403 // Synchronous resampling, all output samples are written to samplesOut | 403 // Synchronous resampling, all output samples are written to samplesOut |
| 404 int Resampler::Push(const int16_t * samplesIn, int lengthIn, | 404 int Resampler::Push(const int16_t * samplesIn, size_t lengthIn, |
| 405 int16_t* samplesOut, int maxLen, int &outLen) | 405 int16_t* samplesOut, size_t maxLen, size_t &outLen) |
| 406 { | 406 { |
| 407 if (num_channels_ == 2) | 407 if (num_channels_ == 2) |
| 408 { | 408 { |
| 409 // Split up the signal and call the slave object for each channel | 409 // Split up the signal and call the slave object for each channel |
| 410 int16_t* left = (int16_t*)malloc(lengthIn * sizeof(int16_t) / 2); | 410 int16_t* left = (int16_t*)malloc(lengthIn * sizeof(int16_t) / 2); |
| 411 int16_t* right = (int16_t*)malloc(lengthIn * sizeof(int16_t) / 2); | 411 int16_t* right = (int16_t*)malloc(lengthIn * sizeof(int16_t) / 2); |
| 412 int16_t* out_left = (int16_t*)malloc(maxLen / 2 * sizeof(int16_t)); | 412 int16_t* out_left = (int16_t*)malloc(maxLen / 2 * sizeof(int16_t)); |
| 413 int16_t* out_right = | 413 int16_t* out_right = |
| 414 (int16_t*)malloc(maxLen / 2 * sizeof(int16_t)); | 414 (int16_t*)malloc(maxLen / 2 * sizeof(int16_t)); |
| 415 int res = 0; | 415 int res = 0; |
| 416 for (int i = 0; i < lengthIn; i += 2) | 416 for (size_t i = 0; i < lengthIn; i += 2) |
| 417 { | 417 { |
| 418 left[i >> 1] = samplesIn[i]; | 418 left[i >> 1] = samplesIn[i]; |
| 419 right[i >> 1] = samplesIn[i + 1]; | 419 right[i >> 1] = samplesIn[i + 1]; |
| 420 } | 420 } |
| 421 | 421 |
| 422 // It's OK to overwrite the local parameter, since it's just a copy | 422 // It's OK to overwrite the local parameter, since it's just a copy |
| 423 lengthIn = lengthIn / 2; | 423 lengthIn = lengthIn / 2; |
| 424 | 424 |
| 425 int actualOutLen_left = 0; | 425 size_t actualOutLen_left = 0; |
| 426 int actualOutLen_right = 0; | 426 size_t actualOutLen_right = 0; |
| 427 // Do resampling for right channel | 427 // Do resampling for right channel |
| 428 res |= slave_left_->Push(left, lengthIn, out_left, maxLen / 2, actualOut
Len_left); | 428 res |= slave_left_->Push(left, lengthIn, out_left, maxLen / 2, actualOut
Len_left); |
| 429 res |= slave_right_->Push(right, lengthIn, out_right, maxLen / 2, actual
OutLen_right); | 429 res |= slave_right_->Push(right, lengthIn, out_right, maxLen / 2, actual
OutLen_right); |
| 430 if (res || (actualOutLen_left != actualOutLen_right)) | 430 if (res || (actualOutLen_left != actualOutLen_right)) |
| 431 { | 431 { |
| 432 free(left); | 432 free(left); |
| 433 free(right); | 433 free(right); |
| 434 free(out_left); | 434 free(out_left); |
| 435 free(out_right); | 435 free(out_right); |
| 436 return -1; | 436 return -1; |
| 437 } | 437 } |
| 438 | 438 |
| 439 // Reassemble the signal | 439 // Reassemble the signal |
| 440 for (int i = 0; i < actualOutLen_left; i++) | 440 for (size_t i = 0; i < actualOutLen_left; i++) |
| 441 { | 441 { |
| 442 samplesOut[i * 2] = out_left[i]; | 442 samplesOut[i * 2] = out_left[i]; |
| 443 samplesOut[i * 2 + 1] = out_right[i]; | 443 samplesOut[i * 2 + 1] = out_right[i]; |
| 444 } | 444 } |
| 445 outLen = 2 * actualOutLen_left; | 445 outLen = 2 * actualOutLen_left; |
| 446 | 446 |
| 447 free(left); | 447 free(left); |
| 448 free(right); | 448 free(right); |
| 449 free(out_left); | 449 free(out_left); |
| 450 free(out_right); | 450 free(out_right); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 479 if ((lengthIn % 160) != 0) | 479 if ((lengthIn % 160) != 0) |
| 480 { | 480 { |
| 481 return -1; | 481 return -1; |
| 482 } | 482 } |
| 483 if (maxLen < (lengthIn * 3)) | 483 if (maxLen < (lengthIn * 3)) |
| 484 { | 484 { |
| 485 return -1; | 485 return -1; |
| 486 } | 486 } |
| 487 tmp_mem = (int32_t*)malloc(336 * sizeof(int32_t)); | 487 tmp_mem = (int32_t*)malloc(336 * sizeof(int32_t)); |
| 488 | 488 |
| 489 for (int i = 0; i < lengthIn; i += 160) | 489 for (size_t i = 0; i < lengthIn; i += 160) |
| 490 { | 490 { |
| 491 WebRtcSpl_Resample16khzTo48khz(samplesIn + i, samplesOut + i * 3
, | 491 WebRtcSpl_Resample16khzTo48khz(samplesIn + i, samplesOut + i * 3
, |
| 492 (WebRtcSpl_State16khzTo48khz *)st
ate1_, | 492 (WebRtcSpl_State16khzTo48khz *)st
ate1_, |
| 493 tmp_mem); | 493 tmp_mem); |
| 494 } | 494 } |
| 495 outLen = lengthIn * 3; | 495 outLen = lengthIn * 3; |
| 496 free(tmp_mem); | 496 free(tmp_mem); |
| 497 return 0; | 497 return 0; |
| 498 case kResamplerMode1To4: | 498 case kResamplerMode1To4: |
| 499 if (maxLen < (lengthIn * 4)) | 499 if (maxLen < (lengthIn * 4)) |
| (...skipping 22 matching lines...) Expand all Loading... |
| 522 } | 522 } |
| 523 | 523 |
| 524 //1:2 | 524 //1:2 |
| 525 | 525 |
| 526 tmp_mem = (int32_t*)malloc(336 * sizeof(int32_t)); | 526 tmp_mem = (int32_t*)malloc(336 * sizeof(int32_t)); |
| 527 tmp = (int16_t*)malloc(sizeof(int16_t) * 2 * lengthIn); | 527 tmp = (int16_t*)malloc(sizeof(int16_t) * 2 * lengthIn); |
| 528 | 528 |
| 529 WebRtcSpl_UpsampleBy2(samplesIn, lengthIn, tmp, (int32_t*)state1_); | 529 WebRtcSpl_UpsampleBy2(samplesIn, lengthIn, tmp, (int32_t*)state1_); |
| 530 outLen = lengthIn * 2; | 530 outLen = lengthIn * 2; |
| 531 | 531 |
| 532 for (int i = 0; i < outLen; i += 160) | 532 for (size_t i = 0; i < outLen; i += 160) |
| 533 { | 533 { |
| 534 WebRtcSpl_Resample16khzTo48khz(tmp + i, samplesOut + i * 3, | 534 WebRtcSpl_Resample16khzTo48khz(tmp + i, samplesOut + i * 3, |
| 535 (WebRtcSpl_State16khzTo48khz *)st
ate2_, | 535 (WebRtcSpl_State16khzTo48khz *)st
ate2_, |
| 536 tmp_mem); | 536 tmp_mem); |
| 537 } | 537 } |
| 538 outLen = outLen * 3; | 538 outLen = outLen * 3; |
| 539 free(tmp_mem); | 539 free(tmp_mem); |
| 540 free(tmp); | 540 free(tmp); |
| 541 | 541 |
| 542 return 0; | 542 return 0; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 553 tmp_mem = (int32_t*) malloc(336 * sizeof(int32_t)); | 553 tmp_mem = (int32_t*) malloc(336 * sizeof(int32_t)); |
| 554 tmp = (int16_t*) malloc(sizeof(int16_t) * 4 * lengthIn); | 554 tmp = (int16_t*) malloc(sizeof(int16_t) * 4 * lengthIn); |
| 555 //1:2 | 555 //1:2 |
| 556 WebRtcSpl_UpsampleBy2(samplesIn, lengthIn, samplesOut, | 556 WebRtcSpl_UpsampleBy2(samplesIn, lengthIn, samplesOut, |
| 557 (int32_t*) state1_); | 557 (int32_t*) state1_); |
| 558 outLen = lengthIn * 2; | 558 outLen = lengthIn * 2; |
| 559 //2:4 | 559 //2:4 |
| 560 WebRtcSpl_UpsampleBy2(samplesOut, outLen, tmp, (int32_t*) state2_); | 560 WebRtcSpl_UpsampleBy2(samplesOut, outLen, tmp, (int32_t*) state2_); |
| 561 outLen = outLen * 2; | 561 outLen = outLen * 2; |
| 562 // 4:12 | 562 // 4:12 |
| 563 for (int i = 0; i < outLen; i += 160) { | 563 for (size_t i = 0; i < outLen; i += 160) { |
| 564 // WebRtcSpl_Resample16khzTo48khz() takes a block of 160 samples | 564 // WebRtcSpl_Resample16khzTo48khz() takes a block of 160 samples |
| 565 // as input and outputs a resampled block of 480 samples. The | 565 // as input and outputs a resampled block of 480 samples. The |
| 566 // data is now actually in 32 kHz sampling rate, despite the | 566 // data is now actually in 32 kHz sampling rate, despite the |
| 567 // function name, and with a resampling factor of three becomes | 567 // function name, and with a resampling factor of three becomes |
| 568 // 96 kHz. | 568 // 96 kHz. |
| 569 WebRtcSpl_Resample16khzTo48khz(tmp + i, samplesOut + i * 3, | 569 WebRtcSpl_Resample16khzTo48khz(tmp + i, samplesOut + i * 3, |
| 570 (WebRtcSpl_State16khzTo48khz*) stat
e3_, | 570 (WebRtcSpl_State16khzTo48khz*) stat
e3_, |
| 571 tmp_mem); | 571 tmp_mem); |
| 572 } | 572 } |
| 573 outLen = outLen * 3; | 573 outLen = outLen * 3; |
| 574 free(tmp_mem); | 574 free(tmp_mem); |
| 575 free(tmp); | 575 free(tmp); |
| 576 | 576 |
| 577 return 0; | 577 return 0; |
| 578 case kResamplerMode2To3: | 578 case kResamplerMode2To3: |
| 579 if (maxLen < (lengthIn * 3 / 2)) | 579 if (maxLen < (lengthIn * 3 / 2)) |
| 580 { | 580 { |
| 581 return -1; | 581 return -1; |
| 582 } | 582 } |
| 583 // 2:6 | 583 // 2:6 |
| 584 // We can only handle blocks of 160 samples | 584 // We can only handle blocks of 160 samples |
| 585 // Can be fixed, but I don't think it's needed | 585 // Can be fixed, but I don't think it's needed |
| 586 if ((lengthIn % 160) != 0) | 586 if ((lengthIn % 160) != 0) |
| 587 { | 587 { |
| 588 return -1; | 588 return -1; |
| 589 } | 589 } |
| 590 tmp = static_cast<int16_t*> (malloc(sizeof(int16_t) * lengthIn * 3))
; | 590 tmp = static_cast<int16_t*> (malloc(sizeof(int16_t) * lengthIn * 3))
; |
| 591 tmp_mem = (int32_t*)malloc(336 * sizeof(int32_t)); | 591 tmp_mem = (int32_t*)malloc(336 * sizeof(int32_t)); |
| 592 for (int i = 0; i < lengthIn; i += 160) | 592 for (size_t i = 0; i < lengthIn; i += 160) |
| 593 { | 593 { |
| 594 WebRtcSpl_Resample16khzTo48khz(samplesIn + i, tmp + i * 3, | 594 WebRtcSpl_Resample16khzTo48khz(samplesIn + i, tmp + i * 3, |
| 595 (WebRtcSpl_State16khzTo48khz *)st
ate1_, | 595 (WebRtcSpl_State16khzTo48khz *)st
ate1_, |
| 596 tmp_mem); | 596 tmp_mem); |
| 597 } | 597 } |
| 598 lengthIn = lengthIn * 3; | 598 lengthIn = lengthIn * 3; |
| 599 // 6:3 | 599 // 6:3 |
| 600 WebRtcSpl_DownsampleBy2(tmp, lengthIn, samplesOut, (int32_t*)state2_
); | 600 WebRtcSpl_DownsampleBy2(tmp, lengthIn, samplesOut, (int32_t*)state2_
); |
| 601 outLen = lengthIn / 2; | 601 outLen = lengthIn / 2; |
| 602 free(tmp); | 602 free(tmp); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 614 { | 614 { |
| 615 return -1; | 615 return -1; |
| 616 } | 616 } |
| 617 tmp = (int16_t*)malloc(sizeof(int16_t) * 2 * lengthIn); | 617 tmp = (int16_t*)malloc(sizeof(int16_t) * 2 * lengthIn); |
| 618 // 1:2 | 618 // 1:2 |
| 619 WebRtcSpl_UpsampleBy2(samplesIn, lengthIn, tmp, (int32_t*)state1_); | 619 WebRtcSpl_UpsampleBy2(samplesIn, lengthIn, tmp, (int32_t*)state1_); |
| 620 lengthIn *= 2; | 620 lengthIn *= 2; |
| 621 | 621 |
| 622 tmp_mem = (int32_t*)malloc(98 * sizeof(int32_t)); | 622 tmp_mem = (int32_t*)malloc(98 * sizeof(int32_t)); |
| 623 | 623 |
| 624 for (int i = 0; i < lengthIn; i += 80) | 624 for (size_t i = 0; i < lengthIn; i += 80) |
| 625 { | 625 { |
| 626 WebRtcSpl_Resample8khzTo22khz(tmp + i, samplesOut + (i * 11) / 4
, | 626 WebRtcSpl_Resample8khzTo22khz(tmp + i, samplesOut + (i * 11) / 4
, |
| 627 (WebRtcSpl_State8khzTo22khz *)stat
e2_, | 627 (WebRtcSpl_State8khzTo22khz *)stat
e2_, |
| 628 tmp_mem); | 628 tmp_mem); |
| 629 } | 629 } |
| 630 outLen = (lengthIn * 11) / 4; | 630 outLen = (lengthIn * 11) / 4; |
| 631 free(tmp_mem); | 631 free(tmp_mem); |
| 632 free(tmp); | 632 free(tmp); |
| 633 return 0; | 633 return 0; |
| 634 case kResamplerMode4To11: | 634 case kResamplerMode4To11: |
| 635 | 635 |
| 636 // We can only handle blocks of 80 samples | 636 // We can only handle blocks of 80 samples |
| 637 // Can be fixed, but I don't think it's needed | 637 // Can be fixed, but I don't think it's needed |
| 638 if ((lengthIn % 80) != 0) | 638 if ((lengthIn % 80) != 0) |
| 639 { | 639 { |
| 640 return -1; | 640 return -1; |
| 641 } | 641 } |
| 642 if (maxLen < ((lengthIn * 11) / 4)) | 642 if (maxLen < ((lengthIn * 11) / 4)) |
| 643 { | 643 { |
| 644 return -1; | 644 return -1; |
| 645 } | 645 } |
| 646 tmp_mem = (int32_t*)malloc(98 * sizeof(int32_t)); | 646 tmp_mem = (int32_t*)malloc(98 * sizeof(int32_t)); |
| 647 | 647 |
| 648 for (int i = 0; i < lengthIn; i += 80) | 648 for (size_t i = 0; i < lengthIn; i += 80) |
| 649 { | 649 { |
| 650 WebRtcSpl_Resample8khzTo22khz(samplesIn + i, samplesOut + (i * 1
1) / 4, | 650 WebRtcSpl_Resample8khzTo22khz(samplesIn + i, samplesOut + (i * 1
1) / 4, |
| 651 (WebRtcSpl_State8khzTo22khz *)stat
e1_, | 651 (WebRtcSpl_State8khzTo22khz *)stat
e1_, |
| 652 tmp_mem); | 652 tmp_mem); |
| 653 } | 653 } |
| 654 outLen = (lengthIn * 11) / 4; | 654 outLen = (lengthIn * 11) / 4; |
| 655 free(tmp_mem); | 655 free(tmp_mem); |
| 656 return 0; | 656 return 0; |
| 657 case kResamplerMode8To11: | 657 case kResamplerMode8To11: |
| 658 // We can only handle blocks of 160 samples | 658 // We can only handle blocks of 160 samples |
| 659 // Can be fixed, but I don't think it's needed | 659 // Can be fixed, but I don't think it's needed |
| 660 if ((lengthIn % 160) != 0) | 660 if ((lengthIn % 160) != 0) |
| 661 { | 661 { |
| 662 return -1; | 662 return -1; |
| 663 } | 663 } |
| 664 if (maxLen < ((lengthIn * 11) / 8)) | 664 if (maxLen < ((lengthIn * 11) / 8)) |
| 665 { | 665 { |
| 666 return -1; | 666 return -1; |
| 667 } | 667 } |
| 668 tmp_mem = (int32_t*)malloc(88 * sizeof(int32_t)); | 668 tmp_mem = (int32_t*)malloc(88 * sizeof(int32_t)); |
| 669 | 669 |
| 670 for (int i = 0; i < lengthIn; i += 160) | 670 for (size_t i = 0; i < lengthIn; i += 160) |
| 671 { | 671 { |
| 672 WebRtcSpl_Resample16khzTo22khz(samplesIn + i, samplesOut + (i *
11) / 8, | 672 WebRtcSpl_Resample16khzTo22khz(samplesIn + i, samplesOut + (i *
11) / 8, |
| 673 (WebRtcSpl_State16khzTo22khz *)st
ate1_, | 673 (WebRtcSpl_State16khzTo22khz *)st
ate1_, |
| 674 tmp_mem); | 674 tmp_mem); |
| 675 } | 675 } |
| 676 outLen = (lengthIn * 11) / 8; | 676 outLen = (lengthIn * 11) / 8; |
| 677 free(tmp_mem); | 677 free(tmp_mem); |
| 678 return 0; | 678 return 0; |
| 679 | 679 |
| 680 case kResamplerMode11To16: | 680 case kResamplerMode11To16: |
| 681 // We can only handle blocks of 110 samples | 681 // We can only handle blocks of 110 samples |
| 682 if ((lengthIn % 110) != 0) | 682 if ((lengthIn % 110) != 0) |
| 683 { | 683 { |
| 684 return -1; | 684 return -1; |
| 685 } | 685 } |
| 686 if (maxLen < ((lengthIn * 16) / 11)) | 686 if (maxLen < ((lengthIn * 16) / 11)) |
| 687 { | 687 { |
| 688 return -1; | 688 return -1; |
| 689 } | 689 } |
| 690 | 690 |
| 691 tmp_mem = (int32_t*)malloc(104 * sizeof(int32_t)); | 691 tmp_mem = (int32_t*)malloc(104 * sizeof(int32_t)); |
| 692 tmp = (int16_t*)malloc((sizeof(int16_t) * lengthIn * 2)); | 692 tmp = (int16_t*)malloc((sizeof(int16_t) * lengthIn * 2)); |
| 693 | 693 |
| 694 WebRtcSpl_UpsampleBy2(samplesIn, lengthIn, tmp, (int32_t*)state1_); | 694 WebRtcSpl_UpsampleBy2(samplesIn, lengthIn, tmp, (int32_t*)state1_); |
| 695 | 695 |
| 696 for (int i = 0; i < (lengthIn * 2); i += 220) | 696 for (size_t i = 0; i < (lengthIn * 2); i += 220) |
| 697 { | 697 { |
| 698 WebRtcSpl_Resample22khzTo16khz(tmp + i, samplesOut + (i / 220) *
160, | 698 WebRtcSpl_Resample22khzTo16khz(tmp + i, samplesOut + (i / 220) *
160, |
| 699 (WebRtcSpl_State22khzTo16khz *)st
ate2_, | 699 (WebRtcSpl_State22khzTo16khz *)st
ate2_, |
| 700 tmp_mem); | 700 tmp_mem); |
| 701 } | 701 } |
| 702 | 702 |
| 703 outLen = (lengthIn * 16) / 11; | 703 outLen = (lengthIn * 16) / 11; |
| 704 | 704 |
| 705 free(tmp_mem); | 705 free(tmp_mem); |
| 706 free(tmp); | 706 free(tmp); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 718 return -1; | 718 return -1; |
| 719 } | 719 } |
| 720 | 720 |
| 721 tmp_mem = (int32_t*)malloc(104 * sizeof(int32_t)); | 721 tmp_mem = (int32_t*)malloc(104 * sizeof(int32_t)); |
| 722 tmp = (int16_t*)malloc((sizeof(int16_t) * lengthIn * 2)); | 722 tmp = (int16_t*)malloc((sizeof(int16_t) * lengthIn * 2)); |
| 723 | 723 |
| 724 // 11 -> 22 kHz in samplesOut | 724 // 11 -> 22 kHz in samplesOut |
| 725 WebRtcSpl_UpsampleBy2(samplesIn, lengthIn, samplesOut, (int32_t*)sta
te1_); | 725 WebRtcSpl_UpsampleBy2(samplesIn, lengthIn, samplesOut, (int32_t*)sta
te1_); |
| 726 | 726 |
| 727 // 22 -> 16 in tmp | 727 // 22 -> 16 in tmp |
| 728 for (int i = 0; i < (lengthIn * 2); i += 220) | 728 for (size_t i = 0; i < (lengthIn * 2); i += 220) |
| 729 { | 729 { |
| 730 WebRtcSpl_Resample22khzTo16khz(samplesOut + i, tmp + (i / 220) *
160, | 730 WebRtcSpl_Resample22khzTo16khz(samplesOut + i, tmp + (i / 220) *
160, |
| 731 (WebRtcSpl_State22khzTo16khz *)st
ate2_, | 731 (WebRtcSpl_State22khzTo16khz *)st
ate2_, |
| 732 tmp_mem); | 732 tmp_mem); |
| 733 } | 733 } |
| 734 | 734 |
| 735 // 16 -> 32 in samplesOut | 735 // 16 -> 32 in samplesOut |
| 736 WebRtcSpl_UpsampleBy2(tmp, (lengthIn * 16) / 11, samplesOut, | 736 WebRtcSpl_UpsampleBy2(tmp, (lengthIn * 16) / 11, samplesOut, |
| 737 (int32_t*)state3_); | 737 (int32_t*)state3_); |
| 738 | 738 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 756 if ((lengthIn % 480) != 0) | 756 if ((lengthIn % 480) != 0) |
| 757 { | 757 { |
| 758 return -1; | 758 return -1; |
| 759 } | 759 } |
| 760 if (maxLen < (lengthIn / 3)) | 760 if (maxLen < (lengthIn / 3)) |
| 761 { | 761 { |
| 762 return -1; | 762 return -1; |
| 763 } | 763 } |
| 764 tmp_mem = (int32_t*)malloc(496 * sizeof(int32_t)); | 764 tmp_mem = (int32_t*)malloc(496 * sizeof(int32_t)); |
| 765 | 765 |
| 766 for (int i = 0; i < lengthIn; i += 480) | 766 for (size_t i = 0; i < lengthIn; i += 480) |
| 767 { | 767 { |
| 768 WebRtcSpl_Resample48khzTo16khz(samplesIn + i, samplesOut + i / 3
, | 768 WebRtcSpl_Resample48khzTo16khz(samplesIn + i, samplesOut + i / 3
, |
| 769 (WebRtcSpl_State48khzTo16khz *)st
ate1_, | 769 (WebRtcSpl_State48khzTo16khz *)st
ate1_, |
| 770 tmp_mem); | 770 tmp_mem); |
| 771 } | 771 } |
| 772 outLen = lengthIn / 3; | 772 outLen = lengthIn / 3; |
| 773 free(tmp_mem); | 773 free(tmp_mem); |
| 774 return 0; | 774 return 0; |
| 775 case kResamplerMode4To1: | 775 case kResamplerMode4To1: |
| 776 if (maxLen < (lengthIn / 4)) | 776 if (maxLen < (lengthIn / 4)) |
| (...skipping 17 matching lines...) Expand all Loading... |
| 794 return -1; | 794 return -1; |
| 795 } | 795 } |
| 796 if (maxLen < (lengthIn / 6)) | 796 if (maxLen < (lengthIn / 6)) |
| 797 { | 797 { |
| 798 return -1; | 798 return -1; |
| 799 } | 799 } |
| 800 | 800 |
| 801 tmp_mem = (int32_t*)malloc(496 * sizeof(int32_t)); | 801 tmp_mem = (int32_t*)malloc(496 * sizeof(int32_t)); |
| 802 tmp = (int16_t*)malloc((sizeof(int16_t) * lengthIn) / 3); | 802 tmp = (int16_t*)malloc((sizeof(int16_t) * lengthIn) / 3); |
| 803 | 803 |
| 804 for (int i = 0; i < lengthIn; i += 480) | 804 for (size_t i = 0; i < lengthIn; i += 480) |
| 805 { | 805 { |
| 806 WebRtcSpl_Resample48khzTo16khz(samplesIn + i, tmp + i / 3, | 806 WebRtcSpl_Resample48khzTo16khz(samplesIn + i, tmp + i / 3, |
| 807 (WebRtcSpl_State48khzTo16khz *)st
ate1_, | 807 (WebRtcSpl_State48khzTo16khz *)st
ate1_, |
| 808 tmp_mem); | 808 tmp_mem); |
| 809 } | 809 } |
| 810 outLen = lengthIn / 3; | 810 outLen = lengthIn / 3; |
| 811 free(tmp_mem); | 811 free(tmp_mem); |
| 812 WebRtcSpl_DownsampleBy2(tmp, outLen, samplesOut, (int32_t*)state2_); | 812 WebRtcSpl_DownsampleBy2(tmp, outLen, samplesOut, (int32_t*)state2_); |
| 813 free(tmp); | 813 free(tmp); |
| 814 outLen = outLen / 2; | 814 outLen = outLen / 2; |
| 815 return 0; | 815 return 0; |
| 816 case kResamplerMode12To1: | 816 case kResamplerMode12To1: |
| 817 // We can only handle blocks of 480 samples | 817 // We can only handle blocks of 480 samples |
| 818 // Can be fixed, but I don't think it's needed | 818 // Can be fixed, but I don't think it's needed |
| 819 if ((lengthIn % 480) != 0) { | 819 if ((lengthIn % 480) != 0) { |
| 820 return -1; | 820 return -1; |
| 821 } | 821 } |
| 822 if (maxLen < (lengthIn / 12)) { | 822 if (maxLen < (lengthIn / 12)) { |
| 823 return -1; | 823 return -1; |
| 824 } | 824 } |
| 825 | 825 |
| 826 tmp_mem = (int32_t*) malloc(496 * sizeof(int32_t)); | 826 tmp_mem = (int32_t*) malloc(496 * sizeof(int32_t)); |
| 827 tmp = (int16_t*) malloc((sizeof(int16_t) * lengthIn) / 3); | 827 tmp = (int16_t*) malloc((sizeof(int16_t) * lengthIn) / 3); |
| 828 tmp_2 = (int16_t*) malloc((sizeof(int16_t) * lengthIn) / 6); | 828 tmp_2 = (int16_t*) malloc((sizeof(int16_t) * lengthIn) / 6); |
| 829 // 12:4 | 829 // 12:4 |
| 830 for (int i = 0; i < lengthIn; i += 480) { | 830 for (size_t i = 0; i < lengthIn; i += 480) { |
| 831 // WebRtcSpl_Resample48khzTo16khz() takes a block of 480 samples | 831 // WebRtcSpl_Resample48khzTo16khz() takes a block of 480 samples |
| 832 // as input and outputs a resampled block of 160 samples. The | 832 // as input and outputs a resampled block of 160 samples. The |
| 833 // data is now actually in 96 kHz sampling rate, despite the | 833 // data is now actually in 96 kHz sampling rate, despite the |
| 834 // function name, and with a resampling factor of 1/3 becomes | 834 // function name, and with a resampling factor of 1/3 becomes |
| 835 // 32 kHz. | 835 // 32 kHz. |
| 836 WebRtcSpl_Resample48khzTo16khz(samplesIn + i, tmp + i / 3, | 836 WebRtcSpl_Resample48khzTo16khz(samplesIn + i, tmp + i / 3, |
| 837 (WebRtcSpl_State48khzTo16khz*) stat
e1_, | 837 (WebRtcSpl_State48khzTo16khz*) stat
e1_, |
| 838 tmp_mem); | 838 tmp_mem); |
| 839 } | 839 } |
| 840 outLen = lengthIn / 3; | 840 outLen = lengthIn / 3; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 860 lengthIn *= 2; | 860 lengthIn *= 2; |
| 861 // 6:2 | 861 // 6:2 |
| 862 // We can only handle blocks of 480 samples | 862 // We can only handle blocks of 480 samples |
| 863 // Can be fixed, but I don't think it's needed | 863 // Can be fixed, but I don't think it's needed |
| 864 if ((lengthIn % 480) != 0) | 864 if ((lengthIn % 480) != 0) |
| 865 { | 865 { |
| 866 free(tmp); | 866 free(tmp); |
| 867 return -1; | 867 return -1; |
| 868 } | 868 } |
| 869 tmp_mem = (int32_t*)malloc(496 * sizeof(int32_t)); | 869 tmp_mem = (int32_t*)malloc(496 * sizeof(int32_t)); |
| 870 for (int i = 0; i < lengthIn; i += 480) | 870 for (size_t i = 0; i < lengthIn; i += 480) |
| 871 { | 871 { |
| 872 WebRtcSpl_Resample48khzTo16khz(tmp + i, samplesOut + i / 3, | 872 WebRtcSpl_Resample48khzTo16khz(tmp + i, samplesOut + i / 3, |
| 873 (WebRtcSpl_State48khzTo16khz *)st
ate2_, | 873 (WebRtcSpl_State48khzTo16khz *)st
ate2_, |
| 874 tmp_mem); | 874 tmp_mem); |
| 875 } | 875 } |
| 876 outLen = lengthIn / 3; | 876 outLen = lengthIn / 3; |
| 877 free(tmp); | 877 free(tmp); |
| 878 free(tmp_mem); | 878 free(tmp_mem); |
| 879 return 0; | 879 return 0; |
| 880 case kResamplerMode11To2: | 880 case kResamplerMode11To2: |
| 881 // We can only handle blocks of 220 samples | 881 // We can only handle blocks of 220 samples |
| 882 // Can be fixed, but I don't think it's needed | 882 // Can be fixed, but I don't think it's needed |
| 883 if ((lengthIn % 220) != 0) | 883 if ((lengthIn % 220) != 0) |
| 884 { | 884 { |
| 885 return -1; | 885 return -1; |
| 886 } | 886 } |
| 887 if (maxLen < ((lengthIn * 2) / 11)) | 887 if (maxLen < ((lengthIn * 2) / 11)) |
| 888 { | 888 { |
| 889 return -1; | 889 return -1; |
| 890 } | 890 } |
| 891 tmp_mem = (int32_t*)malloc(126 * sizeof(int32_t)); | 891 tmp_mem = (int32_t*)malloc(126 * sizeof(int32_t)); |
| 892 tmp = (int16_t*)malloc((lengthIn * 4) / 11 * sizeof(int16_t)); | 892 tmp = (int16_t*)malloc((lengthIn * 4) / 11 * sizeof(int16_t)); |
| 893 | 893 |
| 894 for (int i = 0; i < lengthIn; i += 220) | 894 for (size_t i = 0; i < lengthIn; i += 220) |
| 895 { | 895 { |
| 896 WebRtcSpl_Resample22khzTo8khz(samplesIn + i, tmp + (i * 4) / 11, | 896 WebRtcSpl_Resample22khzTo8khz(samplesIn + i, tmp + (i * 4) / 11, |
| 897 (WebRtcSpl_State22khzTo8khz *)stat
e1_, | 897 (WebRtcSpl_State22khzTo8khz *)stat
e1_, |
| 898 tmp_mem); | 898 tmp_mem); |
| 899 } | 899 } |
| 900 lengthIn = (lengthIn * 4) / 11; | 900 lengthIn = (lengthIn * 4) / 11; |
| 901 | 901 |
| 902 WebRtcSpl_DownsampleBy2(tmp, lengthIn, samplesOut, | 902 WebRtcSpl_DownsampleBy2(tmp, lengthIn, samplesOut, |
| 903 (int32_t*)state2_); | 903 (int32_t*)state2_); |
| 904 outLen = lengthIn / 2; | 904 outLen = lengthIn / 2; |
| 905 | 905 |
| 906 free(tmp_mem); | 906 free(tmp_mem); |
| 907 free(tmp); | 907 free(tmp); |
| 908 return 0; | 908 return 0; |
| 909 case kResamplerMode11To4: | 909 case kResamplerMode11To4: |
| 910 // We can only handle blocks of 220 samples | 910 // We can only handle blocks of 220 samples |
| 911 // Can be fixed, but I don't think it's needed | 911 // Can be fixed, but I don't think it's needed |
| 912 if ((lengthIn % 220) != 0) | 912 if ((lengthIn % 220) != 0) |
| 913 { | 913 { |
| 914 return -1; | 914 return -1; |
| 915 } | 915 } |
| 916 if (maxLen < ((lengthIn * 4) / 11)) | 916 if (maxLen < ((lengthIn * 4) / 11)) |
| 917 { | 917 { |
| 918 return -1; | 918 return -1; |
| 919 } | 919 } |
| 920 tmp_mem = (int32_t*)malloc(126 * sizeof(int32_t)); | 920 tmp_mem = (int32_t*)malloc(126 * sizeof(int32_t)); |
| 921 | 921 |
| 922 for (int i = 0; i < lengthIn; i += 220) | 922 for (size_t i = 0; i < lengthIn; i += 220) |
| 923 { | 923 { |
| 924 WebRtcSpl_Resample22khzTo8khz(samplesIn + i, samplesOut + (i * 4
) / 11, | 924 WebRtcSpl_Resample22khzTo8khz(samplesIn + i, samplesOut + (i * 4
) / 11, |
| 925 (WebRtcSpl_State22khzTo8khz *)stat
e1_, | 925 (WebRtcSpl_State22khzTo8khz *)stat
e1_, |
| 926 tmp_mem); | 926 tmp_mem); |
| 927 } | 927 } |
| 928 outLen = (lengthIn * 4) / 11; | 928 outLen = (lengthIn * 4) / 11; |
| 929 free(tmp_mem); | 929 free(tmp_mem); |
| 930 return 0; | 930 return 0; |
| 931 case kResamplerMode11To8: | 931 case kResamplerMode11To8: |
| 932 // We can only handle blocks of 160 samples | 932 // We can only handle blocks of 160 samples |
| 933 // Can be fixed, but I don't think it's needed | 933 // Can be fixed, but I don't think it's needed |
| 934 if ((lengthIn % 220) != 0) | 934 if ((lengthIn % 220) != 0) |
| 935 { | 935 { |
| 936 return -1; | 936 return -1; |
| 937 } | 937 } |
| 938 if (maxLen < ((lengthIn * 8) / 11)) | 938 if (maxLen < ((lengthIn * 8) / 11)) |
| 939 { | 939 { |
| 940 return -1; | 940 return -1; |
| 941 } | 941 } |
| 942 tmp_mem = (int32_t*)malloc(104 * sizeof(int32_t)); | 942 tmp_mem = (int32_t*)malloc(104 * sizeof(int32_t)); |
| 943 | 943 |
| 944 for (int i = 0; i < lengthIn; i += 220) | 944 for (size_t i = 0; i < lengthIn; i += 220) |
| 945 { | 945 { |
| 946 WebRtcSpl_Resample22khzTo16khz(samplesIn + i, samplesOut + (i *
8) / 11, | 946 WebRtcSpl_Resample22khzTo16khz(samplesIn + i, samplesOut + (i *
8) / 11, |
| 947 (WebRtcSpl_State22khzTo16khz *)st
ate1_, | 947 (WebRtcSpl_State22khzTo16khz *)st
ate1_, |
| 948 tmp_mem); | 948 tmp_mem); |
| 949 } | 949 } |
| 950 outLen = (lengthIn * 8) / 11; | 950 outLen = (lengthIn * 8) / 11; |
| 951 free(tmp_mem); | 951 free(tmp_mem); |
| 952 return 0; | 952 return 0; |
| 953 break; | 953 break; |
| 954 | 954 |
| 955 } | 955 } |
| 956 return 0; | 956 return 0; |
| 957 } | 957 } |
| 958 | 958 |
| 959 } // namespace webrtc | 959 } // namespace webrtc |
| OLD | NEW |