| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 return channel(3); | 156 return channel(3); |
| 157 case ChannelSurroundLeft: | 157 case ChannelSurroundLeft: |
| 158 return channel(4); | 158 return channel(4); |
| 159 case ChannelSurroundRight: | 159 case ChannelSurroundRight: |
| 160 return channel(5); | 160 return channel(5); |
| 161 default: | 161 default: |
| 162 return nullptr; | 162 return nullptr; |
| 163 } | 163 } |
| 164 } | 164 } |
| 165 | 165 |
| 166 ASSERT_NOT_REACHED(); | 166 NOTREACHED(); |
| 167 return nullptr; | 167 return nullptr; |
| 168 } | 168 } |
| 169 | 169 |
| 170 const AudioChannel* AudioBus::channelByType(unsigned type) const { | 170 const AudioChannel* AudioBus::channelByType(unsigned type) const { |
| 171 return const_cast<AudioBus*>(this)->channelByType(type); | 171 return const_cast<AudioBus*>(this)->channelByType(type); |
| 172 } | 172 } |
| 173 | 173 |
| 174 // Returns true if the channel count and frame-size match. | 174 // Returns true if the channel count and frame-size match. |
| 175 bool AudioBus::topologyMatches(const AudioBus& bus) const { | 175 bool AudioBus::topologyMatches(const AudioBus& bus) const { |
| 176 if (numberOfChannels() != bus.numberOfChannels()) | 176 if (numberOfChannels() != bus.numberOfChannels()) |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 460 // All other cases, fall back to the discrete sum. This will perform | 460 // All other cases, fall back to the discrete sum. This will perform |
| 461 // channel-wise sum until the destination channels run out. | 461 // channel-wise sum until the destination channels run out. |
| 462 discreteSumFrom(sourceBus); | 462 discreteSumFrom(sourceBus); |
| 463 } | 463 } |
| 464 } | 464 } |
| 465 | 465 |
| 466 void AudioBus::copyWithGainFrom(const AudioBus& sourceBus, | 466 void AudioBus::copyWithGainFrom(const AudioBus& sourceBus, |
| 467 float* lastMixGain, | 467 float* lastMixGain, |
| 468 float targetGain) { | 468 float targetGain) { |
| 469 if (!topologyMatches(sourceBus)) { | 469 if (!topologyMatches(sourceBus)) { |
| 470 ASSERT_NOT_REACHED(); | 470 NOTREACHED(); |
| 471 zero(); | 471 zero(); |
| 472 return; | 472 return; |
| 473 } | 473 } |
| 474 | 474 |
| 475 if (sourceBus.isSilent()) { | 475 if (sourceBus.isSilent()) { |
| 476 zero(); | 476 zero(); |
| 477 return; | 477 return; |
| 478 } | 478 } |
| 479 | 479 |
| 480 unsigned numberOfChannels = this->numberOfChannels(); | 480 unsigned numberOfChannels = this->numberOfChannels(); |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 576 *lastMixGain = gain; | 576 *lastMixGain = gain; |
| 577 } | 577 } |
| 578 | 578 |
| 579 void AudioBus::copyWithSampleAccurateGainValuesFrom( | 579 void AudioBus::copyWithSampleAccurateGainValuesFrom( |
| 580 const AudioBus& sourceBus, | 580 const AudioBus& sourceBus, |
| 581 float* gainValues, | 581 float* gainValues, |
| 582 unsigned numberOfGainValues) { | 582 unsigned numberOfGainValues) { |
| 583 // Make sure we're processing from the same type of bus. | 583 // Make sure we're processing from the same type of bus. |
| 584 // We *are* able to process from mono -> stereo | 584 // We *are* able to process from mono -> stereo |
| 585 if (sourceBus.numberOfChannels() != 1 && !topologyMatches(sourceBus)) { | 585 if (sourceBus.numberOfChannels() != 1 && !topologyMatches(sourceBus)) { |
| 586 ASSERT_NOT_REACHED(); | 586 NOTREACHED(); |
| 587 return; | 587 return; |
| 588 } | 588 } |
| 589 | 589 |
| 590 if (!gainValues || numberOfGainValues > sourceBus.length()) { | 590 if (!gainValues || numberOfGainValues > sourceBus.length()) { |
| 591 ASSERT_NOT_REACHED(); | 591 NOTREACHED(); |
| 592 return; | 592 return; |
| 593 } | 593 } |
| 594 | 594 |
| 595 if (sourceBus.length() == numberOfGainValues && | 595 if (sourceBus.length() == numberOfGainValues && |
| 596 sourceBus.length() == length() && sourceBus.isSilent()) { | 596 sourceBus.length() == length() && sourceBus.isSilent()) { |
| 597 zero(); | 597 zero(); |
| 598 return; | 598 return; |
| 599 } | 599 } |
| 600 | 600 |
| 601 // We handle both the 1 -> N and N -> N case here. | 601 // We handle both the 1 -> N and N -> N case here. |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 695 // Do the mono mixdown. | 695 // Do the mono mixdown. |
| 696 for (unsigned i = 0; i < n; ++i) | 696 for (unsigned i = 0; i < n; ++i) |
| 697 destination[i] = (sourceL[i] + sourceR[i]) / 2; | 697 destination[i] = (sourceL[i] + sourceR[i]) / 2; |
| 698 | 698 |
| 699 destinationBus->clearSilentFlag(); | 699 destinationBus->clearSilentFlag(); |
| 700 destinationBus->setSampleRate(sourceBus->sampleRate()); | 700 destinationBus->setSampleRate(sourceBus->sampleRate()); |
| 701 return destinationBus; | 701 return destinationBus; |
| 702 } | 702 } |
| 703 } | 703 } |
| 704 | 704 |
| 705 ASSERT_NOT_REACHED(); | 705 NOTREACHED(); |
| 706 return nullptr; | 706 return nullptr; |
| 707 } | 707 } |
| 708 | 708 |
| 709 bool AudioBus::isSilent() const { | 709 bool AudioBus::isSilent() const { |
| 710 for (size_t i = 0; i < m_channels.size(); ++i) { | 710 for (size_t i = 0; i < m_channels.size(); ++i) { |
| 711 if (!m_channels[i]->isSilent()) | 711 if (!m_channels[i]->isSilent()) |
| 712 return false; | 712 return false; |
| 713 } | 713 } |
| 714 return true; | 714 return true; |
| 715 } | 715 } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 758 // If the bus needs no conversion then return as is. | 758 // If the bus needs no conversion then return as is. |
| 759 if ((!mixToMono || audioBus->numberOfChannels() == 1) && | 759 if ((!mixToMono || audioBus->numberOfChannels() == 1) && |
| 760 audioBus->sampleRate() == sampleRate) | 760 audioBus->sampleRate() == sampleRate) |
| 761 return audioBus; | 761 return audioBus; |
| 762 | 762 |
| 763 return AudioBus::createBySampleRateConverting(audioBus.get(), mixToMono, | 763 return AudioBus::createBySampleRateConverting(audioBus.get(), mixToMono, |
| 764 sampleRate); | 764 sampleRate); |
| 765 } | 765 } |
| 766 | 766 |
| 767 } // namespace blink | 767 } // namespace blink |
| OLD | NEW |