Home | History | Annotate | Download | only in downmix
      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 
     31 typedef enum {
     32     DOWNMIX_STATE_UNINITIALIZED,
     33     DOWNMIX_STATE_INITIALIZED,
     34     DOWNMIX_STATE_ACTIVE,
     35 } downmix_state_t;
     36 
     37 /* parameters for each downmixer */
     38 typedef 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 
     46 typedef 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 
     52 const uint32_t kSides = AUDIO_CHANNEL_OUT_SIDE_LEFT | AUDIO_CHANNEL_OUT_SIDE_RIGHT;
     53 const uint32_t kBacks = AUDIO_CHANNEL_OUT_BACK_LEFT | AUDIO_CHANNEL_OUT_BACK_RIGHT;
     54 const 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 */
     68 int32_t DownmixLib_Create(const effect_uuid_t *uuid,
     69         int32_t sessionId,
     70         int32_t ioId,
     71         effect_handle_t *pHandle);
     72 int32_t DownmixLib_Release(effect_handle_t handle);
     73 int32_t DownmixLib_GetDescriptor(const effect_uuid_t *uuid,
     74         effect_descriptor_t *pDescriptor);
     75 
     76 static int Downmix_Process(effect_handle_t self,
     77         audio_buffer_t *inBuffer,
     78         audio_buffer_t *outBuffer);
     79 static int Downmix_Command(effect_handle_t self,
     80         uint32_t cmdCode,
     81         uint32_t cmdSize,
     82         void *pCmdData,
     83         uint32_t *replySize,
     84         void *pReplyData);
     85 static int Downmix_GetDescriptor(effect_handle_t self,
     86         effect_descriptor_t *pDescriptor);
     87 
     88 
     89 /*------------------------------------
     90  * internal functions
     91  *------------------------------------
     92 */
     93 int Downmix_Init(downmix_module_t *pDwmModule);
     94 int Downmix_Configure(downmix_module_t *pDwmModule, effect_config_t *pConfig, bool init);
     95 int Downmix_Reset(downmix_object_t *pDownmixer, bool init);
     96 int Downmix_setParameter(downmix_object_t *pDownmixer, int32_t param, uint32_t size, void *pValue);
     97 int Downmix_getParameter(downmix_object_t *pDownmixer, int32_t param, uint32_t *pSize, void *pValue);
     98 
     99 void Downmix_foldFromQuad(int16_t *pSrc, int16_t*pDst, size_t numFrames, bool accumulate);
    100 void Downmix_foldFrom5Point1(int16_t *pSrc, int16_t*pDst, size_t numFrames, bool accumulate);
    101 void Downmix_foldFrom7Point1(int16_t *pSrc, int16_t*pDst, size_t numFrames, bool accumulate);
    102 bool Downmix_foldGeneric(
    103         uint32_t mask, int16_t *pSrc, int16_t*pDst, size_t numFrames, bool accumulate);
    104 
    105 #endif /*ANDROID_EFFECTDOWNMIX_H_*/
    106