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

Commit d7400830 authored by Robert Wu's avatar Robert Wu
Browse files

Blend MMAP streams for accessibility

There is an accessibility feature called Mono audio. This feature
allows stereo audio to be blended into mono audio.

Currently, this feature works perfectly in most scenarios. However,
this feature is not used when MMAP is enabled. This cl fixes MMAP
scenarios.

Bug: 69635707
Test: Tested on Bramble and MMAP through the following six scenarios:
1. MMAP Exclusive Mono Audio Enabled
2. MMAP Shared Mono Audio Enabled
3. No MMAP Mono Audio Enabled
4. MMAP Exclusive Mono Audio Disabled
5. MMAP Shared Mono Audio Disabled
6. No MMAP Mono Audio Disabled
You can enable Mono Audio from Settings -> Accessibility -> Audio
adjustment -> Mono audio
With OboeTester playing a different frequency on each ear, this seems
to work as expected.
atest test_flowgraph

Change-Id: I2688f06cc8c6ef0f2965845e65e2582f3cc9788e
parent 057f083d
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -211,6 +211,7 @@ cc_library {
        "flowgraph/ClipToRange.cpp",
        "flowgraph/FlowGraphNode.cpp",
        "flowgraph/ManyToMultiConverter.cpp",
        "flowgraph/MonoBlend.cpp",
        "flowgraph/MonoToMultiConverter.cpp",
        "flowgraph/MultiToMonoConverter.cpp",
        "flowgraph/RampLinear.cpp",
+9 −1
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@
#include "AAudioFlowGraph.h"

#include <flowgraph/ClipToRange.h>
#include <flowgraph/MonoBlend.h>
#include <flowgraph/MonoToMultiConverter.h>
#include <flowgraph/RampLinear.h>
#include <flowgraph/SinkFloat.h>
@@ -37,7 +38,8 @@ using namespace flowgraph;
aaudio_result_t AAudioFlowGraph::configure(audio_format_t sourceFormat,
                          int32_t sourceChannelCount,
                          audio_format_t sinkFormat,
                          int32_t sinkChannelCount) {
                          int32_t sinkChannelCount,
                          bool useMonoBlend) {
    FlowGraphPortFloatOutput *lastOutput = nullptr;

    // TODO change back to ALOGD
@@ -76,6 +78,12 @@ aaudio_result_t AAudioFlowGraph::configure(audio_format_t sourceFormat,
        lastOutput = &mClipper->output;
    }

    if (useMonoBlend) {
        mMonoBlend = std::make_unique<MonoBlend>(sourceChannelCount);
        lastOutput->connect(&mMonoBlend->input);
        lastOutput = &mMonoBlend->output;
    }

    // Expand the number of channels if required.
    if (sourceChannelCount == 1 && sinkChannelCount > 1) {
        mChannelConverter = std::make_unique<MonoToMultiConverter>(sinkChannelCount);
+4 −1
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@

#include <aaudio/AAudio.h>
#include <flowgraph/ClipToRange.h>
#include <flowgraph/MonoBlend.h>
#include <flowgraph/MonoToMultiConverter.h>
#include <flowgraph/RampLinear.h>

@@ -41,7 +42,8 @@ public:
    aaudio_result_t configure(audio_format_t sourceFormat,
                              int32_t sourceChannelCount,
                              audio_format_t sinkFormat,
                              int32_t sinkChannelCount);
                              int32_t sinkChannelCount,
                              bool useMonoBlend);

    void process(const void *source, void *destination, int32_t numFrames);

@@ -54,6 +56,7 @@ public:

private:
    std::unique_ptr<flowgraph::FlowGraphSourceBuffered>     mSource;
    std::unique_ptr<flowgraph::MonoBlend>                   mMonoBlend;
    std::unique_ptr<flowgraph::RampLinear>                  mVolumeRamp;
    std::unique_ptr<flowgraph::ClipToRange>                 mClipper;
    std::unique_ptr<flowgraph::MonoToMultiConverter>        mChannelConverter;
+10 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@
#include <aaudio/AAudio.h>
#include <cutils/properties.h>

#include <media/AudioParameter.h>
#include <media/AudioSystem.h>
#include <media/MediaMetricsItem.h>
#include <utils/Trace.h>
@@ -270,6 +271,15 @@ aaudio_result_t AudioStreamInternal::open(const AudioStreamBuilder &builder) {
        mCallbackBuffer = std::make_unique<uint8_t[]>(callbackBufferSize);
    }

    // Exclusive output streams should combine channels when mono audio adjustment
    // is enabled.
    if ((getDirection() == AAUDIO_DIRECTION_OUTPUT) &&
        (getSharingMode() == AAUDIO_SHARING_MODE_EXCLUSIVE)) {
        bool isMasterMono = false;
        android::AudioSystem::getMasterMono(&isMasterMono);
        setRequireMonoBlend(isMasterMono);
    }

    // For debugging and analyzing the distribution of MMAP timestamps.
    // For OUTPUT, use a NEGATIVE offset to move the CPU writes further BEFORE the HW reads.
    // For INPUT, use a POSITIVE offset to move the CPU reads further AFTER the HW writes.
+2 −1
Original line number Diff line number Diff line
@@ -52,7 +52,8 @@ aaudio_result_t AudioStreamInternalPlay::open(const AudioStreamBuilder &builder)
        result = mFlowGraph.configure(getFormat(),
                             getSamplesPerFrame(),
                             getDeviceFormat(),
                             getDeviceChannelCount());
                             getDeviceChannelCount(),
                             getRequireMonoBlend());

        if (result != AAUDIO_OK) {
            safeReleaseClose();
Loading