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

Commit 02fec70d authored by Phil Burk's avatar Phil Burk
Browse files

aaudio: set ramp frames based on sample rate

Now it will be the same number of msec at any rate.

Bug: 68804159
Test: write_sine_callback -pl -s60
Test: then change volume. Should be smooth.
Change-Id: I1f375e5a680198d0f8c6c398b22faf8b092e94fd
parent c2c0aabf
Loading
Loading
Loading
Loading
+13 −1
Original line number Diff line number Diff line
@@ -38,6 +38,18 @@ AudioStreamInternalPlay::AudioStreamInternalPlay(AAudioServiceInterface &servic

AudioStreamInternalPlay::~AudioStreamInternalPlay() {}

constexpr int kRampMSec = 10; // time to apply a change in volume

aaudio_result_t AudioStreamInternalPlay::open(const AudioStreamBuilder &builder) {
    aaudio_result_t result = AudioStreamInternal::open(builder);
    if (result == AAUDIO_OK) {
        // Sample rate is constrained to common values by now and should not overflow.
        int32_t numFrames = kRampMSec * getSampleRate() / AAUDIO_MILLIS_PER_SECOND;
        mVolumeRamp.setLengthInFrames(numFrames);
    }
    return result;
}

aaudio_result_t AudioStreamInternalPlay::requestPause()
{
    aaudio_result_t result = stopCallback();
@@ -45,7 +57,7 @@ aaudio_result_t AudioStreamInternalPlay::requestPause()
        return result;
    }
    if (mServiceStreamHandle == AAUDIO_HANDLE_INVALID) {
        ALOGE("AudioStreamInternal::requestPauseInternal() mServiceStreamHandle invalid = 0x%08X",
        ALOGE("requestPauseInternal() mServiceStreamHandle invalid = 0x%08X",
              mServiceStreamHandle);
        return AAUDIO_ERROR_INVALID_STATE;
    }
+2 −0
Original line number Diff line number Diff line
@@ -33,6 +33,8 @@ public:
    AudioStreamInternalPlay(AAudioServiceInterface  &serviceInterface, bool inService = false);
    virtual ~AudioStreamInternalPlay();

    aaudio_result_t open(const AudioStreamBuilder &builder) override;

    aaudio_result_t requestPause() override;

    aaudio_result_t requestFlush() override;