blob: cb7a69f2af4837110d9998cb79c5c84d44a7f08d [file] [log] [blame]
Chih-Chung Chang99698662011-06-30 14:21:38 +08001/*
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
James Dong3bd45592012-01-20 19:28:01 -080017#ifndef VE_BACKGROUND_AUDIO_PROC_H
18#define VE_BACKGROUND_AUDIO_PROC_H
19
Chih-Chung Chang99698662011-06-30 14:21:38 +080020#include "M4OSA_Error.h"
21#include "M4OSA_Types.h"
22#include "M4OSA_Memory.h"
23#include "M4OSA_Export.h"
24#include "M4OSA_CoreID.h"
25
Chih-Chung Chang99698662011-06-30 14:21:38 +080026
James Dong3bd45592012-01-20 19:28:01 -080027namespace android {
Chih-Chung Chang99698662011-06-30 14:21:38 +080028
29typedef struct {
30 M4OSA_UInt16* m_dataAddress; // Android SRC needs a Int16 pointer
31 M4OSA_UInt32 m_bufferSize;
32} M4AM_Buffer16; // Structure contains Int16_t pointer
33
James Dong3bd45592012-01-20 19:28:01 -080034enum AudioFormat {
35 MONO_16_BIT,
36 STEREO_16_BIT
37};
38
Chih-Chung Chang99698662011-06-30 14:21:38 +080039// Following struct will be used by app to supply the PT and BT properties
40// along with ducking values
41typedef struct {
42 M4OSA_Int32 lvInSampleRate; // Sampling audio freq (8000,16000 or more )
43 M4OSA_Int32 lvOutSampleRate; //Sampling audio freq (8000,16000 or more )
James Dong3bd45592012-01-20 19:28:01 -080044 AudioFormat lvBTFormat;
Chih-Chung Chang99698662011-06-30 14:21:38 +080045
46 M4OSA_Int32 lvInDucking_threshold;
47 M4OSA_Float lvInDucking_lowVolume;
48 M4OSA_Bool lvInDucking_enable;
49 M4OSA_Float lvPTVolLevel;
50 M4OSA_Float lvBTVolLevel;
51 M4OSA_Int32 lvBTChannelCount;
52 M4OSA_Int32 lvPTChannelCount;
James Dong3bd45592012-01-20 19:28:01 -080053} AudioMixSettings;
Chih-Chung Chang99698662011-06-30 14:21:38 +080054
55// This class is defined to get SF SRC access
56class VideoEditorBGAudioProcessing {
57public:
58 VideoEditorBGAudioProcessing();
James Dong3bd45592012-01-20 19:28:01 -080059 ~VideoEditorBGAudioProcessing() {}
Chih-Chung Chang99698662011-06-30 14:21:38 +080060
James Dong3bd45592012-01-20 19:28:01 -080061 void setMixParams(const AudioMixSettings& params);
62
63 M4OSA_Int32 mixAndDuck(
Chih-Chung Chang99698662011-06-30 14:21:38 +080064 void* primaryTrackBuffer,
65 void* backgroundTrackBuffer,
66 void* mixedOutputBuffer);
67
Chih-Chung Chang99698662011-06-30 14:21:38 +080068private:
James Dong3bd45592012-01-20 19:28:01 -080069 enum {
70 kProcessingWindowSize = 10,
71 };
72
Chih-Chung Chang99698662011-06-30 14:21:38 +080073 M4OSA_Int32 mInSampleRate;
74 M4OSA_Int32 mOutSampleRate;
James Dong3bd45592012-01-20 19:28:01 -080075 AudioFormat mBTFormat;
Chih-Chung Chang99698662011-06-30 14:21:38 +080076
77 M4OSA_Bool mIsSSRCneeded;
78 M4OSA_Int32 mBTChannelCount;
79 M4OSA_Int32 mPTChannelCount;
80 M4OSA_UInt8 mChannelConversion;
81
82 M4OSA_UInt32 mDucking_threshold;
83 M4OSA_Float mDucking_lowVolume;
84 M4OSA_Float mDuckingFactor ;
85 M4OSA_Bool mDucking_enable;
James Dong3bd45592012-01-20 19:28:01 -080086 M4OSA_Int32 mAudioVolumeArray[kProcessingWindowSize];
Chih-Chung Chang99698662011-06-30 14:21:38 +080087 M4OSA_Int32 mAudVolArrIndex;
88 M4OSA_Bool mDoDucking;
89 M4OSA_Float mPTVolLevel;
90 M4OSA_Float mBTVolLevel;
91
92 M4AM_Buffer16 mBTBuffer;
93
94 M4OSA_Int32 getDecibelSound(M4OSA_UInt32 value);
95 M4OSA_Bool isThresholdBreached(M4OSA_Int32* averageValue,
96 M4OSA_Int32 storeCount, M4OSA_Int32 thresholdValue);
97
98 // This returns the size of buffer which needs to allocated
99 // before resampling is called
100 M4OSA_Int32 calculateOutResampleBufSize();
James Donged6269f2012-01-19 18:40:59 -0800101
102 // Don't call me.
103 VideoEditorBGAudioProcessing(const VideoEditorBGAudioProcessing&);
104 VideoEditorBGAudioProcessing& operator=(
105 const VideoEditorBGAudioProcessing&);
Chih-Chung Chang99698662011-06-30 14:21:38 +0800106};
James Dong3bd45592012-01-20 19:28:01 -0800107
108} // namespace android
109
110#endif // VE_BACKGROUND_AUDIO_PROC_H