Commit e9a72d64 authored by Jeremy Roman's avatar Jeremy Roman Committed by Commit Bot

audio: Directly store channels in AudioBus::channels_.

Nothing depends on pointer stability of these (and besides, this vector
is never resized), so these can just be stored inline as long as we
don't go out of our way to prevent move-assignment.

Change-Id: Id0ddfc214068c4d1b8e9c9fa0defea2fff33d435
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2561752
Commit-Queue: Raymond Toy <rtoy@chromium.org>
Auto-Submit: Jeremy Roman <jbroman@chromium.org>
Reviewed-by: default avatarRaymond Toy <rtoy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#831881}
parent aed31981
......@@ -34,6 +34,7 @@ include_rules = [
"+base/numerics/safe_conversions.h",
"+base/optional.h",
"+base/rand_util.h",
"+base/ranges",
"+base/sequence_checker.h",
"+base/sequenced_task_runner.h",
"+base/single_thread_task_runner.h",
......
......@@ -34,6 +34,7 @@
#include <memory>
#include <utility>
#include "base/ranges/algorithm.h"
#include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/public/platform/web_audio_bus.h"
#include "third_party/blink/renderer/platform/audio/audio_file_reader.h"
......@@ -65,10 +66,11 @@ AudioBus::AudioBus(unsigned number_of_channels, uint32_t length, bool allocate)
channels_.ReserveInitialCapacity(number_of_channels);
for (unsigned i = 0; i < number_of_channels; ++i) {
std::unique_ptr<AudioChannel> channel =
allocate ? std::make_unique<AudioChannel>(length)
: std::make_unique<AudioChannel>(nullptr, length);
channels_.push_back(std::move(channel));
if (allocate) {
channels_.emplace_back(length);
} else {
channels_.emplace_back(nullptr, length);
}
}
layout_ = kLayoutCanonical; // for now this is the only layout we define
......@@ -89,13 +91,13 @@ void AudioBus::ResizeSmaller(uint32_t new_length) {
if (new_length <= length_)
length_ = new_length;
for (unsigned i = 0; i < channels_.size(); ++i)
channels_[i]->ResizeSmaller(new_length);
for (AudioChannel& channel : channels_)
channel.ResizeSmaller(new_length);
}
void AudioBus::Zero() {
for (unsigned i = 0; i < channels_.size(); ++i)
channels_[i]->Zero();
for (AudioChannel& channel : channels_)
channel.Zero();
}
AudioChannel* AudioBus::ChannelByType(unsigned channel_type) {
......@@ -670,16 +672,12 @@ scoped_refptr<AudioBus> AudioBus::CreateByMixingToMono(
}
bool AudioBus::IsSilent() const {
for (size_t i = 0; i < channels_.size(); ++i) {
if (!channels_[i]->IsSilent())
return false;
}
return true;
return base::ranges::all_of(channels_, &AudioChannel::IsSilent);
}
void AudioBus::ClearSilentFlag() {
for (size_t i = 0; i < channels_.size(); ++i)
channels_[i]->ClearSilentFlag();
for (AudioChannel& channel : channels_)
channel.ClearSilentFlag();
}
scoped_refptr<AudioBus> DecodeAudioFileData(const char* data, size_t size) {
......
......@@ -80,9 +80,9 @@ class PLATFORM_EXPORT AudioBus : public ThreadSafeRefCounted<AudioBus> {
// Channels
unsigned NumberOfChannels() const { return channels_.size(); }
AudioChannel* Channel(unsigned channel) { return channels_[channel].get(); }
AudioChannel* Channel(unsigned channel) { return &channels_[channel]; }
const AudioChannel* Channel(unsigned channel) const {
return channels_[channel].get();
return &channels_[channel];
}
AudioChannel* ChannelByType(unsigned type);
const AudioChannel* ChannelByType(unsigned type) const;
......@@ -176,7 +176,7 @@ class PLATFORM_EXPORT AudioBus : public ThreadSafeRefCounted<AudioBus> {
void SumFromByDownMixing(const AudioBus&);
uint32_t length_;
Vector<std::unique_ptr<AudioChannel>> channels_;
Vector<AudioChannel, 2> channels_;
int layout_;
float sample_rate_; // 0.0 if unknown or N/A
......
......@@ -34,7 +34,6 @@
#include "base/numerics/checked_math.h"
#include "third_party/blink/renderer/platform/audio/audio_array.h"
#include "third_party/blink/renderer/platform/platform_export.h"
#include "third_party/blink/renderer/platform/wtf/allocator/allocator.h"
namespace blink {
......@@ -42,8 +41,6 @@ namespace blink {
// samples.
// The PCM samples are normally assumed to be in a nominal range -1.0 -> +1.0
class PLATFORM_EXPORT AudioChannel {
USING_FAST_MALLOC(AudioChannel);
public:
// Memory can be externally referenced, or can be internally allocated with an
// AudioFloatArray.
......@@ -130,8 +127,6 @@ class PLATFORM_EXPORT AudioChannel {
float* raw_pointer_;
std::unique_ptr<AudioFloatArray> mem_buffer_;
bool silent_;
DISALLOW_COPY_AND_ASSIGN(AudioChannel);
};
} // namespace blink
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment