* limitations under the License.
*/
-#define LOG_NDEBUG 1
+//#define LOG_NDEBUG 0
#define LOG_TAG "VideoEditorBGAudioProcessing"
#include <utils/Log.h>
#include "VideoEditorBGAudioProcessing.h"
namespace android {
VideoEditorBGAudioProcessing::VideoEditorBGAudioProcessing() {
-
- ALOGV("VideoEditorBGAudioProcessing:: Construct VideoEditorBGAudioProcessing ");
+ ALOGV("Constructor");
mAudVolArrIndex = 0;
mDoDucking = 0;
mBTChannelCount = 1;
}
-M4OSA_Int32 VideoEditorBGAudioProcessing::veProcessAudioMixNDuck(
- void *pPTBuffer, void *pBTBuffer, void *pOutBuffer) {
-
- M4AM_Buffer16* pPrimaryTrack = (M4AM_Buffer16*)pPTBuffer;
- M4AM_Buffer16* pBackgroundTrack = (M4AM_Buffer16*)pBTBuffer;
- M4AM_Buffer16* pMixedOutBuffer = (M4AM_Buffer16*)pOutBuffer;
-
- ALOGV("VideoEditorBGAudioProcessing::lvProcessAudioMixNDuck \
- pPTBuffer 0x%x pBTBuffer 0x%x pOutBuffer 0x%x", pPTBuffer,
- pBTBuffer, pOutBuffer);
+M4OSA_Int32 VideoEditorBGAudioProcessing::mixAndDuck(
+ void *primaryTrackBuffer,
+ void *backgroundTrackBuffer,
+ void *outBuffer) {
- M4OSA_ERR result = M4NO_ERROR;
- M4OSA_Int16 *pBTMdata1;
- M4OSA_Int16 *pPTMdata2;
- M4OSA_UInt32 uiPCMsize;
+ ALOGV("mixAndDuck: track buffers (primary: 0x%x and background: 0x%x) "
+ "and out buffer 0x%x",
+ primaryTrackBuffer, backgroundTrackBuffer, outBuffer);
- // Ducking variable
- M4OSA_UInt16 loopIndex = 0;
- M4OSA_Int16 *pPCM16Sample = M4OSA_NULL;
- M4OSA_Int32 peakDbValue = 0;
- M4OSA_Int32 previousDbValue = 0;
- M4OSA_UInt32 i;
+ M4AM_Buffer16* pPrimaryTrack = (M4AM_Buffer16*)primaryTrackBuffer;
+ M4AM_Buffer16* pBackgroundTrack = (M4AM_Buffer16*)backgroundTrackBuffer;
+ M4AM_Buffer16* pMixedOutBuffer = (M4AM_Buffer16*)outBuffer;
// Output size if same as PT size
pMixedOutBuffer->m_bufferSize = pPrimaryTrack->m_bufferSize;
memcpy((void *)pMixedOutBuffer->m_dataAddress,
(void *)pPrimaryTrack->m_dataAddress, pMixedOutBuffer->m_bufferSize);
+ // Initialize ducking variables
// Initially contains the input primary track
- pPTMdata2 = (M4OSA_Int16*)pMixedOutBuffer->m_dataAddress;
+ M4OSA_Int16 *pPTMdata2 = (M4OSA_Int16*)pMixedOutBuffer->m_dataAddress;
+
// Contains BG track processed data(like channel conversion etc..
- pBTMdata1 = (M4OSA_Int16*) pBackgroundTrack->m_dataAddress;
+ M4OSA_Int16 *pBTMdata1 = (M4OSA_Int16*) pBackgroundTrack->m_dataAddress;
// Since we need to give sample count and not buffer size
- uiPCMsize = pMixedOutBuffer->m_bufferSize/2 ;
+ M4OSA_UInt32 uiPCMsize = pMixedOutBuffer->m_bufferSize / 2 ;
if ((mDucking_enable) && (mPTVolLevel != 0.0)) {
- // ALOGI("VideoEditorBGAudioProcessing:: In Ducking analysis ");
- loopIndex = 0;
- peakDbValue = 0;
- previousDbValue = peakDbValue;
-
- pPCM16Sample = (M4OSA_Int16*)pPrimaryTrack->m_dataAddress;
+ M4OSA_Int32 peakDbValue = 0;
+ M4OSA_Int32 previousDbValue = 0;
+ M4OSA_Int16 *pPCM16Sample = (M4OSA_Int16*)pPrimaryTrack->m_dataAddress;
+ const size_t n = pPrimaryTrack->m_bufferSize / sizeof(M4OSA_Int16);
- while (loopIndex < pPrimaryTrack->m_bufferSize/sizeof(M4OSA_Int16)) {
+ for (size_t loopIndex = 0; loopIndex < n; ++loopIndex) {
if (pPCM16Sample[loopIndex] >= 0) {
peakDbValue = previousDbValue > pPCM16Sample[loopIndex] ?
previousDbValue : pPCM16Sample[loopIndex];
previousDbValue: -pPCM16Sample[loopIndex];
previousDbValue = peakDbValue;
}
- loopIndex++;
}
mAudioVolumeArray[mAudVolArrIndex] = getDecibelSound(peakDbValue);
- ALOGV("VideoEditorBGAudioProcessing:: getDecibelSound %d",
- mAudioVolumeArray[mAudVolArrIndex]);
+ // Check for threshold is done after kProcessingWindowSize cycles
+ if (mAudVolArrIndex >= kProcessingWindowSize - 1) {
+ mDoDucking = isThresholdBreached(
+ mAudioVolumeArray, mAudVolArrIndex, mDucking_threshold);
- // WINDOW_SIZE is 10 by default
- // Check for threshold is done after 10 cycles
- if (mAudVolArrIndex >= WINDOW_SIZE - 1) {
- mDoDucking = isThresholdBreached(mAudioVolumeArray,
- mAudVolArrIndex,mDucking_threshold );
mAudVolArrIndex = 0;
} else {
mAudVolArrIndex++;
// FADE OUT BG Track
// Increment ducking factor in total steps in factor
// of low volume steps to reach low volume level
- mDuckingFactor -= (mDucking_lowVolume);
+ mDuckingFactor -= mDucking_lowVolume;
} else {
mDuckingFactor = mDucking_lowVolume;
}
// FADE IN BG Track
// Increment ducking factor in total steps of
// low volume factor to reach orig.volume level
- mDuckingFactor += (mDucking_lowVolume);
+ mDuckingFactor += mDucking_lowVolume;
} else {
mDuckingFactor = 1.0;
}
} // end if - mDucking_enable
- // Mixing Logic
-
- ALOGV("VideoEditorBGAudioProcessing:: Out of Ducking analysis uiPCMsize\
- %d %f %f", mDoDucking, mDuckingFactor,mBTVolLevel);
-
+ // Mixing logic
+ ALOGV("Out of Ducking analysis uiPCMsize %d %f %f",
+ mDoDucking, mDuckingFactor, mBTVolLevel);
while (uiPCMsize-- > 0) {
- M4OSA_Int32 temp;
// Set vol factor for BT and PT
*pBTMdata1 = (M4OSA_Int16)(*pBTMdata1*mBTVolLevel);
*pPTMdata2 = (M4OSA_Int16)(*pPTMdata2*mPTVolLevel);
*pBTMdata1 = (M4OSA_Int16)(*pBTMdata1 /2 + *pPTMdata2 /2);
}
+ M4OSA_Int32 temp;
if (*pBTMdata1 < 0) {
temp = -(*pBTMdata1) * 2; // bring to original Amplitude level
pBTMdata1++;
pPTMdata2++;
}
- //ALOGV("VideoEditorBGAudioProcessing:: Copy final out ");
+
memcpy((void *)pMixedOutBuffer->m_dataAddress,
(void *)pBackgroundTrack->m_dataAddress,
pBackgroundTrack->m_bufferSize);
- ALOGV("VideoEditorBGAudioProcessing::lvProcessAudioMixNDuck EXIT");
- return result;
-}
-
-VideoEditorBGAudioProcessing::~VideoEditorBGAudioProcessing() {
-
+ ALOGV("mixAndDuck: X");
+ return M4NO_ERROR;
}
M4OSA_Int32 VideoEditorBGAudioProcessing::calculateOutResampleBufSize() {
return (mOutSampleRate / mInSampleRate) * mBTBuffer.m_bufferSize;
}
-void VideoEditorBGAudioProcessing ::veSetAudioProcessingParams(
- const veAudMixSettings& gInputParams) {
-
- ALOGV("VideoEditorBGAudioProcessing:: ENTER lvSetAudioProcessingParams ");
- mDucking_enable = gInputParams.lvInDucking_enable;
- mDucking_lowVolume = gInputParams.lvInDucking_lowVolume;
- mDucking_threshold = gInputParams.lvInDucking_threshold;
-
- mPTVolLevel = gInputParams.lvPTVolLevel;
- mBTVolLevel = gInputParams.lvBTVolLevel ;
-
- mBTChannelCount = gInputParams.lvBTChannelCount;
- mPTChannelCount = gInputParams.lvPTChannelCount;
-
- mBTFormat = gInputParams.lvBTFormat;
-
- mInSampleRate = gInputParams.lvInSampleRate;
- mOutSampleRate = gInputParams.lvOutSampleRate;
-
+void VideoEditorBGAudioProcessing::setMixParams(
+ const AudioMixSettings& setting) {
+ ALOGV("setMixParams");
+
+ mDucking_enable = setting.lvInDucking_enable;
+ mDucking_lowVolume = setting.lvInDucking_lowVolume;
+ mDucking_threshold = setting.lvInDucking_threshold;
+ mPTVolLevel = setting.lvPTVolLevel;
+ mBTVolLevel = setting.lvBTVolLevel ;
+ mBTChannelCount = setting.lvBTChannelCount;
+ mPTChannelCount = setting.lvPTChannelCount;
+ mBTFormat = setting.lvBTFormat;
+ mInSampleRate = setting.lvInSampleRate;
+ mOutSampleRate = setting.lvOutSampleRate;
+
+ // Reset the following params to default values
mAudVolArrIndex = 0;
mDoDucking = 0;
- mDuckingFactor = 1.0; // default
-
- ALOGV("VideoEditorBGAudioProcessing:: ducking_enable 0x%x \
- ducking_lowVolume %f ducking_threshold %d fPTVolLevel %f BTVolLevel %f",
- mDucking_enable, mDucking_lowVolume, mDucking_threshold,
- mPTVolLevel, mPTVolLevel);
-
- // Following logc decides if SSRC support is needed for this mixing
- mIsSSRCneeded = (gInputParams.lvInSampleRate != gInputParams.lvOutSampleRate);
- if (gInputParams.lvBTChannelCount != gInputParams.lvPTChannelCount){
- if (gInputParams.lvBTChannelCount == 2){
- mChannelConversion = 1; // convert to MONO
+ mDuckingFactor = 1.0;
+
+ ALOGV("ducking enable 0x%x lowVolume %f threshold %d "
+ "fPTVolLevel %f BTVolLevel %f",
+ mDucking_enable, mDucking_lowVolume, mDucking_threshold,
+ mPTVolLevel, mPTVolLevel);
+
+ // Decides if SSRC support is needed for this mixing
+ mIsSSRCneeded = (setting.lvInSampleRate != setting.lvOutSampleRate);
+ if (setting.lvBTChannelCount != setting.lvPTChannelCount){
+ if (setting.lvBTChannelCount == 2){
+ mChannelConversion = 1; // convert to MONO
} else {
- mChannelConversion = 2; // Convert to STEREO
+ mChannelConversion = 2; // Convert to STEREO
}
} else {
- mChannelConversion = 0;
+ mChannelConversion = 0;
}
- ALOGV("VideoEditorBGAudioProcessing:: EXIT veSetAudioProcessingParams ");
}
-
// Fast way to compute 10 * log(value)
M4OSA_Int32 VideoEditorBGAudioProcessing::getDecibelSound(M4OSA_UInt32 value) {
+ ALOGV("getDecibelSound: %ld", value);
+
if (value <= 0 || value > 0x8000) {
return 0;
} else if (value > 0x4000) { // 32768
M4OSA_Int32 storeCount,
M4OSA_Int32 thresholdValue) {
+ ALOGV("isThresholdBreached");
+
int totalValue = 0;
for (int i = 0; i < storeCount; ++i) {
totalValue += averageValue[i];
* limitations under the License.
*/
+#ifndef VE_BACKGROUND_AUDIO_PROC_H
+#define VE_BACKGROUND_AUDIO_PROC_H
+
#include "M4OSA_Error.h"
#include "M4OSA_Types.h"
#include "M4OSA_Memory.h"
#include "M4OSA_Export.h"
#include "M4OSA_CoreID.h"
-namespace android{
-
-#define WINDOW_SIZE 10
-
-enum veAudioFormat {MONO_16_BIT, STEREO_16_BIT};
+namespace android {
typedef struct {
M4OSA_UInt16* m_dataAddress; // Android SRC needs a Int16 pointer
M4OSA_UInt32 m_bufferSize;
} M4AM_Buffer16; // Structure contains Int16_t pointer
+enum AudioFormat {
+ MONO_16_BIT,
+ STEREO_16_BIT
+};
+
// Following struct will be used by app to supply the PT and BT properties
// along with ducking values
typedef struct {
M4OSA_Int32 lvInSampleRate; // Sampling audio freq (8000,16000 or more )
M4OSA_Int32 lvOutSampleRate; //Sampling audio freq (8000,16000 or more )
- veAudioFormat lvBTFormat;
+ AudioFormat lvBTFormat;
M4OSA_Int32 lvInDucking_threshold;
M4OSA_Float lvInDucking_lowVolume;
M4OSA_Float lvBTVolLevel;
M4OSA_Int32 lvBTChannelCount;
M4OSA_Int32 lvPTChannelCount;
-} veAudMixSettings;
+} AudioMixSettings;
// This class is defined to get SF SRC access
class VideoEditorBGAudioProcessing {
public:
VideoEditorBGAudioProcessing();
- void veSetAudioProcessingParams(const veAudMixSettings& mixParams);
+ ~VideoEditorBGAudioProcessing() {}
- M4OSA_Int32 veProcessAudioMixNDuck(
+ void setMixParams(const AudioMixSettings& params);
+
+ M4OSA_Int32 mixAndDuck(
void* primaryTrackBuffer,
void* backgroundTrackBuffer,
void* mixedOutputBuffer);
- ~VideoEditorBGAudioProcessing();
-
private:
+ enum {
+ kProcessingWindowSize = 10,
+ };
+
M4OSA_Int32 mInSampleRate;
M4OSA_Int32 mOutSampleRate;
- veAudioFormat mBTFormat;
+ AudioFormat mBTFormat;
M4OSA_Bool mIsSSRCneeded;
M4OSA_Int32 mBTChannelCount;
M4OSA_Float mDucking_lowVolume;
M4OSA_Float mDuckingFactor ;
M4OSA_Bool mDucking_enable;
- M4OSA_Int32 mAudioVolumeArray[WINDOW_SIZE];
+ M4OSA_Int32 mAudioVolumeArray[kProcessingWindowSize];
M4OSA_Int32 mAudVolArrIndex;
M4OSA_Bool mDoDucking;
M4OSA_Float mPTVolLevel;
VideoEditorBGAudioProcessing& operator=(
const VideoEditorBGAudioProcessing&);
};
-} // namespace android
+
+} // namespace android
+
+#endif // VE_BACKGROUND_AUDIO_PROC_H