Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #define MODULE_NAME "OboeTester" |
| 18 | |
| 19 | #include <cassert> |
| 20 | #include <cstring> |
| 21 | #include <jni.h> |
| 22 | #include <stdint.h> |
| 23 | #include <thread> |
| 24 | |
| 25 | #include "common/OboeDebug.h" |
| 26 | #include "oboe/Oboe.h" |
| 27 | |
| 28 | #include "NativeAudioContext.h" |
| 29 | |
Phil Burk | 0af43bb | 2019-03-12 14:11:38 -0700 | [diff] [blame] | 30 | NativeAudioContext engine; |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 31 | |
| 32 | /*********************************************************************************/ |
| 33 | /********************** JNI Prototypes *****************************************/ |
| 34 | /*********************************************************************************/ |
| 35 | extern "C" { |
| 36 | |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 37 | JNIEXPORT jint JNICALL |
| 38 | Java_com_google_sample_oboe_manualtest_OboeAudioStream_openNative(JNIEnv *env, jobject, |
Phil Burk | 6c16ce9 | 2019-03-05 16:07:38 -0800 | [diff] [blame] | 39 | jint nativeApi, |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 40 | jint sampleRate, |
| 41 | jint channelCount, |
| 42 | jint format, |
| 43 | jint sharingMode, |
| 44 | jint performanceMode, |
| 45 | jint deviceId, |
| 46 | jint sessionId, |
| 47 | jint framesPerBurst, |
Phil Burk | 301b066 | 2019-06-06 11:36:30 -0700 | [diff] [blame] | 48 | jboolean channelConversionAllowed, |
Phil Burk | 5927398 | 2019-08-29 09:10:37 -0700 | [diff] [blame] | 49 | jboolean formatConversionAllowed, |
Phil Burk | 301b066 | 2019-06-06 11:36:30 -0700 | [diff] [blame] | 50 | jint rateConversionQuality, |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 51 | jboolean isInput); |
| 52 | JNIEXPORT void JNICALL |
Phil Burk | 6c16ce9 | 2019-03-05 16:07:38 -0800 | [diff] [blame] | 53 | Java_com_google_sample_oboe_manualtest_OboeAudioStream_close(JNIEnv *env, jobject, jint); |
Phil Burk | 0af43bb | 2019-03-12 14:11:38 -0700 | [diff] [blame] | 54 | |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 55 | JNIEXPORT jint JNICALL |
Phil Burk | 6c16ce9 | 2019-03-05 16:07:38 -0800 | [diff] [blame] | 56 | Java_com_google_sample_oboe_manualtest_OboeAudioStream_setThresholdInFrames(JNIEnv *env, jobject, jint, jint); |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 57 | JNIEXPORT jint JNICALL |
Phil Burk | 6c16ce9 | 2019-03-05 16:07:38 -0800 | [diff] [blame] | 58 | Java_com_google_sample_oboe_manualtest_OboeAudioStream_getThresholdInFrames(JNIEnv *env, jobject, jint); |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 59 | JNIEXPORT jint JNICALL |
Phil Burk | 6c16ce9 | 2019-03-05 16:07:38 -0800 | [diff] [blame] | 60 | Java_com_google_sample_oboe_manualtest_OboeAudioStream_getBufferCapacityInFrames(JNIEnv *env, jobject, jint); |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 61 | JNIEXPORT jint JNICALL |
Phil Burk | 6c16ce9 | 2019-03-05 16:07:38 -0800 | [diff] [blame] | 62 | Java_com_google_sample_oboe_manualtest_OboeAudioStream_setNativeApi(JNIEnv *env, jobject, jint, jint); |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 63 | |
| 64 | JNIEXPORT void JNICALL |
| 65 | Java_com_google_sample_oboe_manualtest_OboeAudioStream_setUseCallback(JNIEnv *env, jclass type, |
Phil Burk | 6fb1d80 | 2018-12-21 15:28:07 -0800 | [diff] [blame] | 66 | jboolean useCallback); |
| 67 | JNIEXPORT void JNICALL |
| 68 | Java_com_google_sample_oboe_manualtest_OboeAudioStream_setCallbackReturnStop(JNIEnv *env, |
| 69 | jclass type, |
| 70 | jboolean b); |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 71 | JNIEXPORT void JNICALL |
| 72 | Java_com_google_sample_oboe_manualtest_OboeAudioStream_setCallbackSize(JNIEnv *env, jclass type, |
| 73 | jint callbackSize); |
| 74 | |
| 75 | // ================= OboeAudioOutputStream ================================ |
| 76 | |
| 77 | JNIEXPORT void JNICALL |
| 78 | Java_com_google_sample_oboe_manualtest_OboeAudioOutputStream_setToneEnabled(JNIEnv *env, jobject, jboolean); |
| 79 | JNIEXPORT void JNICALL |
| 80 | Java_com_google_sample_oboe_manualtest_OboeAudioOutputStream_setToneType(JNIEnv *env, jobject, jint); |
| 81 | JNIEXPORT void JNICALL |
| 82 | Java_com_google_sample_oboe_manualtest_OboeAudioOutputStream_setAmplitude(JNIEnv *env, jobject, jdouble); |
| 83 | |
| 84 | /*********************************************************************************/ |
| 85 | /********************** JNI Implementations *************************************/ |
| 86 | /*********************************************************************************/ |
Phil Burk | 6c16ce9 | 2019-03-05 16:07:38 -0800 | [diff] [blame] | 87 | |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 88 | JNIEXPORT jint JNICALL |
| 89 | Java_com_google_sample_oboe_manualtest_OboeAudioStream_openNative( |
| 90 | JNIEnv *env, jobject synth, |
Phil Burk | 6c16ce9 | 2019-03-05 16:07:38 -0800 | [diff] [blame] | 91 | jint nativeApi, |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 92 | jint sampleRate, |
| 93 | jint channelCount, |
| 94 | jint format, |
| 95 | jint sharingMode, |
| 96 | jint performanceMode, |
| 97 | jint deviceId, |
| 98 | jint sessionId, |
| 99 | jint framesPerBurst, |
Phil Burk | 301b066 | 2019-06-06 11:36:30 -0700 | [diff] [blame] | 100 | jboolean channelConversionAllowed, |
Phil Burk | 5927398 | 2019-08-29 09:10:37 -0700 | [diff] [blame] | 101 | jboolean formatConversionAllowed, |
Phil Burk | 301b066 | 2019-06-06 11:36:30 -0700 | [diff] [blame] | 102 | jint rateConversionQuality, |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 103 | jboolean isInput) { |
| 104 | LOGD("OboeAudioStream_openNative: sampleRate = %d, framesPerBurst = %d", sampleRate, framesPerBurst); |
| 105 | |
Phil Burk | 0af43bb | 2019-03-12 14:11:38 -0700 | [diff] [blame] | 106 | return (jint) engine.getCurrentActivity()->open(nativeApi, |
Phil Burk | 6c16ce9 | 2019-03-05 16:07:38 -0800 | [diff] [blame] | 107 | sampleRate, |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 108 | channelCount, |
| 109 | format, |
| 110 | sharingMode, |
| 111 | performanceMode, |
| 112 | deviceId, |
| 113 | sessionId, |
| 114 | framesPerBurst, |
Phil Burk | 301b066 | 2019-06-06 11:36:30 -0700 | [diff] [blame] | 115 | channelConversionAllowed, |
Phil Burk | 5927398 | 2019-08-29 09:10:37 -0700 | [diff] [blame] | 116 | formatConversionAllowed, |
Phil Burk | 301b066 | 2019-06-06 11:36:30 -0700 | [diff] [blame] | 117 | rateConversionQuality, |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 118 | isInput); |
| 119 | } |
| 120 | |
| 121 | JNIEXPORT jint JNICALL |
Phil Burk | 03bdc0a | 2019-03-06 15:56:25 -0800 | [diff] [blame] | 122 | Java_com_google_sample_oboe_manualtest_TestAudioActivity_startNative(JNIEnv *env, jobject) { |
Phil Burk | 0af43bb | 2019-03-12 14:11:38 -0700 | [diff] [blame] | 123 | return (jint) engine.getCurrentActivity()->start(); |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | JNIEXPORT jint JNICALL |
Phil Burk | 03bdc0a | 2019-03-06 15:56:25 -0800 | [diff] [blame] | 127 | Java_com_google_sample_oboe_manualtest_TestAudioActivity_pauseNative(JNIEnv *env, jobject) { |
Phil Burk | 0af43bb | 2019-03-12 14:11:38 -0700 | [diff] [blame] | 128 | return (jint) engine.getCurrentActivity()->pause(); |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | JNIEXPORT jint JNICALL |
Phil Burk | 03bdc0a | 2019-03-06 15:56:25 -0800 | [diff] [blame] | 132 | Java_com_google_sample_oboe_manualtest_TestAudioActivity_stopNative(JNIEnv *env, jobject) { |
Phil Burk | 0af43bb | 2019-03-12 14:11:38 -0700 | [diff] [blame] | 133 | return (jint) engine.getCurrentActivity()->stop(); |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | JNIEXPORT jint JNICALL |
| 137 | Java_com_google_sample_oboe_manualtest_OboeAudioStream_startPlaybackNative(JNIEnv *env, jobject) { |
Phil Burk | 0af43bb | 2019-03-12 14:11:38 -0700 | [diff] [blame] | 138 | return (jint) engine.getCurrentActivity()->startPlayback(); |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | JNIEXPORT void JNICALL |
Phil Burk | 6c16ce9 | 2019-03-05 16:07:38 -0800 | [diff] [blame] | 142 | Java_com_google_sample_oboe_manualtest_OboeAudioStream_close(JNIEnv *env, jobject, jint streamIndex) { |
Phil Burk | 0af43bb | 2019-03-12 14:11:38 -0700 | [diff] [blame] | 143 | engine.getCurrentActivity()->close(streamIndex); |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | JNIEXPORT jint JNICALL |
| 147 | Java_com_google_sample_oboe_manualtest_OboeAudioStream_setBufferSizeInFrames( |
Phil Burk | 6c16ce9 | 2019-03-05 16:07:38 -0800 | [diff] [blame] | 148 | JNIEnv *env, jobject, jint streamIndex, jint threshold) { |
Phil Burk | 0af43bb | 2019-03-12 14:11:38 -0700 | [diff] [blame] | 149 | oboe::AudioStream *oboeStream = engine.getCurrentActivity()->getStream(streamIndex); |
Phil Burk | 6c16ce9 | 2019-03-05 16:07:38 -0800 | [diff] [blame] | 150 | if (oboeStream != nullptr) { |
| 151 | auto result = oboeStream->setBufferSizeInFrames(threshold); |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 152 | return (!result) |
| 153 | ? (jint) result.error() |
| 154 | : (jint) result.value(); |
| 155 | } |
| 156 | return (jint) oboe::Result::ErrorNull; |
| 157 | } |
| 158 | |
| 159 | JNIEXPORT jint JNICALL |
| 160 | Java_com_google_sample_oboe_manualtest_OboeAudioStream_getBufferSizeInFrames( |
Phil Burk | 6c16ce9 | 2019-03-05 16:07:38 -0800 | [diff] [blame] | 161 | JNIEnv *env, jobject, jint streamIndex) { |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 162 | jint result = (jint) oboe::Result::ErrorNull; |
Phil Burk | 0af43bb | 2019-03-12 14:11:38 -0700 | [diff] [blame] | 163 | oboe::AudioStream *oboeStream = engine.getCurrentActivity()->getStream(streamIndex); |
Phil Burk | 6c16ce9 | 2019-03-05 16:07:38 -0800 | [diff] [blame] | 164 | if (oboeStream != nullptr) { |
| 165 | result = oboeStream->getBufferSizeInFrames(); |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 166 | } |
| 167 | return result; |
| 168 | } |
| 169 | |
| 170 | JNIEXPORT jint JNICALL |
| 171 | Java_com_google_sample_oboe_manualtest_OboeAudioStream_getBufferCapacityInFrames( |
Phil Burk | 6c16ce9 | 2019-03-05 16:07:38 -0800 | [diff] [blame] | 172 | JNIEnv *env, jobject, jint streamIndex) { |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 173 | jint result = (jint) oboe::Result::ErrorNull; |
Phil Burk | 0af43bb | 2019-03-12 14:11:38 -0700 | [diff] [blame] | 174 | oboe::AudioStream *oboeStream = engine.getCurrentActivity()->getStream(streamIndex); |
Phil Burk | 6c16ce9 | 2019-03-05 16:07:38 -0800 | [diff] [blame] | 175 | if (oboeStream != nullptr) { |
| 176 | result = oboeStream->getBufferCapacityInFrames(); |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 177 | } |
| 178 | return result; |
| 179 | } |
| 180 | |
| 181 | static int convertAudioApiToNativeApi(oboe::AudioApi audioApi) { |
| 182 | switch(audioApi) { |
| 183 | case oboe::AudioApi::Unspecified: |
| 184 | return NATIVE_MODE_UNSPECIFIED; |
| 185 | case oboe::AudioApi::OpenSLES: |
| 186 | return NATIVE_MODE_OPENSLES; |
| 187 | case oboe::AudioApi::AAudio: |
| 188 | return NATIVE_MODE_AAUDIO; |
| 189 | default: |
| 190 | return -1; |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | JNIEXPORT jint JNICALL |
| 195 | Java_com_google_sample_oboe_manualtest_OboeAudioStream_getNativeApi( |
Phil Burk | 6c16ce9 | 2019-03-05 16:07:38 -0800 | [diff] [blame] | 196 | JNIEnv *env, jobject, jint streamIndex) { |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 197 | jint result = (jint) oboe::Result::ErrorNull; |
Phil Burk | 0af43bb | 2019-03-12 14:11:38 -0700 | [diff] [blame] | 198 | oboe::AudioStream *oboeStream = engine.getCurrentActivity()->getStream(streamIndex); |
Phil Burk | 6c16ce9 | 2019-03-05 16:07:38 -0800 | [diff] [blame] | 199 | if (oboeStream != nullptr) { |
| 200 | oboe::AudioApi audioApi = oboeStream->getAudioApi(); |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 201 | result = convertAudioApiToNativeApi(audioApi); |
| 202 | LOGD("OboeAudioStream_getNativeApi got %d", result); |
| 203 | } |
| 204 | return result; |
| 205 | } |
| 206 | |
| 207 | JNIEXPORT jint JNICALL |
| 208 | Java_com_google_sample_oboe_manualtest_OboeAudioStream_getSampleRate( |
Phil Burk | 6c16ce9 | 2019-03-05 16:07:38 -0800 | [diff] [blame] | 209 | JNIEnv *env, jobject, jint streamIndex) { |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 210 | jint result = (jint) oboe::Result::ErrorNull; |
Phil Burk | 0af43bb | 2019-03-12 14:11:38 -0700 | [diff] [blame] | 211 | oboe::AudioStream *oboeStream = engine.getCurrentActivity()->getStream(streamIndex); |
Phil Burk | 6c16ce9 | 2019-03-05 16:07:38 -0800 | [diff] [blame] | 212 | if (oboeStream != nullptr) { |
| 213 | result = oboeStream->getSampleRate(); |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 214 | } |
| 215 | return result; |
| 216 | } |
| 217 | |
| 218 | JNIEXPORT jint JNICALL |
| 219 | Java_com_google_sample_oboe_manualtest_OboeAudioStream_getSharingMode( |
Phil Burk | 6c16ce9 | 2019-03-05 16:07:38 -0800 | [diff] [blame] | 220 | JNIEnv *env, jobject, jint streamIndex) { |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 221 | jint result = (jint) oboe::Result::ErrorNull; |
Phil Burk | 0af43bb | 2019-03-12 14:11:38 -0700 | [diff] [blame] | 222 | oboe::AudioStream *oboeStream = engine.getCurrentActivity()->getStream(streamIndex); |
Phil Burk | 6c16ce9 | 2019-03-05 16:07:38 -0800 | [diff] [blame] | 223 | if (oboeStream != nullptr) { |
| 224 | result = (jint) oboeStream->getSharingMode(); |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 225 | } |
| 226 | return result; |
| 227 | } |
| 228 | |
| 229 | JNIEXPORT jint JNICALL |
| 230 | Java_com_google_sample_oboe_manualtest_OboeAudioStream_getPerformanceMode( |
Phil Burk | 6c16ce9 | 2019-03-05 16:07:38 -0800 | [diff] [blame] | 231 | JNIEnv *env, jobject, jint streamIndex) { |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 232 | jint result = (jint) oboe::Result::ErrorNull; |
Phil Burk | 0af43bb | 2019-03-12 14:11:38 -0700 | [diff] [blame] | 233 | oboe::AudioStream *oboeStream = engine.getCurrentActivity()->getStream(streamIndex); |
Phil Burk | 6c16ce9 | 2019-03-05 16:07:38 -0800 | [diff] [blame] | 234 | if (oboeStream != nullptr) { |
| 235 | result = (jint) oboeStream->getPerformanceMode(); |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 236 | } |
| 237 | return result; |
| 238 | } |
| 239 | |
| 240 | JNIEXPORT jint JNICALL |
| 241 | Java_com_google_sample_oboe_manualtest_OboeAudioStream_getFramesPerBurst( |
Phil Burk | 6c16ce9 | 2019-03-05 16:07:38 -0800 | [diff] [blame] | 242 | JNIEnv *env, jobject, jint streamIndex) { |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 243 | jint result = (jint) oboe::Result::ErrorNull; |
Phil Burk | 0af43bb | 2019-03-12 14:11:38 -0700 | [diff] [blame] | 244 | oboe::AudioStream *oboeStream = engine.getCurrentActivity()->getStream(streamIndex); |
Phil Burk | 6c16ce9 | 2019-03-05 16:07:38 -0800 | [diff] [blame] | 245 | if (oboeStream != nullptr) { |
| 246 | result = oboeStream->getFramesPerBurst(); |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 247 | } |
| 248 | return result; |
| 249 | } |
| 250 | |
| 251 | JNIEXPORT jint JNICALL |
| 252 | Java_com_google_sample_oboe_manualtest_OboeAudioStream_getChannelCount( |
Phil Burk | 6c16ce9 | 2019-03-05 16:07:38 -0800 | [diff] [blame] | 253 | JNIEnv *env, jobject, jint streamIndex) { |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 254 | jint result = (jint) oboe::Result::ErrorNull; |
Phil Burk | 0af43bb | 2019-03-12 14:11:38 -0700 | [diff] [blame] | 255 | oboe::AudioStream *oboeStream = engine.getCurrentActivity()->getStream(streamIndex); |
Phil Burk | 6c16ce9 | 2019-03-05 16:07:38 -0800 | [diff] [blame] | 256 | if (oboeStream != nullptr) { |
| 257 | result = oboeStream->getChannelCount(); |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 258 | } |
| 259 | return result; |
| 260 | } |
| 261 | |
| 262 | JNIEXPORT jint JNICALL |
Phil Burk | 6c16ce9 | 2019-03-05 16:07:38 -0800 | [diff] [blame] | 263 | Java_com_google_sample_oboe_manualtest_OboeAudioStream_getFormat(JNIEnv *env, jobject instance, jint streamIndex) { |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 264 | jint result = (jint) oboe::Result::ErrorNull; |
Phil Burk | 0af43bb | 2019-03-12 14:11:38 -0700 | [diff] [blame] | 265 | oboe::AudioStream *oboeStream = engine.getCurrentActivity()->getStream(streamIndex); |
Phil Burk | 6c16ce9 | 2019-03-05 16:07:38 -0800 | [diff] [blame] | 266 | if (oboeStream != nullptr) { |
| 267 | result = (jint) oboeStream->getFormat(); |
| 268 | } |
| 269 | return result; |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | JNIEXPORT jint JNICALL |
| 273 | Java_com_google_sample_oboe_manualtest_OboeAudioStream_getDeviceId( |
Phil Burk | 6c16ce9 | 2019-03-05 16:07:38 -0800 | [diff] [blame] | 274 | JNIEnv *env, jobject, jint streamIndex) { |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 275 | jint result = (jint) oboe::Result::ErrorNull; |
Phil Burk | 0af43bb | 2019-03-12 14:11:38 -0700 | [diff] [blame] | 276 | oboe::AudioStream *oboeStream = engine.getCurrentActivity()->getStream(streamIndex); |
Phil Burk | 6c16ce9 | 2019-03-05 16:07:38 -0800 | [diff] [blame] | 277 | if (oboeStream != nullptr) { |
| 278 | result = oboeStream->getDeviceId(); |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 279 | } |
| 280 | return result; |
| 281 | } |
| 282 | |
| 283 | JNIEXPORT jint JNICALL |
| 284 | Java_com_google_sample_oboe_manualtest_OboeAudioStream_getSessionId( |
Phil Burk | 6c16ce9 | 2019-03-05 16:07:38 -0800 | [diff] [blame] | 285 | JNIEnv *env, jobject, jint streamIndex) { |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 286 | jint result = (jint) oboe::Result::ErrorNull; |
Phil Burk | 0af43bb | 2019-03-12 14:11:38 -0700 | [diff] [blame] | 287 | oboe::AudioStream *oboeStream = engine.getCurrentActivity()->getStream(streamIndex); |
Phil Burk | 6c16ce9 | 2019-03-05 16:07:38 -0800 | [diff] [blame] | 288 | if (oboeStream != nullptr) { |
| 289 | result = oboeStream->getSessionId(); |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 290 | } |
| 291 | return result; |
| 292 | } |
| 293 | |
| 294 | JNIEXPORT jlong JNICALL |
| 295 | Java_com_google_sample_oboe_manualtest_OboeAudioStream_getFramesWritten( |
Phil Burk | 6c16ce9 | 2019-03-05 16:07:38 -0800 | [diff] [blame] | 296 | JNIEnv *env, jobject, jint streamIndex) { |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 297 | jlong result = (jint) oboe::Result::ErrorNull; |
Phil Burk | 0af43bb | 2019-03-12 14:11:38 -0700 | [diff] [blame] | 298 | oboe::AudioStream *oboeStream = engine.getCurrentActivity()->getStream(streamIndex); |
Phil Burk | 6c16ce9 | 2019-03-05 16:07:38 -0800 | [diff] [blame] | 299 | if (oboeStream != nullptr) { |
| 300 | result = oboeStream->getFramesWritten(); |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 301 | } |
| 302 | return result; |
| 303 | } |
| 304 | |
| 305 | JNIEXPORT jlong JNICALL |
| 306 | Java_com_google_sample_oboe_manualtest_OboeAudioStream_getFramesRead( |
Phil Burk | 6c16ce9 | 2019-03-05 16:07:38 -0800 | [diff] [blame] | 307 | JNIEnv *env, jobject, jint streamIndex) { |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 308 | jlong result = (jlong) oboe::Result::ErrorNull; |
Phil Burk | 0af43bb | 2019-03-12 14:11:38 -0700 | [diff] [blame] | 309 | oboe::AudioStream *oboeStream = engine.getCurrentActivity()->getStream(streamIndex); |
Phil Burk | 6c16ce9 | 2019-03-05 16:07:38 -0800 | [diff] [blame] | 310 | if (oboeStream != nullptr) { |
| 311 | result = oboeStream->getFramesRead(); |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 312 | } |
| 313 | return result; |
| 314 | } |
| 315 | |
Phil Burk | 5cb621f | 2019-02-14 17:51:30 -0800 | [diff] [blame] | 316 | JNIEXPORT jint JNICALL |
| 317 | Java_com_google_sample_oboe_manualtest_OboeAudioStream_getXRunCount( |
Phil Burk | 6c16ce9 | 2019-03-05 16:07:38 -0800 | [diff] [blame] | 318 | JNIEnv *env, jobject, jint streamIndex) { |
Phil Burk | 5cb621f | 2019-02-14 17:51:30 -0800 | [diff] [blame] | 319 | jint result = (jlong) oboe::Result::ErrorNull; |
Phil Burk | 0af43bb | 2019-03-12 14:11:38 -0700 | [diff] [blame] | 320 | oboe::AudioStream *oboeStream = engine.getCurrentActivity()->getStream(streamIndex); |
Phil Burk | 6c16ce9 | 2019-03-05 16:07:38 -0800 | [diff] [blame] | 321 | if (oboeStream != nullptr) { |
| 322 | auto oboeResult = oboeStream->getXRunCount(); |
Phil Burk | 5cb621f | 2019-02-14 17:51:30 -0800 | [diff] [blame] | 323 | if (!oboeResult) { |
| 324 | result = (jint) oboeResult.error(); |
| 325 | } else { |
| 326 | result = oboeResult.value(); |
| 327 | } |
| 328 | } |
| 329 | return result; |
| 330 | } |
| 331 | |
Phil Burk | 6fb1d80 | 2018-12-21 15:28:07 -0800 | [diff] [blame] | 332 | JNIEXPORT jlong JNICALL |
| 333 | Java_com_google_sample_oboe_manualtest_OboeAudioStream_getCallbackCount( |
| 334 | JNIEnv *env, jobject) { |
Phil Burk | 0af43bb | 2019-03-12 14:11:38 -0700 | [diff] [blame] | 335 | return engine.getCurrentActivity()->getCallbackCount(); |
Phil Burk | 6fb1d80 | 2018-12-21 15:28:07 -0800 | [diff] [blame] | 336 | } |
| 337 | |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 338 | JNIEXPORT jdouble JNICALL |
Phil Burk | 6c16ce9 | 2019-03-05 16:07:38 -0800 | [diff] [blame] | 339 | Java_com_google_sample_oboe_manualtest_OboeAudioStream_getLatency(JNIEnv *env, jobject instance, jint streamIndex) { |
Phil Burk | 0af43bb | 2019-03-12 14:11:38 -0700 | [diff] [blame] | 340 | oboe::AudioStream *oboeStream = engine.getCurrentActivity()->getStream(streamIndex); |
Phil Burk | 6c16ce9 | 2019-03-05 16:07:38 -0800 | [diff] [blame] | 341 | if (oboeStream != nullptr) { |
| 342 | auto result = oboeStream->calculateLatencyMillis(); |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 343 | return (!result) ? -1.0 : result.value(); |
| 344 | } |
| 345 | return -1.0; |
| 346 | } |
| 347 | |
| 348 | JNIEXPORT jint JNICALL |
Phil Burk | 6c16ce9 | 2019-03-05 16:07:38 -0800 | [diff] [blame] | 349 | Java_com_google_sample_oboe_manualtest_OboeAudioStream_getState(JNIEnv *env, jobject instance, jint streamIndex) { |
Phil Burk | 0af43bb | 2019-03-12 14:11:38 -0700 | [diff] [blame] | 350 | oboe::AudioStream *oboeStream = engine.getCurrentActivity()->getStream(streamIndex); |
Phil Burk | 6c16ce9 | 2019-03-05 16:07:38 -0800 | [diff] [blame] | 351 | if (oboeStream != nullptr) { |
| 352 | auto state = oboeStream->getState(); |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 353 | if (state != oboe::StreamState::Starting && state != oboe::StreamState::Started) { |
Phil Burk | 6c16ce9 | 2019-03-05 16:07:38 -0800 | [diff] [blame] | 354 | oboe::Result result = oboeStream->waitForStateChange( |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 355 | oboe::StreamState::Uninitialized, |
| 356 | &state, 0); |
| 357 | if (result != oboe::Result::OK) state = oboe::StreamState::Unknown; |
| 358 | } |
| 359 | return (jint) state; |
| 360 | } |
| 361 | return -1; |
| 362 | } |
| 363 | |
| 364 | JNIEXPORT jdouble JNICALL |
| 365 | Java_com_google_sample_oboe_manualtest_AudioInputTester_getPeakLevel(JNIEnv *env, |
| 366 | jobject instance, |
| 367 | jint index) { |
Phil Burk | 0af43bb | 2019-03-12 14:11:38 -0700 | [diff] [blame] | 368 | return engine.getCurrentActivity()->getPeakLevel(index); |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 369 | } |
| 370 | |
| 371 | JNIEXPORT void JNICALL |
| 372 | Java_com_google_sample_oboe_manualtest_OboeAudioStream_setUseCallback(JNIEnv *env, jclass type, |
Phil Burk | 6fb1d80 | 2018-12-21 15:28:07 -0800 | [diff] [blame] | 373 | jboolean useCallback) { |
Phil Burk | bd76d6a | 2019-06-01 08:48:03 -0700 | [diff] [blame] | 374 | ActivityContext::mUseCallback = useCallback; |
Phil Burk | 6fb1d80 | 2018-12-21 15:28:07 -0800 | [diff] [blame] | 375 | } |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 376 | |
Phil Burk | 6fb1d80 | 2018-12-21 15:28:07 -0800 | [diff] [blame] | 377 | JNIEXPORT void JNICALL |
| 378 | Java_com_google_sample_oboe_manualtest_OboeAudioStream_setCallbackReturnStop(JNIEnv *env, jclass type, |
| 379 | jboolean b) { |
Phil Burk | 6f1d5c1 | 2019-04-05 15:33:07 -0700 | [diff] [blame] | 380 | OboeStreamCallbackProxy::setCallbackReturnStop(b); |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | JNIEXPORT void JNICALL |
| 384 | Java_com_google_sample_oboe_manualtest_OboeAudioStream_setCallbackSize(JNIEnv *env, jclass type, |
| 385 | jint callbackSize) { |
Phil Burk | 0af43bb | 2019-03-12 14:11:38 -0700 | [diff] [blame] | 386 | ActivityContext::callbackSize = callbackSize; |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 387 | } |
| 388 | |
| 389 | JNIEXPORT jboolean JNICALL |
Phil Burk | 6c16ce9 | 2019-03-05 16:07:38 -0800 | [diff] [blame] | 390 | Java_com_google_sample_oboe_manualtest_OboeAudioStream_isMMap(JNIEnv *env, jobject instance, jint streamIndex) { |
Phil Burk | 0af43bb | 2019-03-12 14:11:38 -0700 | [diff] [blame] | 391 | return engine.getCurrentActivity()->isMMapUsed(streamIndex); |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 392 | } |
| 393 | |
| 394 | // ================= OboeAudioOutputStream ================================ |
| 395 | |
| 396 | JNIEXPORT void JNICALL |
| 397 | Java_com_google_sample_oboe_manualtest_OboeAudioOutputStream_setToneEnabled( |
| 398 | JNIEnv *env, jobject, jboolean enabled) { |
Phil Burk | 0af43bb | 2019-03-12 14:11:38 -0700 | [diff] [blame] | 399 | engine.getCurrentActivity()->setEnabled(enabled); |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | JNIEXPORT void JNICALL |
| 403 | Java_com_google_sample_oboe_manualtest_OboeAudioOutputStream_setToneType( |
| 404 | JNIEnv *env, jobject, jint toneType) { |
Phil Burk | 0af43bb | 2019-03-12 14:11:38 -0700 | [diff] [blame] | 405 | // FIXME engine.getCurrentActivity()->setToneType(toneType); |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 406 | } |
| 407 | |
| 408 | JNIEXPORT void JNICALL |
| 409 | Java_com_google_sample_oboe_manualtest_OboeAudioOutputStream_setAmplitude( |
| 410 | JNIEnv *env, jobject, jdouble amplitude) { |
Phil Burk | 0af43bb | 2019-03-12 14:11:38 -0700 | [diff] [blame] | 411 | engine.getCurrentActivity()->setAmplitude(amplitude); |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 412 | |
| 413 | } |
| 414 | |
Phil Burk | e5985ed | 2018-12-06 11:38:30 -0800 | [diff] [blame] | 415 | JNIEXPORT void JNICALL |
| 416 | Java_com_google_sample_oboe_manualtest_OboeAudioOutputStream_setChannelEnabled( |
| 417 | JNIEnv *env, jobject, jint channelIndex, jboolean enabled) { |
Phil Burk | 0af43bb | 2019-03-12 14:11:38 -0700 | [diff] [blame] | 418 | engine.getCurrentActivity()->setChannelEnabled(channelIndex, enabled); |
Phil Burk | e5985ed | 2018-12-06 11:38:30 -0800 | [diff] [blame] | 419 | } |
| 420 | |
Phil Burk | 0a784e6 | 2019-07-20 12:43:15 -0700 | [diff] [blame] | 421 | JNIEXPORT void JNICALL |
| 422 | Java_com_google_sample_oboe_manualtest_OboeAudioOutputStream_setSignalType( |
| 423 | JNIEnv *env, jobject, jint signalType) { |
| 424 | engine.getCurrentActivity()->setSignalType(signalType); |
| 425 | } |
| 426 | |
Phil Burk | 7386a83 | 2019-03-21 16:07:27 -0700 | [diff] [blame] | 427 | // ========================================================================== |
Phil Burk | 03bdc0a | 2019-03-06 15:56:25 -0800 | [diff] [blame] | 428 | JNIEXPORT void JNICALL |
| 429 | Java_com_google_sample_oboe_manualtest_TestAudioActivity_setActivityType(JNIEnv *env, |
| 430 | jobject instance, |
| 431 | jint activityType) { |
| 432 | engine.setActivityType(activityType); |
| 433 | } |
| 434 | |
Phil Burk | 7386a83 | 2019-03-21 16:07:27 -0700 | [diff] [blame] | 435 | // ========================================================================== |
Phil Burk | 327361c | 2019-04-13 14:45:27 -0700 | [diff] [blame] | 436 | JNIEXPORT jint JNICALL |
| 437 | Java_com_google_sample_oboe_manualtest_TestInputActivity_saveWaveFile(JNIEnv *env, |
| 438 | jobject instance, |
| 439 | jstring fileName) { |
| 440 | const char *str = env->GetStringUTFChars(fileName, nullptr); |
| 441 | LOGD("nativeSaveFile(%s)", str); |
| 442 | jint result = engine.getCurrentActivity()->saveWaveFile(str); |
| 443 | env->ReleaseStringUTFChars(fileName, str); |
| 444 | return result; |
| 445 | } |
| 446 | |
| 447 | // ========================================================================== |
Phil Burk | 1d17a60 | 2019-03-12 15:37:56 -0700 | [diff] [blame] | 448 | JNIEXPORT void JNICALL |
Phil Burk | bbde5bb | 2019-09-02 16:00:18 -0700 | [diff] [blame] | 449 | Java_com_google_sample_oboe_manualtest_TestInputActivity_setMinimumFramesBeforeRead(JNIEnv *env, |
| 450 | jobject instance, |
| 451 | jint numFrames) { |
| 452 | engine.getCurrentActivity()->setMinimumFramesBeforeRead(numFrames); |
| 453 | } |
| 454 | |
| 455 | // ========================================================================== |
| 456 | JNIEXPORT void JNICALL |
Phil Burk | 1d17a60 | 2019-03-12 15:37:56 -0700 | [diff] [blame] | 457 | Java_com_google_sample_oboe_manualtest_EchoActivity_setDelayTime(JNIEnv *env, |
| 458 | jobject instance, |
| 459 | jdouble delayTimeSeconds) { |
| 460 | engine.setDelayTime(delayTimeSeconds); |
| 461 | } |
| 462 | |
Phil Burk | 7386a83 | 2019-03-21 16:07:27 -0700 | [diff] [blame] | 463 | // ========================================================================== |
Phil Burk | 80d83d8 | 2019-03-15 12:03:37 -0700 | [diff] [blame] | 464 | JNIEXPORT jint JNICALL |
| 465 | Java_com_google_sample_oboe_manualtest_RoundTripLatencyActivity_getAnalyzerProgress(JNIEnv *env, |
Phil Burk | 3873e88 | 2019-03-18 10:15:13 -0700 | [diff] [blame] | 466 | jobject instance) { |
Phil Burk | d2dd527 | 2019-03-18 16:05:25 -0700 | [diff] [blame] | 467 | return engine.mActivityRoundTripLatency.getLatencyAnalyzer()->getProgress(); |
Phil Burk | 80d83d8 | 2019-03-15 12:03:37 -0700 | [diff] [blame] | 468 | } |
| 469 | |
Phil Burk | cd12e2c | 2019-07-29 20:39:42 -0700 | [diff] [blame] | 470 | JNIEXPORT jint JNICALL |
Phil Burk | 80d83d8 | 2019-03-15 12:03:37 -0700 | [diff] [blame] | 471 | Java_com_google_sample_oboe_manualtest_RoundTripLatencyActivity_getMeasuredLatency(JNIEnv *env, |
| 472 | jobject instance) { |
Phil Burk | d2dd527 | 2019-03-18 16:05:25 -0700 | [diff] [blame] | 473 | return engine.mActivityRoundTripLatency.getLatencyAnalyzer()->getMeasuredLatency(); |
Phil Burk | 80d83d8 | 2019-03-15 12:03:37 -0700 | [diff] [blame] | 474 | } |
| 475 | |
| 476 | JNIEXPORT jdouble JNICALL |
| 477 | Java_com_google_sample_oboe_manualtest_RoundTripLatencyActivity_getMeasuredConfidence(JNIEnv *env, |
Phil Burk | d2dd527 | 2019-03-18 16:05:25 -0700 | [diff] [blame] | 478 | jobject instance) { |
| 479 | return engine.mActivityRoundTripLatency.getLatencyAnalyzer()->getMeasuredConfidence(); |
| 480 | } |
| 481 | |
Phil Burk | cd12e2c | 2019-07-29 20:39:42 -0700 | [diff] [blame] | 482 | JNIEXPORT jdouble JNICALL |
| 483 | Java_com_google_sample_oboe_manualtest_RoundTripLatencyActivity_getBackgroundRMS(JNIEnv *env, |
| 484 | jobject instance) { |
| 485 | return engine.mActivityRoundTripLatency.getLatencyAnalyzer()->getBackgroundRMS(); |
| 486 | } |
| 487 | |
| 488 | JNIEXPORT jdouble JNICALL |
| 489 | Java_com_google_sample_oboe_manualtest_RoundTripLatencyActivity_getSignalRMS(JNIEnv *env, |
| 490 | jobject instance) { |
| 491 | return engine.mActivityRoundTripLatency.getLatencyAnalyzer()->getSignalRMS(); |
| 492 | } |
| 493 | |
| 494 | JNIEXPORT jint JNICALL |
| 495 | Java_com_google_sample_oboe_manualtest_AnalyzerActivity_getMeasuredResult(JNIEnv *env, |
| 496 | jobject instance) { |
| 497 | return engine.mActivityRoundTripLatency.getLatencyAnalyzer()->getResult(); |
| 498 | } |
| 499 | |
Phil Burk | 7386a83 | 2019-03-21 16:07:27 -0700 | [diff] [blame] | 500 | // ========================================================================== |
Phil Burk | d2dd527 | 2019-03-18 16:05:25 -0700 | [diff] [blame] | 501 | JNIEXPORT jint JNICALL |
Phil Burk | 7386a83 | 2019-03-21 16:07:27 -0700 | [diff] [blame] | 502 | Java_com_google_sample_oboe_manualtest_AnalyzerActivity_getAnalyzerState(JNIEnv *env, |
| 503 | jobject instance) { |
| 504 | return ((ActivityFullDuplex *)engine.getCurrentActivity())->getState(); |
| 505 | } |
| 506 | |
| 507 | JNIEXPORT jboolean JNICALL |
| 508 | Java_com_google_sample_oboe_manualtest_AnalyzerActivity_isAnalyzerDone(JNIEnv *env, |
| 509 | jobject instance) { |
| 510 | return ((ActivityFullDuplex *)engine.getCurrentActivity())->isAnalyzerDone(); |
| 511 | } |
| 512 | |
| 513 | JNIEXPORT jint JNICALL |
Phil Burk | cd81832 | 2019-03-22 16:51:40 -0700 | [diff] [blame] | 514 | Java_com_google_sample_oboe_manualtest_AnalyzerActivity_getResetCount(JNIEnv *env, |
| 515 | jobject instance) { |
| 516 | return ((ActivityFullDuplex *)engine.getCurrentActivity())->getResetCount(); |
| 517 | } |
Phil Burk | 7386a83 | 2019-03-21 16:07:27 -0700 | [diff] [blame] | 518 | |
| 519 | // ========================================================================== |
| 520 | JNIEXPORT jint JNICALL |
| 521 | Java_com_google_sample_oboe_manualtest_GlitchActivity_getGlitchCount(JNIEnv *env, |
| 522 | jobject instance) { |
Phil Burk | 7386a83 | 2019-03-21 16:07:27 -0700 | [diff] [blame] | 523 | return engine.mActivityGlitches.getGlitchAnalyzer()->getGlitchCount(); |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 524 | } |
Phil Burk | 7386a83 | 2019-03-21 16:07:27 -0700 | [diff] [blame] | 525 | |
Phil Burk | bbde5bb | 2019-09-02 16:00:18 -0700 | [diff] [blame] | 526 | JNIEXPORT jint JNICALL |
| 527 | Java_com_google_sample_oboe_manualtest_GlitchActivity_getStateFrameCount(JNIEnv *env, |
| 528 | jobject instance, |
| 529 | jint state) { |
| 530 | return engine.mActivityGlitches.getGlitchAnalyzer()->getStateFrameCount(state); |
| 531 | } |
| 532 | |
Phil Burk | 7386a83 | 2019-03-21 16:07:27 -0700 | [diff] [blame] | 533 | JNIEXPORT jdouble JNICALL |
| 534 | Java_com_google_sample_oboe_manualtest_GlitchActivity_getSignalToNoiseDB(JNIEnv *env, |
| 535 | jobject instance) { |
Phil Burk | 7386a83 | 2019-03-21 16:07:27 -0700 | [diff] [blame] | 536 | return engine.mActivityGlitches.getGlitchAnalyzer()->getSignalToNoiseDB(); |
| 537 | } |
Phil Burk | e87667d | 2019-04-30 14:01:42 -0700 | [diff] [blame] | 538 | JNIEXPORT jdouble JNICALL |
| 539 | Java_com_google_sample_oboe_manualtest_GlitchActivity_getPeakAmplitude(JNIEnv *env, |
| 540 | jobject instance) { |
| 541 | return engine.mActivityGlitches.getGlitchAnalyzer()->getPeakAmplitude(); |
| 542 | } |
Phil Burk | 7386a83 | 2019-03-21 16:07:27 -0700 | [diff] [blame] | 543 | |
| 544 | } |