1/*
2 * Copyright (C) 2011 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#include "M4OSA_Error.h"
18#include "M4OSA_Types.h"
19#include "M4OSA_Memory.h"
20#include "M4OSA_Export.h"
21#include "M4OSA_CoreID.h"
22
23namespace android{
24
25#define WINDOW_SIZE 10
26
27enum veAudioFormat {MONO_16_BIT, STEREO_16_BIT};
28
29
30typedef struct {
31    M4OSA_UInt16*   m_dataAddress; // Android SRC needs a Int16 pointer
32    M4OSA_UInt32    m_bufferSize;
33} M4AM_Buffer16;    // Structure contains Int16_t pointer
34
35// Following struct will be used by app to supply the PT and BT properties
36// along with ducking values
37typedef struct {
38    M4OSA_Int32 lvInSampleRate; // Sampling audio freq (8000,16000 or more )
39    M4OSA_Int32 lvOutSampleRate; //Sampling audio freq (8000,16000 or more )
40    veAudioFormat lvBTFormat;
41
42    M4OSA_Int32 lvInDucking_threshold;
43    M4OSA_Float lvInDucking_lowVolume;
44    M4OSA_Bool lvInDucking_enable;
45    M4OSA_Float lvPTVolLevel;
46    M4OSA_Float lvBTVolLevel;
47    M4OSA_Int32 lvBTChannelCount;
48    M4OSA_Int32 lvPTChannelCount;
49} veAudMixSettings;
50
51// This class is defined to get SF SRC access
52class VideoEditorBGAudioProcessing {
53public:
54    VideoEditorBGAudioProcessing();
55    void veSetAudioProcessingParams(const veAudMixSettings& mixParams);
56
57    M4OSA_Int32 veProcessAudioMixNDuck(
58                    void* primaryTrackBuffer,
59                    void* backgroundTrackBuffer,
60                    void* mixedOutputBuffer);
61
62    ~VideoEditorBGAudioProcessing();
63
64private:
65    M4OSA_Int32 mInSampleRate;
66    M4OSA_Int32 mOutSampleRate;
67    veAudioFormat mBTFormat;
68
69    M4OSA_Bool mIsSSRCneeded;
70    M4OSA_Int32 mBTChannelCount;
71    M4OSA_Int32 mPTChannelCount;
72    M4OSA_UInt8 mChannelConversion;
73
74    M4OSA_UInt32 mDucking_threshold;
75    M4OSA_Float mDucking_lowVolume;
76    M4OSA_Float mDuckingFactor ;
77    M4OSA_Bool mDucking_enable;
78    M4OSA_Int32 mAudioVolumeArray[WINDOW_SIZE];
79    M4OSA_Int32 mAudVolArrIndex;
80    M4OSA_Bool mDoDucking;
81    M4OSA_Float mPTVolLevel;
82    M4OSA_Float mBTVolLevel;
83
84    M4AM_Buffer16 mBTBuffer;
85
86    M4OSA_Int32 getDecibelSound(M4OSA_UInt32 value);
87    M4OSA_Bool  isThresholdBreached(M4OSA_Int32* averageValue,
88                    M4OSA_Int32 storeCount, M4OSA_Int32 thresholdValue);
89
90    // This returns the size of buffer which needs to allocated
91    // before resampling is called
92    M4OSA_Int32 calculateOutResampleBufSize();
93};
94} // namespace android
95