michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim:set ts=2 sw=2 sts=2 et cindent: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: #ifndef MOZILLA_AUDIOCHANNELFORMAT_H_ michael@0: #define MOZILLA_AUDIOCHANNELFORMAT_H_ michael@0: michael@0: #include michael@0: michael@0: #include "nsTArrayForwardDeclare.h" michael@0: michael@0: namespace mozilla { michael@0: michael@0: /* michael@0: * This file provides utilities for upmixing and downmixing channels. michael@0: * michael@0: * The channel layouts, upmixing and downmixing are consistent with the michael@0: * Web Audio spec. michael@0: * michael@0: * Channel layouts for up to 6 channels: michael@0: * mono { M } michael@0: * stereo { L, R } michael@0: * { L, R, C } michael@0: * quad { L, R, SL, SR } michael@0: * { L, R, C, SL, SR } michael@0: * 5.1 { L, R, C, LFE, SL, SR } michael@0: * michael@0: * Only 1, 2, 4 and 6 are currently defined in Web Audio. michael@0: */ michael@0: michael@0: /** michael@0: * Return a channel count whose channel layout includes all the channels from michael@0: * aChannels1 and aChannels2. michael@0: */ michael@0: uint32_t michael@0: GetAudioChannelsSuperset(uint32_t aChannels1, uint32_t aChannels2); michael@0: michael@0: /** michael@0: * Given an array of input channel data, and an output channel count, michael@0: * replaces the array with an array of upmixed channels. michael@0: * This shuffles the array and may set some channel buffers to aZeroChannel. michael@0: * Don't call this with input count >= output count. michael@0: * This may return *more* channels than requested. In that case, downmixing michael@0: * is required to to get to aOutputChannelCount. (This is how we handle michael@0: * odd cases like 3 -> 4 upmixing.) michael@0: * If aChannelArray.Length() was the input to one of a series of michael@0: * GetAudioChannelsSuperset calls resulting in aOutputChannelCount, michael@0: * no downmixing will be required. michael@0: */ michael@0: void michael@0: AudioChannelsUpMix(nsTArray* aChannelArray, michael@0: uint32_t aOutputChannelCount, michael@0: const void* aZeroChannel); michael@0: michael@0: /** michael@0: * Given an array of input channels (which must be float format!), michael@0: * downmix to aOutputChannelCount, and copy the results to the michael@0: * channel buffers in aOutputChannels. michael@0: * Don't call this with input count <= output count. michael@0: */ michael@0: void michael@0: AudioChannelsDownMix(const nsTArray& aChannelArray, michael@0: float** aOutputChannels, michael@0: uint32_t aOutputChannelCount, michael@0: uint32_t aDuration); michael@0: michael@0: // A version of AudioChannelsDownMix that downmixes int16_ts may be required. michael@0: michael@0: } // namespace mozilla michael@0: michael@0: #endif /* MOZILLA_AUDIOCHANNELFORMAT_H_ */