Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(17)

Side by Side Diff: media/base/audio_bus.cc

Issue 10829183: Introduce AudioBus to replace std::vector<float*>. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleanup. Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "media/base/audio_bus.h"
6
7 #include "base/logging.h"
8 #include "base/memory/aligned_memory.h"
9 #include "media/base/decrypt_config.h"
10
11 namespace media {
12
13 // Ensure each channel is 16-byte aligned for easy SSE optimizations.
14 static const int kChannelAlignment = 16;
15
16 AudioBus::AudioBus(int channels, int frames, ChannelLayout channel_layout)
17 : frames_(frames),
18 channel_layout_(channel_layout) {
19 // Choose a size such that each channel is aligned by kChannelAlignment.
Chris Rogers 2012/08/06 19:40:26 do we want sanity checking DCHECKS, etc. on channe
DaleCurtis 2012/08/07 01:36:32 Done.
20 int aligned_frames =
21 (frames_ + kChannelAlignment - 1) & ~(kChannelAlignment - 1);
22 audio_data_size_ = sizeof(float) * channels * aligned_frames;
Chris Rogers 2012/08/06 19:40:26 The security guys seemed keen on using size_t for
DaleCurtis 2012/08/07 01:36:32 Used CHECK() above plus limits to ensure this can'
23
24 audio_data_.reset(static_cast<float*>(base::AlignedAlloc(
25 audio_data_size_, kChannelAlignment)));
26
27 // Seperate audio data out into channels for easy lookup later.
Chris Rogers 2012/08/06 19:40:26 typo: Seperate
DaleCurtis 2012/08/07 01:36:32 Done.
28 audio_data_vector_.reserve(channels);
29 for (int i = 0; i < channels; ++i)
30 audio_data_vector_.push_back(audio_data_.get() + i * aligned_frames);
31 }
32
33 AudioBus::AudioBus(int frames, const std::vector<float*>& audio_data_vector)
34 : audio_data_vector_(audio_data_vector),
35 frames_(frames),
36 channel_layout_(CHANNEL_LAYOUT_NONE) {
37 // Sanity check wrapped vector for alignment and channel count.
38 for (size_t i = 0; i < audio_data_vector_.size(); ++i) {
39 DCHECK_EQ(reinterpret_cast<uintptr_t>(audio_data_vector_[i]) &
scherkus (not reviewing) 2012/08/06 18:55:34 idea: add static IsAligned() function at top by co
DaleCurtis 2012/08/07 01:36:32 Done.
40 (kChannelAlignment - 1), 0U);
41 }
42 }
43
44 AudioBus::~AudioBus() {}
45
46 scoped_ptr<AudioBus> AudioBus::Create(int channels, int frames) {
47 return scoped_ptr<AudioBus>(new AudioBus(
48 channels, frames, CHANNEL_LAYOUT_NONE));
49 }
50
51 scoped_ptr<AudioBus> AudioBus::Create(const AudioParameters& params) {
52 return scoped_ptr<AudioBus>(new AudioBus(
53 params.channels(), params.frames_per_buffer(), params.channel_layout()));
54 }
55
56 scoped_ptr<AudioBus> AudioBus::WrapVector(
57 int frames, const std::vector<float*>& audio_data_vector) {
58 return scoped_ptr<AudioBus>(new AudioBus(frames, audio_data_vector));
59 }
60
61 void AudioBus::Zero(int frames) {
62 DCHECK_LE(frames, frames_);
63 for (size_t i = 0; i < audio_data_vector_.size(); ++i)
64 memset(audio_data_vector_[i], 0, frames * sizeof(*audio_data_vector_[i]));
65 }
66
67 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698