Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / media / base / channel_mixer.h
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 #ifndef MEDIA_BASE_CHANNEL_MIXER_H_
6 #define MEDIA_BASE_CHANNEL_MIXER_H_
7
8 #include <vector>
9
10 #include "base/macros.h"
11 #include "media/base/channel_layout.h"
12 #include "media/base/media_export.h"
13
14 namespace media {
15
16 class AudioBus;
17 class AudioParameters;
18
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 {
26  public:
27   ChannelMixer(ChannelLayout input_layout, ChannelLayout output_layout);
28   ChannelMixer(const AudioParameters& input, const AudioParameters& output);
29   ~ChannelMixer();
30
31   // Transforms all channels from |input| into |output| channels.
32   void Transform(const AudioBus* input, AudioBus* output);
33
34  private:
35   void Initialize(ChannelLayout input_layout, int input_channels,
36                   ChannelLayout output_layout, int output_channels);
37
38   // 2D matrix of output channels to input channels.
39   std::vector< std::vector<float> > matrix_;
40
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_|.
43   bool remapping_;
44
45   DISALLOW_COPY_AND_ASSIGN(ChannelMixer);
46 };
47
48 }  // namespace media
49
50 #endif  // MEDIA_BASE_CHANNEL_MIXER_H_