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

Commit 04e805b0 authored by Phil Burk's avatar Phil Burk
Browse files

aaudio: add support for 24 and 32 bit PCM

Add new formats: AAUDIO_FORMAT_PCM_I24_PACKED
and AAUDIO_FORMAT_PCM_I32.

Pass formats to Legacy AudioTrack and AuddioRecord.

Request 24_PACKED in AAudio Service for MMAP streams.
Also add a flowgraph module for converting the I32 data
to/from FLOAT.

Bug:  65067568
Bug: 157671580

Test: To determine which format the MMAP path is using for the DSP,
Test: adb shell dumpsys media.aaudio
Test: then look for the "Exclusive MMAP Endpoints" and "Format:".
Test: The formats listed are the internal AudioFlinger formats:
Test:    1=16_BIT, 3=32_BIT, 4=8_24_BIT, 5=FLOAT, 6=24_BIT_PACKED

Test: atest AAudioTestCases
Test: adb shell write_sine_callback -? # to list new formats
Test: adb shell write_sine_callback -pl -f3 # MMAP LOWLAT I24_PACKED
Test: adb shell write_sine_callback -pl -f4 # MMAP LOWLAT I32
Test: # Legacy LOWLAT I24_PACKED
Test: adb shell write_sine_callback -pl -f3 -m1
Test: adb shell write_sine_callback -pl -f4 -m1 # Legacy LOWLAT I32
Test: adb shell write_sine_callback -pn -f3 # Legacy I24_PACKED
Test: adb shell write_sine_callback -pn -f4 # Legacy I32
Change-Id: Ibe13bfd54425d110f50f89eb10c63872a2f99839
parent bb29fdf9
Loading
Loading
Loading
Loading
+26 −2
Original line number Diff line number Diff line
@@ -65,7 +65,7 @@ enum {

    /**
     * This format uses the int16_t data type.
     * The maximum range of the data is -32768 to 32767.
     * The maximum range of the data is -32768 (0x8000) to 32767 (0x7FFF).
     */
    AAUDIO_FORMAT_PCM_I16,

@@ -77,7 +77,31 @@ enum {
     * See also 'floatData' at
     * https://developer.android.com/reference/android/media/AudioTrack#write(float[],%20int,%20int,%20int)
     */
    AAUDIO_FORMAT_PCM_FLOAT
    AAUDIO_FORMAT_PCM_FLOAT,

    /**
     * This format uses 24-bit samples packed into 3 bytes.
     * The bytes are in the native endian order.
     * The maximum range of the data is -8388608 (0x800000)
     * to 8388607 (0x7FFFFF).
     *
     * Note that the lower precision bits may be ignored by the device.
     *
     * Available since API level 31.
     */
    AAUDIO_FORMAT_PCM_I24_PACKED,

    /**
     * This format uses 32-bit samples stored in an int32_t data type.
     * The maximum range of the data is -2147483648 (0x80000000)
     * to 2147483647 (0x7FFFFFFF).
     *
     * Note that the lower precision bits may be ignored by the device.
     *
     * Available since API level 31.
     */
    AAUDIO_FORMAT_PCM_I32

};
typedef int32_t aaudio_format_t;

+2 −0
Original line number Diff line number Diff line
@@ -130,9 +130,11 @@ cc_library {
        "flowgraph/SinkFloat.cpp",
        "flowgraph/SinkI16.cpp",
        "flowgraph/SinkI24.cpp",
        "flowgraph/SinkI32.cpp",
        "flowgraph/SourceFloat.cpp",
        "flowgraph/SourceI16.cpp",
        "flowgraph/SourceI24.cpp",
        "flowgraph/SourceI32.cpp",
    ],
    sanitize: {
        integer_overflow: true,
+12 −3
Original line number Diff line number Diff line
@@ -26,9 +26,11 @@
#include <flowgraph/SinkFloat.h>
#include <flowgraph/SinkI16.h>
#include <flowgraph/SinkI24.h>
#include <flowgraph/SinkI32.h>
#include <flowgraph/SourceFloat.h>
#include <flowgraph/SourceI16.h>
#include <flowgraph/SourceI24.h>
#include <flowgraph/SourceI32.h>

using namespace flowgraph;

@@ -38,7 +40,8 @@ aaudio_result_t AAudioFlowGraph::configure(audio_format_t sourceFormat,
                          int32_t sinkChannelCount) {
    AudioFloatOutputPort *lastOutput = nullptr;

    ALOGV("%s() source format = 0x%08x, channels = %d, sink format = 0x%08x, channels = %d",
    // TODO change back to ALOGD
    ALOGI("%s() source format = 0x%08x, channels = %d, sink format = 0x%08x, channels = %d",
          __func__, sourceFormat, sourceChannelCount, sinkFormat, sinkChannelCount);

    switch (sourceFormat) {
@@ -51,7 +54,10 @@ aaudio_result_t AAudioFlowGraph::configure(audio_format_t sourceFormat,
        case AUDIO_FORMAT_PCM_24_BIT_PACKED:
            mSource = std::make_unique<SourceI24>(sourceChannelCount);
            break;
        default: // TODO add I32
        case AUDIO_FORMAT_PCM_32_BIT:
            mSource = std::make_unique<SourceI32>(sourceChannelCount);
            break;
        default:
            ALOGE("%s() Unsupported source format = %d", __func__, sourceFormat);
            return AAUDIO_ERROR_UNIMPLEMENTED;
    }
@@ -90,7 +96,10 @@ aaudio_result_t AAudioFlowGraph::configure(audio_format_t sourceFormat,
        case AUDIO_FORMAT_PCM_24_BIT_PACKED:
            mSink = std::make_unique<SinkI24>(sinkChannelCount);
            break;
        default: // TODO add I32
        case AUDIO_FORMAT_PCM_32_BIT:
            mSink = std::make_unique<SinkI32>(sinkChannelCount);
            break;
        default:
            ALOGE("%s() Unsupported sink format = %d", __func__, sinkFormat);
            return AAUDIO_ERROR_UNIMPLEMENTED;
    }
+1 −1
Original line number Diff line number Diff line
@@ -104,7 +104,7 @@ aaudio_result_t AudioStreamInternal::open(const AudioStreamBuilder &builder) {
    if (getFormat() == AUDIO_FORMAT_DEFAULT) {
        setFormat(AUDIO_FORMAT_PCM_FLOAT);
    }
    // Request FLOAT for the shared mixer.
    // Request FLOAT for the shared mixer or the device.
    request.getConfiguration().setFormat(AUDIO_FORMAT_PCM_FLOAT);

    // Build the request to send to the server.
+2 −0
Original line number Diff line number Diff line
@@ -54,7 +54,9 @@ static aaudio_result_t isFormatValid(audio_format_t format) {
    switch (format) {
        case AUDIO_FORMAT_DEFAULT:
        case AUDIO_FORMAT_PCM_16_BIT:
        case AUDIO_FORMAT_PCM_32_BIT:
        case AUDIO_FORMAT_PCM_FLOAT:
        case AUDIO_FORMAT_PCM_24_BIT_PACKED:
            break; // valid
        default:
            ALOGD("audioFormat not valid, audio_format_t = 0x%08x", format);
Loading