15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef MEDIA_BASE_CHANNEL_MIXER_H_ 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define MEDIA_BASE_CHANNEL_MIXER_H_ 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <vector> 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/basictypes.h" 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "media/base/channel_layout.h" 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "media/base/media_export.h" 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace media { 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class AudioBus; 172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class AudioParameters; 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// ChannelMixer is for converting audio between channel layouts. The conversion 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// matrix is built upon construction and used during each Transform() call. The 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// algorithm works by generating a conversion matrix mapping each output channel 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// to list of input channels. The transform renders all of the output channels, 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// with each output channel rendered according to a weighted sum of the relevant 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// input channels as defined in the matrix. 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class MEDIA_EXPORT ChannelMixer { 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ChannelMixer(ChannelLayout input_layout, ChannelLayout output_layout); 282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ChannelMixer(const AudioParameters& input, const AudioParameters& output); 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ~ChannelMixer(); 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Transforms all channels from |input| into |output| channels. 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void Transform(const AudioBus* input, AudioBus* output); 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private: 35c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) void Initialize(ChannelLayout input_layout, int input_channels, 36c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) ChannelLayout output_layout, int output_channels); 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 2D matrix of output channels to input channels. 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::vector< std::vector<float> > matrix_; 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Optimization case for when we can simply remap the input channels to output 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // channels and don't need to do a multiply-accumulate loop over |matrix_|. 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool remapping_; 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(ChannelMixer); 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace media 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif // MEDIA_BASE_CHANNEL_MIXER_H_ 51