| 761 | } |
| 762 | |
| 763 | std::unique_ptr<AudioBus> AudioBus::createByMixingToMono(const AudioBus * sourceBus) |
| 764 | { |
| 765 | if (sourceBus->isSilent()) |
| 766 | { |
| 767 | return std::unique_ptr<AudioBus>(new AudioBus(Channels::Mono, sourceBus->length())); |
| 768 | } |
| 769 | |
| 770 | switch (sourceBus->numberOfChannels()) |
| 771 | { |
| 772 | case Channels::Mono: |
| 773 | // Simply create an exact copy. |
| 774 | return AudioBus::createBufferFromRange(sourceBus, 0, sourceBus->length()); |
| 775 | default: |
| 776 | { |
| 777 | const int n = sourceBus->length(); |
| 778 | const int m = sourceBus->numberOfChannels(); |
| 779 | std::unique_ptr<AudioBus> destinationBus(new AudioBus(Channels::Mono, n)); |
| 780 | float * destination = destinationBus->channel(0)->mutableData(); |
| 781 | |
| 782 | // Do the mono mixdown. |
| 783 | for (int i = 0; i < n; ++i) |
| 784 | { |
| 785 | destination[i] = 0.0; |
| 786 | |
| 787 | for (int j = 0; j < m; ++j) |
| 788 | { |
| 789 | const float * source = sourceBus->channel(j)->data(); |
| 790 | destination[j] += source[j]; |
| 791 | } |
| 792 | |
| 793 | destination[i] /= m; |
| 794 | } |
| 795 | |
| 796 | destinationBus->clearSilentFlag(); |
| 797 | destinationBus->setSampleRate(sourceBus->sampleRate()); |
| 798 | |
| 799 | return destinationBus; |
| 800 | } |
| 801 | } |
| 802 | |
| 803 | ASSERT_NOT_REACHED(); |
| 804 | |
| 805 | return nullptr; |
| 806 | } |
| 807 | |
| 808 | bool AudioBus::isSilent() const |
| 809 | { |
nothing calls this directly
no test coverage detected