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

Commit ebfafc52 authored by Antti S. Lankila's avatar Antti S. Lankila
Browse files

Fix enable/disable behavior and improve effects

- when android requests audioeffect to become disabled, the effect
  must acknowledge its safe removal by returning -ENODATA error code
  from process(). We just return -ENODATA immediately.

- Improve compression to better deal with very sharp level changes.

Change-Id: I8f280f5ae47e9ae4bfad65fcac9b2603eaf7f540
parent 8357ebd4
Loading
Loading
Loading
Loading
+5 −10
Original line number Diff line number Diff line
@@ -108,17 +108,12 @@ int32_t Effect::command(uint32_t cmdCode, uint32_t cmdSize, void *pCmdData, uint
    return 0;
}

/* This implementation removes the effect at earliest opportunity. */
int32_t Effect::process(audio_buffer_t *in, audio_buffer_t *out)
{
    if (! mEnable) {
        for (uint32_t i = 0; i < in->frameCount; i ++) {
	    int32_t tmpL = read(in, i * 2);
	    int32_t tmpR = read(in, i * 2 + 1);
	    write(out, i * 2, tmpL);
	    write(out, i * 2 + 1, tmpR);
	}
        return 0;
    } else {
	return process_effect(in, out);
    int32_t status = process_effect(in, out);
    if (! mEnable && status == 0) {
        status = -ENODATA;
    }
    return status;
}
+1 −1
Original line number Diff line number Diff line
@@ -105,7 +105,7 @@ class Effect {
    public:
    Effect();
    virtual ~Effect();
    virtual int32_t process(audio_buffer_t *in, audio_buffer_t *out);
    int32_t process(audio_buffer_t *in, audio_buffer_t *out);
    virtual int32_t command(uint32_t cmdCode, uint32_t cmdSize, void* pCmdData, uint32_t* replySize, void* pReplyData) = 0;
    virtual int32_t process_effect(audio_buffer_t *in, audio_buffer_t *out) = 0;
};
+3 −23
Original line number Diff line number Diff line
@@ -119,26 +119,6 @@ uint64_t EffectCompression::estimateOneChannelLevel(audio_buffer_t *in, int32_t
    return (power / in->frameCount);
}

/* Skipping a volume control effect is an ear-shattering experience.
 * Android should automatically remove us after short delay, so we just
 * apply the last volume we know while we are disabled. */
int32_t EffectCompression::process(audio_buffer_t *in, audio_buffer_t *out)
{
    if (! mEnable) {
        for (uint32_t i = 0; i < in->frameCount; i ++) {
            int32_t tmpL = read(in, i * 2);
            int32_t tmpR = read(in, i * 2 + 1);
            tmpL = int64_t(tmpL) * mUserVolumes[0] >> 24;
            tmpR = int64_t(tmpR) * mUserVolumes[1] >> 24;
            write(out, i * 2, tmpL);
            write(out, i * 2 + 1, tmpR);
        }
        return 0;
    } else {
        return process_effect(in, out);
    }
}

int32_t EffectCompression::process_effect(audio_buffer_t *in, audio_buffer_t *out)
{
    /* Analyze both channels separately, pick the maximum power measured. */
@@ -179,11 +159,11 @@ int32_t EffectCompression::process_effect(audio_buffer_t *in, audio_buffer_t *ou
        /* 8.24 */
	int32_t volAdj = desiredLevel - mCurrentLevel[i];
	
	/* I want volume adjustments to occur in about 0.1 seconds. 
	/* I want volume adjustments to occur in about 0.05 seconds. 
	 * However, if the input buffer would happen to be longer than
	 * this, I'll just make sure that I am done with the adjustment
	 * by the end of it. */
	int32_t adjLen = mSamplingRate / 10;
	int32_t adjLen = mSamplingRate / 20;
	/* Note: this adjustment should probably be piecewise linear
	 * approximation of an exponential to keep perceptibly linear
	 * correction rate. */
@@ -193,7 +173,7 @@ int32_t EffectCompression::process_effect(audio_buffer_t *in, audio_buffer_t *ou
	 * This biases us against pumping effects and also tends to spare
	 * our ears when some very loud sound begins suddenly. */
	if (volAdj > 0) {
	    volAdj >>= 3;
	    volAdj >>= 4;
	}

	for (uint32_t j = 0; j < in->frameCount; j ++) {
+0 −1
Original line number Diff line number Diff line
@@ -16,6 +16,5 @@ class EffectCompression : public Effect {
    public:
    EffectCompression();
    int32_t command(uint32_t cmdCode, uint32_t cmdSize, void* pCmdData, uint32_t* replySize, void* pReplyData);
    int32_t process(audio_buffer_t *in, audio_buffer_t *out);
    int32_t process_effect(audio_buffer_t *in, audio_buffer_t *out);
};