OLD | NEW |
(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 #ifndef MEDIA_BASE_CHANNEL_MIXER_H_ |
| 6 #define MEDIA_BASE_CHANNEL_MIXER_H_ |
| 7 |
| 8 #include <vector> |
| 9 |
| 10 #include "base/basictypes.h" |
| 11 #include "media/base/channel_layout.h" |
| 12 #include "media/base/media_export.h" |
| 13 |
| 14 namespace media { |
| 15 |
| 16 class AudioBus; |
| 17 |
| 18 // ChannelMixer is a simple rematrixing solution for converting between channel |
| 19 // layouts. The conversion matrix is built upon construction and used during |
| 20 // each Rematrix() call. The algorithm works by generating a conversion matrix |
| 21 // mapping each output channel to list of input channels. The rematrixing is |
| 22 // then done by scaling each input channel according to the matrix and summing |
| 23 // it into a single output channel. |
| 24 class MEDIA_EXPORT ChannelMixer { |
| 25 public: |
| 26 ChannelMixer(ChannelLayout input, ChannelLayout output); |
| 27 ~ChannelMixer(); |
| 28 |
| 29 // Rematrixes all channels from |input| into |output|. |
| 30 void Rematrix(const AudioBus* input, AudioBus* output); |
| 31 |
| 32 private: |
| 33 // Constructor helper methods for managing unaccounted input channels. |
| 34 void AccountFor(Channels ch); |
| 35 bool IsUnaccounted(Channels ch); |
| 36 |
| 37 // Helper methods for checking if |ch| exists in either |input_layout_| or |
| 38 // |output_layout_| respectively. |
| 39 bool HasInputChannel(Channels ch); |
| 40 bool HasOutputChannel(Channels ch); |
| 41 |
| 42 // Constructor helper methods for updating |matrix_| with the proper value for |
| 43 // mixing |input_ch| into |output_ch|. MixWithoutAccounting() does not remove |
| 44 // the channel from |unaccounted_inputs_|. |
| 45 void Mix(Channels input_ch, Channels output_ch, float scale); |
| 46 void MixWithoutAccounting(Channels input_ch, Channels output_ch, float scale); |
| 47 |
| 48 // Input and output channel layout provided during construction. |
| 49 ChannelLayout input_layout_; |
| 50 ChannelLayout output_layout_; |
| 51 |
| 52 // Helper variable for tracking which inputs are currently unaccounted, should |
| 53 // be empty after construction completes. |
| 54 std::vector<Channels> unaccounted_inputs_; |
| 55 |
| 56 // 2D matrix of output channels to input channels. |
| 57 std::vector< std::vector<float> > matrix_; |
| 58 |
| 59 // Optimization case for when we can simply remap the input channels to output |
| 60 // channels and don't need to do a multiply-accumulate loop over |matrix_|. |
| 61 bool remapping_; |
| 62 |
| 63 DISALLOW_COPY_AND_ASSIGN(ChannelMixer); |
| 64 }; |
| 65 |
| 66 } // namespace media |
| 67 |
| 68 #endif // MEDIA_BASE_CHANNEL_MIXER_H_ |
OLD | NEW |