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

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

AAudio: Fix channel rate conversion in flowgraph

In ag/23541584, we added sample rate conversion. However, we introduced
two bugs in regards to channel count.

1. The flowgraph uses the sink channel count instead of the source.
2. getBytesPerDeviceFrame() doesn't use the device channel count.

This CL fixes both issues.

Bug: 292246705
Bug: 219533889
Test: Test Output in OboeTester with a variety of CHs, SRs, FMTs
Test: OboeTester Data Paths test
Change-Id: I74fe810c450bdd03d2765dc5ba9857ba5d03bf97
parent 6b62dd42
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -89,9 +89,9 @@ aaudio_result_t AAudioFlowGraph::configure(audio_format_t sourceFormat,
    }

    if (sourceSampleRate != sinkSampleRate) {
        mResampler.reset(aaudio::resampler::MultiChannelResampler::make(sinkChannelCount,
        mResampler.reset(aaudio::resampler::MultiChannelResampler::make(sourceChannelCount,
                sourceSampleRate, sinkSampleRate, resamplerQuality));
        mRateConverter = std::make_unique<SampleRateConverter>(sinkChannelCount,
        mRateConverter = std::make_unique<SampleRateConverter>(sourceChannelCount,
                                                               *mResampler);
        lastOutput->connect(&mRateConverter->input);
        lastOutput = &mRateConverter->output;
+1 −4
Original line number Diff line number Diff line
@@ -134,8 +134,6 @@ aaudio_result_t AudioStreamInternal::open(const AudioStreamBuilder &builder) {

    request.getConfiguration().setBufferCapacity(builder.getBufferCapacity());

    mDeviceChannelCount = getSamplesPerFrame(); // Assume it will be the same. Update if not.

    mServiceStreamHandleInfo = mServiceInterface.openStream(request, configurationOutput);
    if (getServiceHandle() < 0
            && (request.getConfiguration().getSamplesPerFrame() == 1
@@ -179,8 +177,6 @@ aaudio_result_t AudioStreamInternal::open(const AudioStreamBuilder &builder) {
        setChannelMask(configurationOutput.getChannelMask());
    }

    mDeviceChannelCount = configurationOutput.getSamplesPerFrame();

    setDeviceId(configurationOutput.getDeviceId());
    setSessionId(configurationOutput.getSessionId());
    setSharingMode(configurationOutput.getSharingMode());
@@ -205,6 +201,7 @@ aaudio_result_t AudioStreamInternal::open(const AudioStreamBuilder &builder) {

    // Save device format so we can do format conversion and volume scaling together.
    setDeviceFormat(configurationOutput.getFormat());
    setDeviceSamplesPerFrame(configurationOutput.getSamplesPerFrame());

    setHardwareSamplesPerFrame(configurationOutput.getHardwareSamplesPerFrame());
    setHardwareSampleRate(configurationOutput.getHardwareSampleRate());
+0 −6
Original line number Diff line number Diff line
@@ -138,8 +138,6 @@ protected:
    // Calculate timeout for an operation involving framesPerOperation.
    int64_t calculateReasonableTimeout(int32_t framesPerOperation);

    int32_t getDeviceChannelCount() const { return mDeviceChannelCount; }

    /**
     * @return true if running in audio service, versus in app process
     */
@@ -213,10 +211,6 @@ private:

    int64_t                  mServiceLatencyNanos = 0;

    // Sometimes the hardware is operating with a different channel count from the app.
    // Then we require conversion in AAudio.
    int32_t                  mDeviceChannelCount = 0;

    int32_t                  mBufferSizeInFrames = 0; // local threshold to control latency
    int32_t                  mDeviceBufferSizeInFrames = 0;
    int32_t                  mBufferCapacityInFrames = 0;
+1 −1
Original line number Diff line number Diff line
@@ -51,7 +51,7 @@ aaudio_result_t AudioStreamInternalCapture::open(const AudioStreamBuilder &build
    aaudio_result_t result = AudioStreamInternal::open(builder);
    if (result == AAUDIO_OK) {
        result = mFlowGraph.configure(getDeviceFormat(),
                             getDeviceChannelCount(),
                             getDeviceSamplesPerFrame(),
                             getDeviceSampleRate(),
                             getFormat(),
                             getSamplesPerFrame(),
+1 −1
Original line number Diff line number Diff line
@@ -54,7 +54,7 @@ aaudio_result_t AudioStreamInternalPlay::open(const AudioStreamBuilder &builder)
                             getSamplesPerFrame(),
                             getSampleRate(),
                             getDeviceFormat(),
                             getDeviceChannelCount(),
                             getDeviceSamplesPerFrame(),
                             getDeviceSampleRate(),
                             getRequireMonoBlend(),
                             useVolumeRamps,
Loading