Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add channel mask support for API 32. #1548

Merged
merged 4 commits into from
Jun 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions apps/OboeTester/app/src/main/cpp/NativeAudioContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ void ActivityContext::configureBuilder(bool isInput, oboe::AudioStreamBuilder &b
int ActivityContext::open(jint nativeApi,
jint sampleRate,
jint channelCount,
jint channelMask,
jint format,
jint sharingMode,
jint performanceMode,
Expand Down Expand Up @@ -199,6 +200,10 @@ int ActivityContext::open(jint nativeApi,
->setFormatConversionAllowed(formatConversionAllowed)
->setSampleRateConversionQuality((oboe::SampleRateConversionQuality) rateConversionQuality)
;
if (channelMask != (jint) oboe::ChannelMask::Unspecified) {
// Set channel mask when it is specified.
builder.setChannelMask((oboe::ChannelMask) channelMask);
}
if (mUseCallback) {
builder.setFramesPerCallback(callbackSize);
}
Expand Down
4 changes: 3 additions & 1 deletion apps/OboeTester/app/src/main/cpp/NativeAudioContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
#define NATIVE_MODE_OPENSLES 1
#define NATIVE_MODE_AAUDIO 2

#define MAX_SINE_OSCILLATORS 8
#define MAX_SINE_OSCILLATORS 16
#define AMPLITUDE_SINE 1.0
#define AMPLITUDE_SAWTOOTH 0.5
#define FREQUENCY_SAW_PING 800.0
Expand Down Expand Up @@ -97,6 +97,7 @@ class ActivityContext {
* @param nativeApi
* @param sampleRate
* @param channelCount
* @param channelMask
* @param format
* @param sharingMode
* @param performanceMode
Expand All @@ -114,6 +115,7 @@ class ActivityContext {
int open(jint nativeApi,
jint sampleRate,
jint channelCount,
jint channelMask,
jint format,
jint sharingMode,
jint performanceMode,
Expand Down
14 changes: 14 additions & 0 deletions apps/OboeTester/app/src/main/cpp/jni-bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Java_com_mobileer_oboetester_OboeAudioStream_openNative(JNIEnv *env, jobject,
jint nativeApi,
jint sampleRate,
jint channelCount,
jint channelMask,
jint format,
jint sharingMode,
jint performanceMode,
Expand Down Expand Up @@ -117,6 +118,7 @@ Java_com_mobileer_oboetester_OboeAudioStream_openNative(
jint nativeApi,
jint sampleRate,
jint channelCount,
jint channelMask,
jint format,
jint sharingMode,
jint performanceMode,
Expand All @@ -136,6 +138,7 @@ Java_com_mobileer_oboetester_OboeAudioStream_openNative(
return (jint) engine.getCurrentActivity()->open(nativeApi,
sampleRate,
channelCount,
channelMask,
format,
sharingMode,
performanceMode,
Expand Down Expand Up @@ -309,6 +312,17 @@ Java_com_mobileer_oboetester_OboeAudioStream_getChannelCount(
return result;
}

JNIEXPORT jint JNICALL
Java_com_mobileer_oboetester_OboeAudioStream_getChannelMask(
JNIEnv *env, jobject, jint streamIndex) {
jint result = (jint) oboe::Result::ErrorNull;
std::shared_ptr<oboe::AudioStream> oboeStream = engine.getCurrentActivity()->getStream(streamIndex);
if (oboeStream != nullptr) {
result = (jint) oboeStream->getChannelMask();
}
return result;
}

JNIEXPORT jint JNICALL
Java_com_mobileer_oboetester_OboeAudioStream_getFormat(JNIEnv *env, jobject instance, jint streamIndex) {
jint result = (jint) oboe::Result::ErrorNull;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,33 @@ public class IntentBasedTestSupport {
public static final String VALUE_VOLUME_TYPE_SYSTEM = "system";
public static final String VALUE_VOLUME_TYPE_VOICE_CALL = "voice_call";

public static final String KEY_CHANNEL_MASK = "channel_mask";
public static final String VALUE_CHANNEL_MONO = "mono";
public static final String VALUE_CHANNEL_STEREO = "stereo";
public static final String VALUE_CHANNEL_2POINT1 = "2.1";
public static final String VALUE_CHANNEL_TRI = "tri";
public static final String VALUE_CHANNEL_TRI_BACK = "triBack";
public static final String VALUE_CHANNEL_3POINT1 = "3.1";
public static final String VALUE_CHANNEL_2POINT0POINT2 = "2.0.2";
public static final String VALUE_CHANNEL_2POINT1POINT2 = "2.1.2";
public static final String VALUE_CHANNEL_3POINT0POINT2 = "3.0.2";
public static final String VALUE_CHANNEL_3POINT1POINT2 = "3.1.2";
public static final String VALUE_CHANNEL_QUAD = "quad";
public static final String VALUE_CHANNEL_QUAD_SIDE = "quadside";
public static final String VALUE_CHANNEL_SURROUND = "surround";
public static final String VALUE_CHANNEL_PENTA = "penta";
public static final String VALUE_CHANNEL_5POINT1 = "5.1";
public static final String VALUE_CHANNEL_5POINT1_SIDE = "5.1side";
public static final String VALUE_CHANNEL_6POINT1 = "6.1";
public static final String VALUE_CHANNEL_7POINT1 = "7.1";
public static final String VALUE_CHANNEL_5POINT1POINT2 = "5.1.2";
public static final String VALUE_CHANNEL_5POINT1POINT4 = "5.1.4";
public static final String VALUE_CHANNEL_7POINT1POINT2 = "7.1.2";
public static final String VALUE_CHANNEL_7POINT1POINT4 = "7.1.4";
public static final String VALUE_CHANNEL_9POINT1POINT4 = "9.1.4";
public static final String VALUE_CHANNEL_9POINT1POINT6 = "9.1.6";
public static final String VALUE_CHANNEL_FRONT_BACK = "frontBack";

public static int getApiFromText(String text) {
if (VALUE_API_AAUDIO.equals(text)) {
return StreamConfiguration.NATIVE_API_AAUDIO;
Expand Down Expand Up @@ -136,6 +163,68 @@ public static int getVolumeStreamTypeFromBundle(Bundle bundle) {
}
}

public static int getChannelMaskFromBundle(Bundle bundle) {
String channelMaskText = bundle.getString(KEY_CHANNEL_MASK);
if (channelMaskText == null) {
return StreamConfiguration.UNSPECIFIED;
}
switch (channelMaskText) {
case VALUE_CHANNEL_MONO:
return StreamConfiguration.CHANNEL_MONO;
case VALUE_CHANNEL_STEREO:
return StreamConfiguration.CHANNEL_STEREO;
case VALUE_CHANNEL_2POINT1:
return StreamConfiguration.CHANNEL_2POINT1;
case VALUE_CHANNEL_TRI:
return StreamConfiguration.CHANNEL_TRI;
case VALUE_CHANNEL_TRI_BACK:
return StreamConfiguration.CHANNEL_TRI_BACK;
case VALUE_CHANNEL_3POINT1:
return StreamConfiguration.CHANNEL_3POINT1;
case VALUE_CHANNEL_2POINT0POINT2:
return StreamConfiguration.CHANNEL_2POINT0POINT2;
case VALUE_CHANNEL_2POINT1POINT2:
return StreamConfiguration.CHANNEL_2POINT1POINT2;
case VALUE_CHANNEL_3POINT0POINT2:
return StreamConfiguration.CHANNEL_3POINT0POINT2;
case VALUE_CHANNEL_3POINT1POINT2:
return StreamConfiguration.CHANNEL_3POINT1POINT2;
case VALUE_CHANNEL_QUAD:
return StreamConfiguration.CHANNEL_QUAD;
case VALUE_CHANNEL_QUAD_SIDE:
return StreamConfiguration.CHANNEL_QUAD_SIDE;
case VALUE_CHANNEL_SURROUND:
return StreamConfiguration.CHANNEL_SURROUND;
case VALUE_CHANNEL_PENTA:
return StreamConfiguration.CHANNEL_PENTA;
case VALUE_CHANNEL_5POINT1:
return StreamConfiguration.CHANNEL_5POINT1;
case VALUE_CHANNEL_5POINT1_SIDE:
return StreamConfiguration.CHANNEL_5POINT1_SIDE;
case VALUE_CHANNEL_6POINT1:
return StreamConfiguration.CHANNEL_6POINT1;
case VALUE_CHANNEL_7POINT1:
return StreamConfiguration.CHANNEL_7POINT1;
case VALUE_CHANNEL_5POINT1POINT2:
return StreamConfiguration.CHANNEL_5POINT1POINT2;
case VALUE_CHANNEL_5POINT1POINT4:
return StreamConfiguration.CHANNEL_5POINT1POINT4;
case VALUE_CHANNEL_7POINT1POINT2:
return StreamConfiguration.CHANNEL_7POINT1POINT2;
case VALUE_CHANNEL_7POINT1POINT4:
return StreamConfiguration.CHANNEL_7POINT1POINT4;
case VALUE_CHANNEL_9POINT1POINT4:
return StreamConfiguration.CHANNEL_9POINT1POINT4;
case VALUE_CHANNEL_9POINT1POINT6:
return StreamConfiguration.CHANNEL_9POINT1POINT6;
case VALUE_CHANNEL_FRONT_BACK:
return StreamConfiguration.CHANNEL_FRONT_BACK;
default:
throw new IllegalArgumentException(
KEY_CHANNEL_MASK + " invalid: " + channelMaskText);
}
}

public static void configureOutputStreamFromBundle(Bundle bundle,
StreamConfiguration requestedOutConfig) {
int audioApi;
Expand All @@ -151,7 +240,13 @@ public static void configureOutputStreamFromBundle(Bundle bundle,
requestedOutConfig.setNativeApi(audioApi);

int outChannels = bundle.getInt(KEY_OUT_CHANNELS, VALUE_DEFAULT_CHANNELS);
requestedOutConfig.setChannelCount(outChannels);
int channelMask = getChannelMaskFromBundle(bundle);
// Respect channel mask when it is specified.
if (channelMask != StreamConfiguration.UNSPECIFIED) {
requestedOutConfig.setChannelMask(channelMask);
} else {
requestedOutConfig.setChannelCount(outChannels);
}

boolean outMMAP = bundle.getBoolean(KEY_OUT_USE_MMAP, VALUE_DEFAULT_USE_MMAP);
requestedOutConfig.setMMap(outMMAP);
Expand Down Expand Up @@ -181,7 +276,13 @@ public static void configureInputStreamFromBundle(Bundle bundle,
requestedInConfig.setNativeApi(audioApi);

int inChannels = bundle.getInt(KEY_IN_CHANNELS, VALUE_DEFAULT_CHANNELS);
requestedInConfig.setChannelCount(inChannels);
int channelMask = getChannelMaskFromBundle(bundle);
// Respect channel mask when it is specified.
if (channelMask != StreamConfiguration.UNSPECIFIED) {
requestedInConfig.setChannelMask(channelMask);
} else {
requestedInConfig.setChannelCount(inChannels);
}

boolean inMMAP = bundle.getBoolean(KEY_IN_USE_MMAP, VALUE_DEFAULT_USE_MMAP);
requestedInConfig.setMMap(inMMAP);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public void open(StreamConfiguration requestedConfiguration,
int result = openNative(requestedConfiguration.getNativeApi(),
requestedConfiguration.getSampleRate(),
requestedConfiguration.getChannelCount(),
requestedConfiguration.getChannelMask(),
requestedConfiguration.getFormat(),
requestedConfiguration.getSharingMode(),
requestedConfiguration.getPerformanceMode(),
Expand Down Expand Up @@ -90,6 +91,7 @@ public void open(StreamConfiguration requestedConfiguration,
actualConfiguration.setFramesPerBurst(getFramesPerBurst());
actualConfiguration.setBufferCapacityInFrames(getBufferCapacityInFrames());
actualConfiguration.setChannelCount(getChannelCount());
actualConfiguration.setChannelMask(getChannelMask());
actualConfiguration.setDeviceId(getDeviceId());
actualConfiguration.setSessionId(getSessionId());
actualConfiguration.setFormat(getFormat());
Expand All @@ -103,6 +105,7 @@ private native int openNative(
int nativeApi,
int sampleRate,
int channelCount,
int channelMask,
int format,
int sharingMode,
int performanceMode,
Expand Down Expand Up @@ -201,6 +204,11 @@ public int getChannelCount() {
}
public native int getChannelCount(int streamIndex);

public int getChannelMask() {
return getChannelMask(streamIndex);
}
public native int getChannelMask(int streamIndex);

public int getDeviceId() {
return getDeviceId(streamIndex);
}
Expand Down
Loading