这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@tomty89
Copy link
Contributor

@tomty89 tomty89 commented Apr 4, 2018

There are several changes in the commit:

  1. Use instance methods to get sample rate and buffer size info
    on Android N or above only instead of Android M, since both
    AudioAttributes.FLAG_LOW_LATENCY (256) and the implicitly used
    AudioFormat.SAMPLE_RATE_UNSPECIFIED (0) are available only since
    API 24 (N).

  2. Use setPerformanceMode() on Android O, as FLAG_LOW_LATENCY is
    deprecated since API 26 (O).

  3. Create AudioTrack instance of both the fast (LOW_LATENCY) and
    deep buffer (POWER_SAVING) mixer path. The two paths can be using
    different subdevices on different rate and buffer size (or same
    subdevice on same rate but different buffer size). For example on
    my phone:

AUDIOTRACK_SAMPLE_RATE: 192000
AUDIOTRACK_BUFFER_SIZE_IN_FRAMES: 23046
AUDIOTRACK_SAMPLE_RATE_LOW_LATENCY: 48000
AUDIOTRACK_BUFFER_SIZE_IN_FRAMES_LOW_LATENCY: 192

  1. Get info on sample rate with the getNativeOutputSampleRate()
    static method (static in Java's sense; the value is still sink-
    based) on builds older than N only. The rate appears to be of the
    fast (LOW_LATENCY) mixer path if it is available.

  2. A note on the static method getMinBufferSize(). The reason it
    is not used even for older devices is, it returns buffer size info
    of the deep buffer (POWER_SAVING) mixer path, while NOSR is the
    rate of the fast (LOW_LATENCY) mixer path, so the value we can get
    with it is not always sensical.

There are several changes in the commit:

1. Use instance methods to get sample rate and buffer size info
on Android N or above only instead of Android M, since both
AudioAttributes.FLAG_LOW_LATENCY (256) and the implicitly used
AudioFormat.SAMPLE_RATE_UNSPECIFIED (0) are available only since
API 24 (N).

2. Use setPerformanceMode() on Android O, as FLAG_LOW_LATENCY is
deprecated since API 26 (O).

3. Create AudioTrack instance of both the fast (LOW_LATENCY) and
deep buffer (POWER_SAVING) mixer path. The two paths can be using
different subdevices on different rate and buffer size (or same
subdevice on same rate but different buffer size). For example on
my phone:

AUDIOTRACK_SAMPLE_RATE: 192000
AUDIOTRACK_BUFFER_SIZE_IN_FRAMES: 23046
AUDIOTRACK_SAMPLE_RATE_LOW_LATENCY: 48000
AUDIOTRACK_BUFFER_SIZE_IN_FRAMES_LOW_LATENCY: 192

4. Get info on sample rate with the getNativeOutputSampleRate()
static method (static in Java's sense; the value is still sink-
based) on builds older than N only. The rate appears to be of the
fast (LOW_LATENCY) mixer path if it is available.

5. A note on the static method getMinBufferSize(). The reason it
is not used even for older devices is, it returns buffer size info
of the deep buffer (POWER_SAVING) mixer path, while NOSR is the
rate of the fast (LOW_LATENCY) mixer path, so the value we can get
with it is not always sensical.
@tomty89
Copy link
Contributor Author

tomty89 commented Apr 4, 2018

Build test has been done on Termux:

$ ecj com/
----------
1. WARNING in /data/data/com.termux/files/home/java/com/termux/api/AudioAPI.java (at line 22)
        final boolean bluetootha2dp = am.isBluetoothA2dpOn();
                                         ^^^^^^^^^^^^^^^^^^^
The method isBluetoothA2dpOn() from the type AudioManager is deprecated
----------
2. WARNING in /data/data/com.termux/files/home/java/com/termux/api/AudioAPI.java (at line 23)
        final boolean wiredhs = am.isWiredHeadsetOn();
                                   ^^^^^^^^^^^^^^^^^^
The method isWiredHeadsetOn() from the type AudioManager is deprecated
----------
3. WARNING in /data/data/com.termux/files/home/java/com/termux/api/AudioAPI.java (at line 45)
        int[] flags = {0,AudioAttributes.FLAG_LOW_LATENCY};
                                         ^^^^^^^^^^^^^^^^
The field AudioAttributes.FLAG_LOW_LATENCY is deprecated
----------
4. WARNING in /data/data/com.termux/files/home/java/com/termux/api/AudioAPI.java (at line 57)
        } else if (flag == AudioAttributes.FLAG_LOW_LATENCY) {
                                           ^^^^^^^^^^^^^^^^
The field AudioAttributes.FLAG_LOW_LATENCY is deprecated
----------
4 problems (4 warnings)
$

@fornwall fornwall merged commit 34c6841 into termux:master Apr 6, 2018
@fornwall
Copy link
Member

fornwall commented Apr 6, 2018

Nice! This is now available in the newly released 0.18 version of the Termux:API app, which should be available as an update in Google Play and F-Droid shortly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants