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

Commit f64e4631 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Sync AAudio flowgraph with Oboe"

parents 9c6b3d36 057f083d
Loading
Loading
Loading
Loading
+13 −1
Original line number Diff line number Diff line
@@ -207,10 +207,14 @@ cc_library {
        "binding/RingBufferParcelable.cpp",
        "binding/SharedMemoryParcelable.cpp",
        "binding/SharedRegionParcelable.cpp",
        "flowgraph/AudioProcessorBase.cpp",
        "flowgraph/ChannelCountConverter.cpp",
        "flowgraph/ClipToRange.cpp",
        "flowgraph/FlowGraphNode.cpp",
        "flowgraph/ManyToMultiConverter.cpp",
        "flowgraph/MonoToMultiConverter.cpp",
        "flowgraph/MultiToMonoConverter.cpp",
        "flowgraph/RampLinear.cpp",
        "flowgraph/SampleRateConverter.cpp",
        "flowgraph/SinkFloat.cpp",
        "flowgraph/SinkI16.cpp",
        "flowgraph/SinkI24.cpp",
@@ -219,6 +223,14 @@ cc_library {
        "flowgraph/SourceI16.cpp",
        "flowgraph/SourceI24.cpp",
        "flowgraph/SourceI32.cpp",
        "flowgraph/resampler/IntegerRatio.cpp",
        "flowgraph/resampler/LinearResampler.cpp",
        "flowgraph/resampler/MultiChannelResampler.cpp",
        "flowgraph/resampler/PolyphaseResampler.cpp",
        "flowgraph/resampler/PolyphaseResamplerMono.cpp",
        "flowgraph/resampler/PolyphaseResamplerStereo.cpp",
        "flowgraph/resampler/SincResampler.cpp",
        "flowgraph/resampler/SincResamplerStereo.cpp",
    ],
    sanitize: {
        integer_overflow: true,
+1 −1
Original line number Diff line number Diff line
@@ -38,7 +38,7 @@ aaudio_result_t AAudioFlowGraph::configure(audio_format_t sourceFormat,
                          int32_t sourceChannelCount,
                          audio_format_t sinkFormat,
                          int32_t sinkChannelCount) {
    AudioFloatOutputPort *lastOutput = nullptr;
    FlowGraphPortFloatOutput *lastOutput = nullptr;

    // TODO change back to ALOGD
    ALOGI("%s() source format = 0x%08x, channels = %d, sink format = 0x%08x, channels = %d",
+5 −5
Original line number Diff line number Diff line
@@ -53,11 +53,11 @@ public:
    void setRampLengthInFrames(int32_t numFrames);

private:
    std::unique_ptr<flowgraph::AudioSource>          mSource;
    std::unique_ptr<flowgraph::FlowGraphSourceBuffered>     mSource;
    std::unique_ptr<flowgraph::RampLinear>                  mVolumeRamp;
    std::unique_ptr<flowgraph::ClipToRange>                 mClipper;
    std::unique_ptr<flowgraph::MonoToMultiConverter>        mChannelConverter;
    std::unique_ptr<flowgraph::AudioSink>            mSink;
    std::unique_ptr<flowgraph::FlowGraphSink>               mSink;
};


+52 −0
Original line number Diff line number Diff line
/*
 * Copyright 2015 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <unistd.h>
#include "FlowGraphNode.h"
#include "ChannelCountConverter.h"

using namespace flowgraph;

ChannelCountConverter::ChannelCountConverter(
        int32_t inputChannelCount,
        int32_t outputChannelCount)
        : input(*this, inputChannelCount)
        , output(*this, outputChannelCount) {
}

ChannelCountConverter::~ChannelCountConverter() = default;

int32_t ChannelCountConverter::onProcess(int32_t numFrames) {
    const float *inputBuffer = input.getBuffer();
    float *outputBuffer = output.getBuffer();
    int32_t inputChannelCount = input.getSamplesPerFrame();
    int32_t outputChannelCount = output.getSamplesPerFrame();
    for (int i = 0; i < numFrames; i++) {
        int inputChannel = 0;
        for (int outputChannel = 0; outputChannel < outputChannelCount; outputChannel++) {
            // Copy input channels to output channels.
            // Wrap if we run out of inputs.
            // Discard if we run out of outputs.
            outputBuffer[outputChannel] = inputBuffer[inputChannel];
            inputChannel = (inputChannel == inputChannelCount)
                    ? 0 : inputChannel + 1;
        }
        inputBuffer += inputChannelCount;
        outputBuffer += outputChannelCount;
    }
    return numFrames;
}
+52 −0
Original line number Diff line number Diff line
/*
 * Copyright 2015 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef FLOWGRAPH_CHANNEL_COUNT_CONVERTER_H
#define FLOWGRAPH_CHANNEL_COUNT_CONVERTER_H

#include <unistd.h>
#include <sys/types.h>

#include "FlowGraphNode.h"

namespace flowgraph {

/**
 * Change the number of number of channels without mixing.
 * When increasing the channel count, duplicate input channels.
 * When decreasing the channel count, drop input channels.
 */
    class ChannelCountConverter : public FlowGraphNode {
    public:
        explicit ChannelCountConverter(
                int32_t inputChannelCount,
                int32_t outputChannelCount);

        virtual ~ChannelCountConverter();

        int32_t onProcess(int32_t numFrames) override;

        const char *getName() override {
            return "ChannelCountConverter";
        }

        FlowGraphPortFloatInput input;
        FlowGraphPortFloatOutput output;
    };

} /* namespace flowgraph */

#endif //FLOWGRAPH_CHANNEL_COUNT_CONVERTER_H
Loading