|
@@ -29,7 +29,7 @@ public class SDLAudioManager {
|
|
|
mAudioRecord = null;
|
|
|
mAudioDeviceCallback = null;
|
|
|
|
|
|
- if(Build.VERSION.SDK_INT >= 24)
|
|
|
+ if(Build.VERSION.SDK_INT >= 24 /* Android 7.0 (N) */)
|
|
|
{
|
|
|
mAudioDeviceCallback = new AudioDeviceCallback() {
|
|
|
@Override
|
|
@@ -79,14 +79,14 @@ public class SDLAudioManager {
|
|
|
Log.v(TAG, "Opening " + (isCapture ? "capture" : "playback") + ", requested " + desiredFrames + " frames of " + desiredChannels + " channel " + getAudioFormatString(audioFormat) + " audio at " + sampleRate + " Hz");
|
|
|
|
|
|
/* On older devices let's use known good settings */
|
|
|
- if (Build.VERSION.SDK_INT < 21) {
|
|
|
+ if (Build.VERSION.SDK_INT < 21 /* Android 5.0 (LOLLIPOP) */) {
|
|
|
if (desiredChannels > 2) {
|
|
|
desiredChannels = 2;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/* AudioTrack has sample rate limitation of 48000 (fixed in 5.0.2) */
|
|
|
- if (Build.VERSION.SDK_INT < 22) {
|
|
|
+ if (Build.VERSION.SDK_INT < 22 /* Android 5.1 (LOLLIPOP_MR1) */) {
|
|
|
if (sampleRate < 8000) {
|
|
|
sampleRate = 8000;
|
|
|
} else if (sampleRate > 48000) {
|
|
@@ -95,7 +95,7 @@ public class SDLAudioManager {
|
|
|
}
|
|
|
|
|
|
if (audioFormat == AudioFormat.ENCODING_PCM_FLOAT) {
|
|
|
- int minSDKVersion = (isCapture ? 23 : 21);
|
|
|
+ int minSDKVersion = (isCapture ? 23 /* Android 6.0 (M) */ : 21 /* Android 5.0 (LOLLIPOP) */);
|
|
|
if (Build.VERSION.SDK_INT < minSDKVersion) {
|
|
|
audioFormat = AudioFormat.ENCODING_PCM_16BIT;
|
|
|
}
|
|
@@ -156,7 +156,7 @@ public class SDLAudioManager {
|
|
|
channelConfig = AudioFormat.CHANNEL_OUT_5POINT1 | AudioFormat.CHANNEL_OUT_BACK_CENTER;
|
|
|
break;
|
|
|
case 8:
|
|
|
- if (Build.VERSION.SDK_INT >= 23) {
|
|
|
+ if (Build.VERSION.SDK_INT >= 23 /* Android 6.0 (M) */) {
|
|
|
channelConfig = AudioFormat.CHANNEL_OUT_7POINT1_SURROUND;
|
|
|
} else {
|
|
|
Log.v(TAG, "Requested " + desiredChannels + " channels, getting 5.1 surround");
|
|
@@ -237,7 +237,7 @@ public class SDLAudioManager {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
- if (Build.VERSION.SDK_INT >= 24 && deviceId != 0) {
|
|
|
+ if (Build.VERSION.SDK_INT >= 24 /* Android 7.0 (N) */ && deviceId != 0) {
|
|
|
mAudioRecord.setPreferredDevice(getOutputAudioDeviceInfo(deviceId));
|
|
|
}
|
|
|
|
|
@@ -264,7 +264,7 @@ public class SDLAudioManager {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
- if (Build.VERSION.SDK_INT >= 24 && deviceId != 0) {
|
|
|
+ if (Build.VERSION.SDK_INT >= 24 /* Android 7.0 (N) */ && deviceId != 0) {
|
|
|
mAudioTrack.setPreferredDevice(getInputAudioDeviceInfo(deviceId));
|
|
|
}
|
|
|
|
|
@@ -283,7 +283,7 @@ public class SDLAudioManager {
|
|
|
}
|
|
|
|
|
|
private static AudioDeviceInfo getInputAudioDeviceInfo(int deviceId) {
|
|
|
- if (Build.VERSION.SDK_INT >= 24) {
|
|
|
+ if (Build.VERSION.SDK_INT >= 24 /* Android 7.0 (N) */) {
|
|
|
AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
|
|
|
return Arrays.stream(audioManager.getDevices(AudioManager.GET_DEVICES_INPUTS))
|
|
|
.filter(deviceInfo -> deviceInfo.getId() == deviceId)
|
|
@@ -295,7 +295,7 @@ public class SDLAudioManager {
|
|
|
}
|
|
|
|
|
|
private static AudioDeviceInfo getOutputAudioDeviceInfo(int deviceId) {
|
|
|
- if (Build.VERSION.SDK_INT >= 24) {
|
|
|
+ if (Build.VERSION.SDK_INT >= 24 /* Android 7.0 (N) */) {
|
|
|
AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
|
|
|
return Arrays.stream(audioManager.getDevices(AudioManager.GET_DEVICES_OUTPUTS))
|
|
|
.filter(deviceInfo -> deviceInfo.getId() == deviceId)
|
|
@@ -307,14 +307,14 @@ public class SDLAudioManager {
|
|
|
}
|
|
|
|
|
|
private static void registerAudioDeviceCallback() {
|
|
|
- if (Build.VERSION.SDK_INT >= 24) {
|
|
|
+ if (Build.VERSION.SDK_INT >= 24 /* Android 7.0 (N) */) {
|
|
|
AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
|
|
|
audioManager.registerAudioDeviceCallback(mAudioDeviceCallback, null);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private static void unregisterAudioDeviceCallback(Context context) {
|
|
|
- if (Build.VERSION.SDK_INT >= 24) {
|
|
|
+ if (Build.VERSION.SDK_INT >= 24 /* Android 7.0 (N) */) {
|
|
|
AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
|
|
|
audioManager.unregisterAudioDeviceCallback(mAudioDeviceCallback);
|
|
|
}
|
|
@@ -324,7 +324,7 @@ public class SDLAudioManager {
|
|
|
* This method is called by SDL using JNI.
|
|
|
*/
|
|
|
public static int[] getAudioOutputDevices() {
|
|
|
- if (Build.VERSION.SDK_INT >= 24) {
|
|
|
+ if (Build.VERSION.SDK_INT >= 24 /* Android 7.0 (N) */) {
|
|
|
AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
|
|
|
return Arrays.stream(audioManager.getDevices(AudioManager.GET_DEVICES_OUTPUTS)).mapToInt(AudioDeviceInfo::getId).toArray();
|
|
|
} else {
|
|
@@ -336,7 +336,7 @@ public class SDLAudioManager {
|
|
|
* This method is called by SDL using JNI.
|
|
|
*/
|
|
|
public static int[] getAudioInputDevices() {
|
|
|
- if (Build.VERSION.SDK_INT >= 24) {
|
|
|
+ if (Build.VERSION.SDK_INT >= 24 /* Android 7.0 (N) */) {
|
|
|
AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
|
|
|
return Arrays.stream(audioManager.getDevices(AudioManager.GET_DEVICES_INPUTS)).mapToInt(AudioDeviceInfo::getId).toArray();
|
|
|
} else {
|
|
@@ -360,7 +360,7 @@ public class SDLAudioManager {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- if (android.os.Build.VERSION.SDK_INT < 21) {
|
|
|
+ if (android.os.Build.VERSION.SDK_INT < 21 /* Android 5.0 (LOLLIPOP) */) {
|
|
|
Log.e(TAG, "Attempted to make an incompatible audio call with uninitialized audio! (floating-point output is supported since Android 5.0 Lollipop)");
|
|
|
return;
|
|
|
}
|
|
@@ -443,7 +443,7 @@ public class SDLAudioManager {
|
|
|
|
|
|
/** This method is called by SDL using JNI. */
|
|
|
public static int captureReadFloatBuffer(float[] buffer, boolean blocking) {
|
|
|
- if (Build.VERSION.SDK_INT < 23) {
|
|
|
+ if (Build.VERSION.SDK_INT < 23 /* Android 6.0 (M) */) {
|
|
|
return 0;
|
|
|
} else {
|
|
|
return mAudioRecord.read(buffer, 0, buffer.length, blocking ? AudioRecord.READ_BLOCKING : AudioRecord.READ_NON_BLOCKING);
|
|
@@ -452,7 +452,7 @@ public class SDLAudioManager {
|
|
|
|
|
|
/** This method is called by SDL using JNI. */
|
|
|
public static int captureReadShortBuffer(short[] buffer, boolean blocking) {
|
|
|
- if (Build.VERSION.SDK_INT < 23) {
|
|
|
+ if (Build.VERSION.SDK_INT < 23 /* Android 6.0 (M) */) {
|
|
|
return mAudioRecord.read(buffer, 0, buffer.length);
|
|
|
} else {
|
|
|
return mAudioRecord.read(buffer, 0, buffer.length, blocking ? AudioRecord.READ_BLOCKING : AudioRecord.READ_NON_BLOCKING);
|
|
@@ -461,7 +461,7 @@ public class SDLAudioManager {
|
|
|
|
|
|
/** This method is called by SDL using JNI. */
|
|
|
public static int captureReadByteBuffer(byte[] buffer, boolean blocking) {
|
|
|
- if (Build.VERSION.SDK_INT < 23) {
|
|
|
+ if (Build.VERSION.SDK_INT < 23 /* Android 6.0 (M) */) {
|
|
|
return mAudioRecord.read(buffer, 0, buffer.length);
|
|
|
} else {
|
|
|
return mAudioRecord.read(buffer, 0, buffer.length, blocking ? AudioRecord.READ_BLOCKING : AudioRecord.READ_NON_BLOCKING);
|