• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifdef BUILD_FLOAT
31 #define LVM_FLOAT float
32 #endif
33 typedef enum {
34     DOWNMIX_STATE_UNINITIALIZED,
35     DOWNMIX_STATE_INITIALIZED,
36     DOWNMIX_STATE_ACTIVE,
37 } downmix_state_t;
38 
39 /* parameters for each downmixer */
40 typedef struct {
41     downmix_state_t state;
42     downmix_type_t type;
43     bool apply_volume_correction;
44     uint8_t input_channel_count;
45 } downmix_object_t;
46 
47 
48 typedef struct downmix_module_s {
49     const struct effect_interface_s *itfe;
50     effect_config_t config;
51     downmix_object_t context;
52 } downmix_module_t;
53 
54 const uint32_t kSides = AUDIO_CHANNEL_OUT_SIDE_LEFT | AUDIO_CHANNEL_OUT_SIDE_RIGHT;
55 const uint32_t kBacks = AUDIO_CHANNEL_OUT_BACK_LEFT | AUDIO_CHANNEL_OUT_BACK_RIGHT;
56 const uint32_t kUnsupported =
57         AUDIO_CHANNEL_OUT_FRONT_LEFT_OF_CENTER | AUDIO_CHANNEL_OUT_FRONT_RIGHT_OF_CENTER |
58         AUDIO_CHANNEL_OUT_TOP_CENTER |
59         AUDIO_CHANNEL_OUT_TOP_FRONT_LEFT |
60         AUDIO_CHANNEL_OUT_TOP_FRONT_CENTER |
61         AUDIO_CHANNEL_OUT_TOP_FRONT_RIGHT |
62         AUDIO_CHANNEL_OUT_TOP_BACK_LEFT |
63         AUDIO_CHANNEL_OUT_TOP_BACK_CENTER |
64         AUDIO_CHANNEL_OUT_TOP_BACK_RIGHT;
65 
66 /*------------------------------------
67  * Effect API
68  *------------------------------------
69 */
70 int32_t DownmixLib_Create(const effect_uuid_t *uuid,
71         int32_t sessionId,
72         int32_t ioId,
73         effect_handle_t *pHandle);
74 int32_t DownmixLib_Release(effect_handle_t handle);
75 int32_t DownmixLib_GetDescriptor(const effect_uuid_t *uuid,
76         effect_descriptor_t *pDescriptor);
77 
78 static int Downmix_Process(effect_handle_t self,
79         audio_buffer_t *inBuffer,
80         audio_buffer_t *outBuffer);
81 static int Downmix_Command(effect_handle_t self,
82         uint32_t cmdCode,
83         uint32_t cmdSize,
84         void *pCmdData,
85         uint32_t *replySize,
86         void *pReplyData);
87 static int Downmix_GetDescriptor(effect_handle_t self,
88         effect_descriptor_t *pDescriptor);
89 
90 
91 /*------------------------------------
92  * internal functions
93  *------------------------------------
94 */
95 int Downmix_Init(downmix_module_t *pDwmModule);
96 int Downmix_Configure(downmix_module_t *pDwmModule, effect_config_t *pConfig, bool init);
97 int Downmix_Reset(downmix_object_t *pDownmixer, bool init);
98 int Downmix_setParameter(downmix_object_t *pDownmixer, int32_t param, uint32_t size, void *pValue);
99 int Downmix_getParameter(downmix_object_t *pDownmixer, int32_t param, uint32_t *pSize, void *pValue);
100 #ifdef BUILD_FLOAT
101 void Downmix_foldFromQuad(LVM_FLOAT *pSrc, LVM_FLOAT *pDst, size_t numFrames, bool accumulate);
102 void Downmix_foldFrom5Point1(LVM_FLOAT *pSrc, LVM_FLOAT *pDst, size_t numFrames, bool accumulate);
103 void Downmix_foldFrom7Point1(LVM_FLOAT *pSrc, LVM_FLOAT *pDst, size_t numFrames, bool accumulate);
104 bool Downmix_foldGeneric(
105         uint32_t mask, LVM_FLOAT *pSrc, LVM_FLOAT *pDst, size_t numFrames, bool accumulate);
106 #else
107 void Downmix_foldFromQuad(int16_t *pSrc, int16_t*pDst, size_t numFrames, bool accumulate);
108 void Downmix_foldFrom5Point1(int16_t *pSrc, int16_t*pDst, size_t numFrames, bool accumulate);
109 void Downmix_foldFrom7Point1(int16_t *pSrc, int16_t*pDst, size_t numFrames, bool accumulate);
110 bool Downmix_foldGeneric(
111         uint32_t mask, int16_t *pSrc, int16_t*pDst, size_t numFrames, bool accumulate);
112 #endif
113 
114 #endif /*ANDROID_EFFECTDOWNMIX_H_*/
115