1/* 2 * Copyright (C) 2012 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17#ifndef ANDROID_EFFECTDOWNMIX_H_ 18#define ANDROID_EFFECTDOWNMIX_H_ 19 20#include <audio_effects/effect_downmix.h> 21#include <audio_utils/primitives.h> 22#include <system/audio.h> 23 24/*------------------------------------ 25 * definitions 26 *------------------------------------ 27*/ 28 29#define DOWNMIX_OUTPUT_CHANNELS AUDIO_CHANNEL_OUT_STEREO 30 31typedef enum { 32 DOWNMIX_STATE_UNINITIALIZED, 33 DOWNMIX_STATE_INITIALIZED, 34 DOWNMIX_STATE_ACTIVE, 35} downmix_state_t; 36 37/* parameters for each downmixer */ 38typedef struct { 39 downmix_state_t state; 40 downmix_type_t type; 41 bool apply_volume_correction; 42 uint8_t input_channel_count; 43} downmix_object_t; 44 45 46typedef struct downmix_module_s { 47 const struct effect_interface_s *itfe; 48 effect_config_t config; 49 downmix_object_t context; 50} downmix_module_t; 51 52const uint32_t kSides = AUDIO_CHANNEL_OUT_SIDE_LEFT | AUDIO_CHANNEL_OUT_SIDE_RIGHT; 53const uint32_t kBacks = AUDIO_CHANNEL_OUT_BACK_LEFT | AUDIO_CHANNEL_OUT_BACK_RIGHT; 54const uint32_t kUnsupported = 55 AUDIO_CHANNEL_OUT_FRONT_LEFT_OF_CENTER | AUDIO_CHANNEL_OUT_FRONT_RIGHT_OF_CENTER | 56 AUDIO_CHANNEL_OUT_TOP_CENTER | 57 AUDIO_CHANNEL_OUT_TOP_FRONT_LEFT | 58 AUDIO_CHANNEL_OUT_TOP_FRONT_CENTER | 59 AUDIO_CHANNEL_OUT_TOP_FRONT_RIGHT | 60 AUDIO_CHANNEL_OUT_TOP_BACK_LEFT | 61 AUDIO_CHANNEL_OUT_TOP_BACK_CENTER | 62 AUDIO_CHANNEL_OUT_TOP_BACK_RIGHT; 63 64/*------------------------------------ 65 * Effect API 66 *------------------------------------ 67*/ 68int32_t DownmixLib_QueryNumberEffects(uint32_t *pNumEffects); 69int32_t DownmixLib_QueryEffect(uint32_t index, 70 effect_descriptor_t *pDescriptor); 71int32_t DownmixLib_Create(const effect_uuid_t *uuid, 72 int32_t sessionId, 73 int32_t ioId, 74 effect_handle_t *pHandle); 75int32_t DownmixLib_Release(effect_handle_t handle); 76int32_t DownmixLib_GetDescriptor(const effect_uuid_t *uuid, 77 effect_descriptor_t *pDescriptor); 78 79static int Downmix_Process(effect_handle_t self, 80 audio_buffer_t *inBuffer, 81 audio_buffer_t *outBuffer); 82static int Downmix_Command(effect_handle_t self, 83 uint32_t cmdCode, 84 uint32_t cmdSize, 85 void *pCmdData, 86 uint32_t *replySize, 87 void *pReplyData); 88static int Downmix_GetDescriptor(effect_handle_t self, 89 effect_descriptor_t *pDescriptor); 90 91 92/*------------------------------------ 93 * internal functions 94 *------------------------------------ 95*/ 96int Downmix_Init(downmix_module_t *pDwmModule); 97int Downmix_Configure(downmix_module_t *pDwmModule, effect_config_t *pConfig, bool init); 98int Downmix_Reset(downmix_object_t *pDownmixer, bool init); 99int Downmix_setParameter(downmix_object_t *pDownmixer, int32_t param, size_t size, void *pValue); 100int Downmix_getParameter(downmix_object_t *pDownmixer, int32_t param, size_t *pSize, void *pValue); 101 102void Downmix_foldFromQuad(int16_t *pSrc, int16_t*pDst, size_t numFrames, bool accumulate); 103void Downmix_foldFromSurround(int16_t *pSrc, int16_t*pDst, size_t numFrames, bool accumulate); 104void Downmix_foldFrom5Point1(int16_t *pSrc, int16_t*pDst, size_t numFrames, bool accumulate); 105void Downmix_foldFrom7Point1(int16_t *pSrc, int16_t*pDst, size_t numFrames, bool accumulate); 106bool Downmix_foldGeneric( 107 uint32_t mask, int16_t *pSrc, int16_t*pDst, size_t numFrames, bool accumulate); 108 109#endif /*ANDROID_EFFECTDOWNMIX_H_*/ 110