• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef VE_BACKGROUND_AUDIO_PROC_H
18 #define VE_BACKGROUND_AUDIO_PROC_H
19 
20 #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 
26 
27 namespace android {
28 
29 typedef 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 
34 enum AudioFormat {
35     MONO_16_BIT,
36     STEREO_16_BIT
37 };
38 
39 // Following struct will be used by app to supply the PT and BT properties
40 // along with ducking values
41 typedef struct {
42     M4OSA_Int32 lvInSampleRate; // Sampling audio freq (8000,16000 or more )
43     M4OSA_Int32 lvOutSampleRate; //Sampling audio freq (8000,16000 or more )
44     AudioFormat lvBTFormat;
45 
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;
53 } AudioMixSettings;
54 
55 // This class is defined to get SF SRC access
56 class VideoEditorBGAudioProcessing {
57 public:
58     VideoEditorBGAudioProcessing();
~VideoEditorBGAudioProcessing()59     ~VideoEditorBGAudioProcessing() {}
60 
61     void setMixParams(const AudioMixSettings& params);
62 
63     M4OSA_Int32 mixAndDuck(
64                     void* primaryTrackBuffer,
65                     void* backgroundTrackBuffer,
66                     void* mixedOutputBuffer);
67 
68 private:
69     enum {
70         kProcessingWindowSize = 10,
71     };
72 
73     M4OSA_Int32 mInSampleRate;
74     M4OSA_Int32 mOutSampleRate;
75     AudioFormat mBTFormat;
76 
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;
86     M4OSA_Int32 mAudioVolumeArray[kProcessingWindowSize];
87     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();
101 
102     // Don't call me.
103     VideoEditorBGAudioProcessing(const VideoEditorBGAudioProcessing&);
104     VideoEditorBGAudioProcessing& operator=(
105             const VideoEditorBGAudioProcessing&);
106 };
107 
108 }  // namespace android
109 
110 #endif // VE_BACKGROUND_AUDIO_PROC_H
111