Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 52897c2f authored by Dharmaray Kundargi's avatar Dharmaray Kundargi
Browse files

Fixed the SRC interface

bug - 3369860

Change-Id: I6b866d334af9c9aea1db0295bf19edbc4123293d
parent d01ef568
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ void LVAudiosetSampleRate(M4OSA_Int32 resamplerContext,M4OSA_Int32 inSampleRate)
void LVAudiosetVolume(M4OSA_Int32 resamplerContext, M4OSA_Int16 left, M4OSA_Int16 right) ;
void LVAudioresample_LowQuality(M4OSA_Int16* out, M4OSA_Int16* input,
                                     M4OSA_Int32 outFrameCount, M4OSA_Int32 resamplerContext);
void LVDestroy(M4OSA_Int32 resamplerContext);

void MonoTo2I_16( const M4OSA_Int16 *src,
                        M4OSA_Int16 *dst,
+7 −1
Original line number Diff line number Diff line
@@ -2212,7 +2212,7 @@ M4OSA_ERR M4MCS_init( M4MCS_Context *pContext,
    pC->iSsrcNbSamplIn = 0;
    pC->iSsrcNbSamplOut = 0;
    pC->SsrcScratch = M4OSA_NULL;

    pC->pLVAudioResampler = M4OSA_NULL;
    /**
    * Audio encoder */
    pC->pAudioEncCtxt = M4OSA_NULL;
@@ -3378,6 +3378,12 @@ M4OSA_ERR M4MCS_cleanUp( M4MCS_Context pContext )
        pC->pSsrcBufferOut = M4OSA_NULL;
    }

    if (pC->pLVAudioResampler != M4OSA_NULL)
    {
        LVDestroy((M4OSA_Int32)pC->pLVAudioResampler);
        pC->pLVAudioResampler = M4OSA_NULL;
    }

    /* ----- Free the audio encoder stuff ----- */

    if( M4OSA_NULL != pC->pAudioEncCtxt )
+7 −0
Original line number Diff line number Diff line
@@ -189,6 +189,7 @@ M4OSA_ERR M4VSS3GPP_audioMixingInit( M4VSS3GPP_AudioMixingContext *pContext,
    pC->ewc.pEncContext = M4OSA_NULL;
    pC->ewc.pDummyAuBuffer = M4OSA_NULL;
    pC->ewc.p3gpWriterContext = M4OSA_NULL;
    pC->pLVAudioResampler = M4OSA_NULL;
    /**
    * Set the OSAL filesystem function set */
    pC->pOsaFileReadPtr = pFileReadPtrFct;
@@ -592,6 +593,12 @@ M4OSA_ERR M4VSS3GPP_audioMixingCleanUp( M4VSS3GPP_AudioMixingContext pContext )
        pC->pTempBuffer = M4OSA_NULL;
    }

    if (pC->pLVAudioResampler != M4OSA_NULL)
    {
        LVDestroy(pC->pLVAudioResampler);
        pC->pLVAudioResampler = M4OSA_NULL;
    }

    /**
    * Free the shells interfaces */
    M4VSS3GPP_unRegisterAllWriters(&pC->ShellAPI);
+39 −5
Original line number Diff line number Diff line
@@ -45,19 +45,27 @@ struct VideoEditorResampler : public AudioBufferProvider {
    int16_t* mInput;
    int nbChannels;
    int nbSamples;
    M4OSA_Int32 outSamplingRate;
    M4OSA_Int32 inSamplingRate;

};

#define MAX_SAMPLEDURATION_FOR_CONVERTION 40 //ms

status_t VideoEditorResampler::getNextBuffer(AudioBufferProvider::Buffer *pBuffer) {

    pBuffer->raw = (void*)(this->mInput);
    uint32_t dataSize = pBuffer->frameCount * this->nbChannels * sizeof(int16_t);
    int16_t *pTmpInBuffer = (int16_t*)malloc(dataSize);
    memcpy(pTmpInBuffer, this->mInput, dataSize);
    pBuffer->raw = (void*)pTmpInBuffer;

    return OK;
}

void VideoEditorResampler::releaseBuffer(AudioBufferProvider::Buffer *pBuffer) {

    if(pBuffer->raw != NULL) {
        free(pBuffer->raw);
        pBuffer->raw = NULL;
    }
    pBuffer->frameCount = 0;
@@ -74,9 +82,11 @@ M4OSA_Int32 LVAudioResamplerCreate(M4OSA_Int32 bitDepth, M4OSA_Int32 inChannelCo
    if (context->mResampler == NULL) {
        return NO_MEMORY;
    }
    context->mResampler->setSampleRate(32000);
    context->mResampler->setSampleRate(android::VideoEditorResampler::kFreq32000Hz);
    context->mResampler->setVolume(0x1000, 0x1000);
    context->nbChannels = inChannelCount;
    context->outSamplingRate = sampleRate;
    context->mInput = NULL;

    return ((M4OSA_Int32)context);
}
@@ -91,9 +101,10 @@ void LVAudiosetSampleRate(M4OSA_Int32 resamplerContext, M4OSA_Int32 inSampleRate
     * nbSamples is calculated for 40ms worth of data;hence sample rate
     * is used to calculate the nbSamples
     */
    context->nbSamples = inSampleRate / 25;
    context->mInput = (int16_t*)malloc(context->nbSamples *
                                   context->nbChannels * sizeof(int16_t));
    context->inSamplingRate = inSampleRate;
    // Allocate buffer for maximum allowed number of samples.
    context->mInput = (int16_t*)malloc( (inSampleRate * MAX_SAMPLEDURATION_FOR_CONVERTION *
                                   context->nbChannels * sizeof(int16_t)) / 1000);
}

void LVAudiosetVolume(M4OSA_Int32 resamplerContext, M4OSA_Int16 left, M4OSA_Int16 right) {
@@ -103,6 +114,26 @@ void LVAudiosetVolume(M4OSA_Int32 resamplerContext, M4OSA_Int16 left, M4OSA_Int1
    context->mResampler->setVolume(left,right);
}

void LVDestroy(M4OSA_Int32 resamplerContext) {

    VideoEditorResampler *context =
       (VideoEditorResampler *)resamplerContext;

    if (context->mInput != NULL) {
        free(context->mInput);
        context->mInput = NULL;
    }

    if (context->mResampler != NULL) {
        delete context->mResampler;
        context->mResampler = NULL;
    }

    if (context != NULL) {
        delete context;
        context = NULL;
    }
}

void LVAudioresample_LowQuality(M4OSA_Int16* out, M4OSA_Int16* input,
                                     M4OSA_Int32 outFrameCount, M4OSA_Int32 resamplerContext) {
@@ -110,7 +141,10 @@ void LVAudioresample_LowQuality(M4OSA_Int16* out, M4OSA_Int16* input,
    VideoEditorResampler *context =
      (VideoEditorResampler *)resamplerContext;
    int32_t *pTmpBuffer = NULL;

    context->nbSamples = (context->inSamplingRate * outFrameCount) / context->outSamplingRate;
    memcpy(context->mInput,input,(context->nbSamples * context->nbChannels * sizeof(int16_t)));

    /*
     SRC module always gives stereo output, hence 2 for stereo audio
    */