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

Commit 463a8c77 authored by Andy Hung's avatar Andy Hung
Browse files

Add getFormat to AudioTrack and AudioRecord

This enables getting channel index masks and is future-friendly.

Change-Id: Ia0bb9a855e97e8279b2226cf75e0ddd03af3fb7f
parent f1a38a59
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -14925,6 +14925,7 @@ package android.media {
    method public int getAudioSource();
    method public int getChannelConfiguration();
    method public int getChannelCount();
    method public android.media.AudioFormat getFormat();
    method public static int getMinBufferSize(int, int, int);
    method public int getNativeFrameCount() throws java.lang.IllegalStateException;
    method public int getNotificationMarkerPosition();
@@ -14988,6 +14989,7 @@ package android.media {
    method public int getAudioSessionId();
    method public int getChannelConfiguration();
    method public int getChannelCount();
    method public android.media.AudioFormat getFormat();
    method public static float getMaxVolume();
    method public static int getMinBufferSize(int, int, int);
    method public static float getMinVolume();
+2 −0
Original line number Diff line number Diff line
@@ -16135,6 +16135,7 @@ package android.media {
    method public int getAudioSource();
    method public int getChannelConfiguration();
    method public int getChannelCount();
    method public android.media.AudioFormat getFormat();
    method public static int getMinBufferSize(int, int, int);
    method public int getNativeFrameCount() throws java.lang.IllegalStateException;
    method public int getNotificationMarkerPosition();
@@ -16200,6 +16201,7 @@ package android.media {
    method public int getAudioSessionId();
    method public int getChannelConfiguration();
    method public int getChannelCount();
    method public android.media.AudioFormat getFormat();
    method public static float getMaxVolume();
    method public static int getMinBufferSize(int, int, int);
    method public static float getMinVolume();
+25 −3
Original line number Diff line number Diff line
@@ -683,7 +683,7 @@ public class AudioRecord
    }

    /**
     * Returns the configured audio data format. See {@link AudioFormat#ENCODING_PCM_8BIT},
     * Returns the configured audio data encoding. See {@link AudioFormat#ENCODING_PCM_8BIT},
     * {@link AudioFormat#ENCODING_PCM_16BIT}, and {@link AudioFormat#ENCODING_PCM_FLOAT}.
     */
    public int getAudioFormat() {
@@ -691,14 +691,36 @@ public class AudioRecord
    }

    /**
     * Returns the configured channel configuration.
     * See {@link AudioFormat#CHANNEL_IN_MONO}
     * Returns the configured channel position mask.
     * <p> See {@link AudioFormat#CHANNEL_IN_MONO}
     * and {@link AudioFormat#CHANNEL_IN_STEREO}.
     * This method may return {@link AudioFormat#CHANNEL_INVALID} if
     * a channel index mask is used.
     * Consider {@link #getFormat()} instead, to obtain an {@link AudioFormat},
     * which contains both the channel position mask and the channel index mask.
     */
    public int getChannelConfiguration() {
        return mChannelMask;
    }

    /**
     * Returns the configured <code>AudioRecord</code> format.
     * @return an {@link AudioFormat} containing the
     * <code>AudioRecord</code> parameters at the time of configuration.
     */
    public @NonNull AudioFormat getFormat() {
        AudioFormat.Builder builder = new AudioFormat.Builder()
            .setSampleRate(mSampleRate)
            .setEncoding(mAudioFormat);
        if (mChannelMask != AudioFormat.CHANNEL_INVALID) {
            builder.setChannelMask(mChannelMask);
        }
        if (mChannelIndexMask != AudioFormat.CHANNEL_INVALID  /* 0 */) {
            builder.setChannelIndexMask(mChannelIndexMask);
        }
        return builder.build();
    }

    /**
     * Returns the configured number of channels.
     */
+25 −3
Original line number Diff line number Diff line
@@ -970,8 +970,8 @@ public class AudioTrack
    }

    /**
     * Returns the configured audio data format. See {@link AudioFormat#ENCODING_PCM_16BIT}
     * and {@link AudioFormat#ENCODING_PCM_8BIT}.
     * Returns the configured audio data encoding. See {@link AudioFormat#ENCODING_PCM_8BIT},
     * {@link AudioFormat#ENCODING_PCM_16BIT}, and {@link AudioFormat#ENCODING_PCM_FLOAT}.
     */
    public int getAudioFormat() {
        return mAudioFormat;
@@ -990,13 +990,35 @@ public class AudioTrack

    /**
     * Returns the configured channel position mask.
     * For example, refer to {@link AudioFormat#CHANNEL_OUT_MONO},
     * <p> For example, refer to {@link AudioFormat#CHANNEL_OUT_MONO},
     * {@link AudioFormat#CHANNEL_OUT_STEREO}, {@link AudioFormat#CHANNEL_OUT_5POINT1}.
     * This method may return {@link AudioFormat#CHANNEL_INVALID} if
     * a channel index mask is used. Consider
     * {@link #getFormat()} instead, to obtain an {@link AudioFormat},
     * which contains both the channel position mask and the channel index mask.
     */
    public int getChannelConfiguration() {
        return mChannelConfiguration;
    }

    /**
     * Returns the configured <code>AudioTrack</code> format.
     * @return an {@link AudioFormat} containing the
     * <code>AudioTrack</code> parameters at the time of configuration.
     */
    public @NonNull AudioFormat getFormat() {
        AudioFormat.Builder builder = new AudioFormat.Builder()
            .setSampleRate(mSampleRate)
            .setEncoding(mAudioFormat);
        if (mChannelConfiguration != AudioFormat.CHANNEL_INVALID) {
            builder.setChannelMask(mChannelConfiguration);
        }
        if (mChannelIndexMask != AudioFormat.CHANNEL_INVALID /* 0 */) {
            builder.setChannelIndexMask(mChannelIndexMask);
        }
        return builder.build();
    }

    /**
     * Returns the configured number of channels.
     */