1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/media/AudioChannelFormat.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,72 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim:set ts=2 sw=2 sts=2 et cindent: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 +#ifndef MOZILLA_AUDIOCHANNELFORMAT_H_ 1.10 +#define MOZILLA_AUDIOCHANNELFORMAT_H_ 1.11 + 1.12 +#include <stdint.h> 1.13 + 1.14 +#include "nsTArrayForwardDeclare.h" 1.15 + 1.16 +namespace mozilla { 1.17 + 1.18 +/* 1.19 + * This file provides utilities for upmixing and downmixing channels. 1.20 + * 1.21 + * The channel layouts, upmixing and downmixing are consistent with the 1.22 + * Web Audio spec. 1.23 + * 1.24 + * Channel layouts for up to 6 channels: 1.25 + * mono { M } 1.26 + * stereo { L, R } 1.27 + * { L, R, C } 1.28 + * quad { L, R, SL, SR } 1.29 + * { L, R, C, SL, SR } 1.30 + * 5.1 { L, R, C, LFE, SL, SR } 1.31 + * 1.32 + * Only 1, 2, 4 and 6 are currently defined in Web Audio. 1.33 + */ 1.34 + 1.35 +/** 1.36 + * Return a channel count whose channel layout includes all the channels from 1.37 + * aChannels1 and aChannels2. 1.38 + */ 1.39 +uint32_t 1.40 +GetAudioChannelsSuperset(uint32_t aChannels1, uint32_t aChannels2); 1.41 + 1.42 +/** 1.43 + * Given an array of input channel data, and an output channel count, 1.44 + * replaces the array with an array of upmixed channels. 1.45 + * This shuffles the array and may set some channel buffers to aZeroChannel. 1.46 + * Don't call this with input count >= output count. 1.47 + * This may return *more* channels than requested. In that case, downmixing 1.48 + * is required to to get to aOutputChannelCount. (This is how we handle 1.49 + * odd cases like 3 -> 4 upmixing.) 1.50 + * If aChannelArray.Length() was the input to one of a series of 1.51 + * GetAudioChannelsSuperset calls resulting in aOutputChannelCount, 1.52 + * no downmixing will be required. 1.53 + */ 1.54 +void 1.55 +AudioChannelsUpMix(nsTArray<const void*>* aChannelArray, 1.56 + uint32_t aOutputChannelCount, 1.57 + const void* aZeroChannel); 1.58 + 1.59 +/** 1.60 + * Given an array of input channels (which must be float format!), 1.61 + * downmix to aOutputChannelCount, and copy the results to the 1.62 + * channel buffers in aOutputChannels. 1.63 + * Don't call this with input count <= output count. 1.64 + */ 1.65 +void 1.66 +AudioChannelsDownMix(const nsTArray<const void*>& aChannelArray, 1.67 + float** aOutputChannels, 1.68 + uint32_t aOutputChannelCount, 1.69 + uint32_t aDuration); 1.70 + 1.71 +// A version of AudioChannelsDownMix that downmixes int16_ts may be required. 1.72 + 1.73 +} // namespace mozilla 1.74 + 1.75 +#endif /* MOZILLA_AUDIOCHANNELFORMAT_H_ */