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

Commit d0b254cd authored by Shunkai Yao's avatar Shunkai Yao Committed by Gerrit Code Review
Browse files

Merge "BundleContext: Add a loop to process input iteratively" into main

parents 01a2bd3f 7a0564c4
Loading
Loading
Loading
Loading
+27 −14
Original line number Original line Diff line number Diff line
@@ -854,15 +854,24 @@ IEffect::Status BundleContext::lvmProcess(float* in, float* out, int samples) {
            LOG(DEBUG) << "Effect_process() processing last frame";
            LOG(DEBUG) << "Effect_process() processing last frame";
        }
        }
        mNumberEffectsCalled = 0;
        mNumberEffectsCalled = 0;
        int frames = samples * sizeof(float) / frameSize;
        int bufferIndex = 0;
        // LVM library supports max of int16_t frames at a time and should be multiple of
        // kBlockSizeMultiple.
        constexpr int kBlockSizeMultiple = 4;
        constexpr int kMaxBlockFrames =
                (std::numeric_limits<int16_t>::max() / kBlockSizeMultiple) * kBlockSizeMultiple;
        while (frames > 0) {
            float* outTmp = (accumulate ? getWorkBuffer() : out);
            float* outTmp = (accumulate ? getWorkBuffer() : out);
            /* Process the samples */
            /* Process the samples */
            LVM_ReturnStatus_en lvmStatus;
            LVM_ReturnStatus_en lvmStatus;
            {
            {
                std::lock_guard lg(mMutex);
                std::lock_guard lg(mMutex);

                int processFrames = std::min(frames, kMaxBlockFrames);
            lvmStatus = LVM_Process(mInstance, in, outTmp, inputFrameCount, 0);
                lvmStatus = LVM_Process(mInstance, in + bufferIndex, outTmp + bufferIndex,
                                        processFrames, 0);
                if (lvmStatus != LVM_SUCCESS) {
                if (lvmStatus != LVM_SUCCESS) {
                LOG(ERROR) << __func__ << lvmStatus;
                    LOG(ERROR) << "LVM lib failed with error: " << lvmStatus;
                    return {EX_UNSUPPORTED_OPERATION, 0, 0};
                    return {EX_UNSUPPORTED_OPERATION, 0, 0};
                }
                }
                if (accumulate) {
                if (accumulate) {
@@ -870,6 +879,10 @@ IEffect::Status BundleContext::lvmProcess(float* in, float* out, int samples) {
                        out[i] += outTmp[i];
                        out[i] += outTmp[i];
                    }
                    }
                }
                }
                frames -= processFrames;
                int processedSize = processFrames * frameSize / sizeof(float);
                bufferIndex += processedSize;
            }
        }
        }
    } else {
    } else {
        for (int i = 0; i < samples; i++) {
        for (int i = 0; i < samples; i++) {