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

Commit 5acbfb02 authored by Robert Wu's avatar Robert Wu Committed by Android (Google) Code Review
Browse files

Merge "Blend MMAP streams for accessibility"

parents c92b66cf d7400830
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