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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 | 42 |
43 namespace blink { | 43 namespace blink { |
44 | 44 |
45 using namespace VectorMath; | 45 using namespace VectorMath; |
46 | 46 |
47 const unsigned MaxBusChannels = 32; | 47 const unsigned MaxBusChannels = 32; |
48 | 48 |
49 PassRefPtr<AudioBus> AudioBus::create(unsigned numberOfChannels, | 49 PassRefPtr<AudioBus> AudioBus::create(unsigned numberOfChannels, |
50 size_t length, | 50 size_t length, |
51 bool allocate) { | 51 bool allocate) { |
52 DCHECK_LE(numberOfChannels, MaxBusChannels); | 52 ASSERT(numberOfChannels <= MaxBusChannels); |
53 if (numberOfChannels > MaxBusChannels) | 53 if (numberOfChannels > MaxBusChannels) |
54 return nullptr; | 54 return nullptr; |
55 | 55 |
56 return adoptRef(new AudioBus(numberOfChannels, length, allocate)); | 56 return adoptRef(new AudioBus(numberOfChannels, length, allocate)); |
57 } | 57 } |
58 | 58 |
59 AudioBus::AudioBus(unsigned numberOfChannels, size_t length, bool allocate) | 59 AudioBus::AudioBus(unsigned numberOfChannels, size_t length, bool allocate) |
60 : m_length(length), m_busGain(1), m_isFirstTime(true), m_sampleRate(0) { | 60 : m_length(length), m_busGain(1), m_isFirstTime(true), m_sampleRate(0) { |
61 m_channels.reserveInitialCapacity(numberOfChannels); | 61 m_channels.reserveInitialCapacity(numberOfChannels); |
62 | 62 |
(...skipping 11 matching lines...) Expand all Loading... |
74 float* storage, | 74 float* storage, |
75 size_t length) { | 75 size_t length) { |
76 if (channelIndex < m_channels.size()) { | 76 if (channelIndex < m_channels.size()) { |
77 channel(channelIndex)->set(storage, length); | 77 channel(channelIndex)->set(storage, length); |
78 // FIXME: verify that this length matches all the other channel lengths | 78 // FIXME: verify that this length matches all the other channel lengths |
79 m_length = length; | 79 m_length = length; |
80 } | 80 } |
81 } | 81 } |
82 | 82 |
83 void AudioBus::resizeSmaller(size_t newLength) { | 83 void AudioBus::resizeSmaller(size_t newLength) { |
84 DCHECK_LE(newLength, m_length); | 84 ASSERT(newLength <= m_length); |
85 if (newLength <= m_length) | 85 if (newLength <= m_length) |
86 m_length = newLength; | 86 m_length = newLength; |
87 | 87 |
88 for (unsigned i = 0; i < m_channels.size(); ++i) | 88 for (unsigned i = 0; i < m_channels.size(); ++i) |
89 m_channels[i]->resizeSmaller(newLength); | 89 m_channels[i]->resizeSmaller(newLength); |
90 } | 90 } |
91 | 91 |
92 void AudioBus::zero() { | 92 void AudioBus::zero() { |
93 for (unsigned i = 0; i < m_channels.size(); ++i) | 93 for (unsigned i = 0; i < m_channels.size(); ++i) |
94 m_channels[i]->zero(); | 94 m_channels[i]->zero(); |
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
472 zero(); | 472 zero(); |
473 return; | 473 return; |
474 } | 474 } |
475 | 475 |
476 if (sourceBus.isSilent()) { | 476 if (sourceBus.isSilent()) { |
477 zero(); | 477 zero(); |
478 return; | 478 return; |
479 } | 479 } |
480 | 480 |
481 unsigned numberOfChannels = this->numberOfChannels(); | 481 unsigned numberOfChannels = this->numberOfChannels(); |
482 DCHECK_LE(numberOfChannels, MaxBusChannels); | 482 ASSERT(numberOfChannels <= MaxBusChannels); |
483 if (numberOfChannels > MaxBusChannels) | 483 if (numberOfChannels > MaxBusChannels) |
484 return; | 484 return; |
485 | 485 |
486 // If it is copying from the same bus and no need to change gain, just return. | 486 // If it is copying from the same bus and no need to change gain, just return. |
487 if (this == &sourceBus && *lastMixGain == targetGain && targetGain == 1) | 487 if (this == &sourceBus && *lastMixGain == targetGain && targetGain == 1) |
488 return; | 488 return; |
489 | 489 |
490 AudioBus& sourceBusSafe = const_cast<AudioBus&>(sourceBus); | 490 AudioBus& sourceBusSafe = const_cast<AudioBus&>(sourceBus); |
491 const float* sources[MaxBusChannels]; | 491 const float* sources[MaxBusChannels]; |
492 float* destinations[MaxBusChannels]; | 492 float* destinations[MaxBusChannels]; |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
608 float* destination = channel(channelIndex)->mutableData(); | 608 float* destination = channel(channelIndex)->mutableData(); |
609 vmul(source, 1, gainValues, 1, destination, 1, numberOfGainValues); | 609 vmul(source, 1, gainValues, 1, destination, 1, numberOfGainValues); |
610 } | 610 } |
611 } | 611 } |
612 | 612 |
613 PassRefPtr<AudioBus> AudioBus::createBySampleRateConverting( | 613 PassRefPtr<AudioBus> AudioBus::createBySampleRateConverting( |
614 const AudioBus* sourceBus, | 614 const AudioBus* sourceBus, |
615 bool mixToMono, | 615 bool mixToMono, |
616 double newSampleRate) { | 616 double newSampleRate) { |
617 // sourceBus's sample-rate must be known. | 617 // sourceBus's sample-rate must be known. |
618 DCHECK(sourceBus); | 618 ASSERT(sourceBus && sourceBus->sampleRate()); |
619 DCHECK(sourceBus->sampleRate()); | |
620 if (!sourceBus || !sourceBus->sampleRate()) | 619 if (!sourceBus || !sourceBus->sampleRate()) |
621 return nullptr; | 620 return nullptr; |
622 | 621 |
623 double sourceSampleRate = sourceBus->sampleRate(); | 622 double sourceSampleRate = sourceBus->sampleRate(); |
624 double destinationSampleRate = newSampleRate; | 623 double destinationSampleRate = newSampleRate; |
625 double sampleRateRatio = sourceSampleRate / destinationSampleRate; | 624 double sampleRateRatio = sourceSampleRate / destinationSampleRate; |
626 unsigned numberOfSourceChannels = sourceBus->numberOfChannels(); | 625 unsigned numberOfSourceChannels = sourceBus->numberOfChannels(); |
627 | 626 |
628 if (numberOfSourceChannels == 1) | 627 if (numberOfSourceChannels == 1) |
629 mixToMono = false; // already mono | 628 mixToMono = false; // already mono |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
760 // If the bus needs no conversion then return as is. | 759 // If the bus needs no conversion then return as is. |
761 if ((!mixToMono || audioBus->numberOfChannels() == 1) && | 760 if ((!mixToMono || audioBus->numberOfChannels() == 1) && |
762 audioBus->sampleRate() == sampleRate) | 761 audioBus->sampleRate() == sampleRate) |
763 return audioBus; | 762 return audioBus; |
764 | 763 |
765 return AudioBus::createBySampleRateConverting(audioBus.get(), mixToMono, | 764 return AudioBus::createBySampleRateConverting(audioBus.get(), mixToMono, |
766 sampleRate); | 765 sampleRate); |
767 } | 766 } |
768 | 767 |
769 } // namespace blink | 768 } // namespace blink |
OLD | NEW |