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.
5 #ifndef MEDIA_BASE_CHANNEL_MIXER_H_
6 #define MEDIA_BASE_CHANNEL_MIXER_H_
10 #include "base/macros.h"
11 #include "media/base/channel_layout.h"
12 #include "media/base/media_export.h"
17 class AudioParameters
;
19 // ChannelMixer is for converting audio between channel layouts. The conversion
20 // matrix is built upon construction and used during each Transform() call. The
21 // algorithm works by generating a conversion matrix mapping each output channel
22 // to list of input channels. The transform renders all of the output channels,
23 // with each output channel rendered according to a weighted sum of the relevant
24 // input channels as defined in the matrix.
25 class MEDIA_EXPORT ChannelMixer
{
27 ChannelMixer(ChannelLayout input_layout
, ChannelLayout output_layout
);
28 ChannelMixer(const AudioParameters
& input
, const AudioParameters
& output
);
31 // Transforms all channels from |input| into |output| channels.
32 void Transform(const AudioBus
* input
, AudioBus
* output
);
35 void Initialize(ChannelLayout input_layout
, int input_channels
,
36 ChannelLayout output_layout
, int output_channels
);
38 // 2D matrix of output channels to input channels.
39 std::vector
< std::vector
<float> > matrix_
;
41 // Optimization case for when we can simply remap the input channels to output
42 // channels and don't need to do a multiply-accumulate loop over |matrix_|.
45 DISALLOW_COPY_AND_ASSIGN(ChannelMixer
);
50 #endif // MEDIA_BASE_CHANNEL_MIXER_H_