MCPcopy Create free account
hub / github.com/LabSound/LabSound / createByMixingToMono

Method createByMixingToMono

src/core/AudioBus.cpp:763–806  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

761}
762
763std::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
808bool AudioBus::isSilent() const
809{

Callers

nothing calls this directly

Calls 9

mutableDataMethod · 0.80
channelMethod · 0.80
isSilentMethod · 0.45
lengthMethod · 0.45
numberOfChannelsMethod · 0.45
dataMethod · 0.45
clearSilentFlagMethod · 0.45
setSampleRateMethod · 0.45
sampleRateMethod · 0.45

Tested by

no test coverage detected