channel_mixing_matrix.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * Copyright (c) 2019 The WebRTC project authors. All Rights Reserved.
  3. *
  4. * Use of this source code is governed by a BSD-style license
  5. * that can be found in the LICENSE file in the root of the source
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #ifndef AUDIO_UTILITY_CHANNEL_MIXING_MATRIX_H_
  11. #define AUDIO_UTILITY_CHANNEL_MIXING_MATRIX_H_
  12. #include <vector>
  13. #include "api/audio/channel_layout.h"
  14. namespace webrtc {
  15. class ChannelMixingMatrix {
  16. public:
  17. ChannelMixingMatrix(ChannelLayout input_layout,
  18. int input_channels,
  19. ChannelLayout output_layout,
  20. int output_channels);
  21. ~ChannelMixingMatrix();
  22. // Create the transformation matrix of input channels to output channels.
  23. // Updates the empty matrix with the transformation, and returns true
  24. // if the transformation is just a remapping of channels (no mixing).
  25. // The size of |matrix| is |output_channels| x |input_channels|, i.e., the
  26. // number of rows equals the number of output channels and the number of
  27. // columns corresponds to the number of input channels.
  28. // This file is derived from Chromium's media/base/channel_mixing_matrix.h.
  29. bool CreateTransformationMatrix(std::vector<std::vector<float>>* matrix);
  30. private:
  31. const bool use_voip_channel_mapping_adjustments_;
  32. // Result transformation of input channels to output channels
  33. std::vector<std::vector<float>>* matrix_;
  34. // Input and output channel layout provided during construction.
  35. ChannelLayout input_layout_;
  36. int input_channels_;
  37. ChannelLayout output_layout_;
  38. int output_channels_;
  39. // Helper variable for tracking which inputs are currently unaccounted,
  40. // should be empty after construction completes.
  41. std::vector<Channels> unaccounted_inputs_;
  42. // Helper methods for managing unaccounted input channels.
  43. void AccountFor(Channels ch);
  44. bool IsUnaccounted(Channels ch) const;
  45. // Helper methods for checking if |ch| exists in either |input_layout_| or
  46. // |output_layout_| respectively.
  47. bool HasInputChannel(Channels ch) const;
  48. bool HasOutputChannel(Channels ch) const;
  49. // Helper methods for updating |matrix_| with the proper value for
  50. // mixing |input_ch| into |output_ch|. MixWithoutAccounting() does not
  51. // remove the channel from |unaccounted_inputs_|.
  52. void Mix(Channels input_ch, Channels output_ch, float scale);
  53. void MixWithoutAccounting(Channels input_ch, Channels output_ch, float scale);
  54. // Delete the copy constructor and assignment operator.
  55. ChannelMixingMatrix(const ChannelMixingMatrix& other) = delete;
  56. ChannelMixingMatrix& operator=(const ChannelMixingMatrix& other) = delete;
  57. };
  58. } // namespace webrtc
  59. #endif // AUDIO_UTILITY_CHANNEL_MIXING_MATRIX_H_