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, |
Phil Burk | cd03b99 | 2019-09-20 10:28:20 +0900 | [diff] [blame] | 45 | jint inputPreset, |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 46 | jint deviceId, |
| 47 | jint sessionId, |
| 48 | jint framesPerBurst, |
Phil Burk | 301b066 | 2019-06-06 11:36:30 -0700 | [diff] [blame] | 49 | jboolean channelConversionAllowed, |
Phil Burk | 5927398 | 2019-08-29 09:10:37 -0700 | [diff] [blame] | 50 | jboolean formatConversionAllowed, |
Phil Burk | 301b066 | 2019-06-06 11:36:30 -0700 | [diff] [blame] | 51 | jint rateConversionQuality, |
Phil Burk | 2beb2c7 | 2019-09-05 18:51:14 -0700 | [diff] [blame] | 52 | jboolean isMMap, |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 53 | jboolean isInput); |
| 54 | JNIEXPORT void JNICALL |
Phil Burk | 6c16ce9 | 2019-03-05 16:07:38 -0800 | [diff] [blame] | 55 | Java_com_google_sample_oboe_manualtest_OboeAudioStream_close(JNIEnv *env, jobject, jint); |
Phil Burk | 0af43bb | 2019-03-12 14:11:38 -0700 | [diff] [blame] | 56 | |
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_setThresholdInFrames(JNIEnv *env, jobject, jint, 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_getThresholdInFrames(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_getBufferCapacityInFrames(JNIEnv *env, jobject, jint); |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 63 | JNIEXPORT jint JNICALL |
Phil Burk | 6c16ce9 | 2019-03-05 16:07:38 -0800 | [diff] [blame] | 64 | 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] | 65 | |
| 66 | JNIEXPORT void JNICALL |
| 67 | Java_com_google_sample_oboe_manualtest_OboeAudioStream_setUseCallback(JNIEnv *env, jclass type, |
Phil Burk | 6fb1d80 | 2018-12-21 15:28:07 -0800 | [diff] [blame] | 68 | jboolean useCallback); |
| 69 | JNIEXPORT void JNICALL |
| 70 | Java_com_google_sample_oboe_manualtest_OboeAudioStream_setCallbackReturnStop(JNIEnv *env, |
| 71 | jclass type, |
| 72 | jboolean b); |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 73 | JNIEXPORT void JNICALL |
| 74 | Java_com_google_sample_oboe_manualtest_OboeAudioStream_setCallbackSize(JNIEnv *env, jclass type, |
| 75 | jint callbackSize); |
| 76 | |
| 77 | // ================= OboeAudioOutputStream ================================ |
| 78 | |
| 79 | JNIEXPORT void JNICALL |
Phil Burk | 9102c2a | 2020-11-04 16:19:52 -0800 | [diff] [blame] | 80 | Java_com_google_sample_oboe_manualtest_OboeAudioOutputStream_trigger(JNIEnv *env, jobject); |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 81 | JNIEXPORT void JNICALL |
| 82 | Java_com_google_sample_oboe_manualtest_OboeAudioOutputStream_setToneType(JNIEnv *env, jobject, jint); |
| 83 | JNIEXPORT void JNICALL |
| 84 | Java_com_google_sample_oboe_manualtest_OboeAudioOutputStream_setAmplitude(JNIEnv *env, jobject, jdouble); |
| 85 | |
| 86 | /*********************************************************************************/ |
| 87 | /********************** JNI Implementations *************************************/ |
| 88 | /*********************************************************************************/ |
Phil Burk | 6c16ce9 | 2019-03-05 16:07:38 -0800 | [diff] [blame] | 89 | |
Phil Burk | 2beb2c7 | 2019-09-05 18:51:14 -0700 | [diff] [blame] | 90 | JNIEXPORT jboolean JNICALL |
| 91 | Java_com_google_sample_oboe_manualtest_NativeEngine_isMMapSupported(JNIEnv *env, jclass type) { |
Haibo Huang | c0d5f47 | 2021-02-09 16:44:15 -0800 | [diff] [blame^] | 92 | return oboe::AAudioExtensions::getInstance().isMMapSupported(); |
Phil Burk | 2beb2c7 | 2019-09-05 18:51:14 -0700 | [diff] [blame] | 93 | } |
| 94 | |
Phil Burk | 67f41f0 | 2019-12-10 08:31:44 -0800 | [diff] [blame] | 95 | JNIEXPORT jboolean JNICALL |
| 96 | Java_com_google_sample_oboe_manualtest_NativeEngine_isMMapExclusiveSupported(JNIEnv *env, jclass type) { |
Haibo Huang | c0d5f47 | 2021-02-09 16:44:15 -0800 | [diff] [blame^] | 97 | return oboe::AAudioExtensions::getInstance().isMMapExclusiveSupported(); |
Phil Burk | 67f41f0 | 2019-12-10 08:31:44 -0800 | [diff] [blame] | 98 | } |
| 99 | |
Phil Burk | 236521e | 2019-10-15 07:51:07 -0700 | [diff] [blame] | 100 | JNIEXPORT void JNICALL |
| 101 | Java_com_google_sample_oboe_manualtest_NativeEngine_setWorkaroundsEnabled(JNIEnv *env, jclass type, |
| 102 | jboolean enabled) { |
| 103 | oboe::OboeGlobals::setWorkaroundsEnabled(enabled); |
| 104 | } |
| 105 | |
Phil Burk | 1b08a72 | 2020-06-11 17:54:14 -0700 | [diff] [blame] | 106 | JNIEXPORT jboolean JNICALL |
| 107 | Java_com_google_sample_oboe_manualtest_NativeEngine_areWorkaroundsEnabled(JNIEnv *env, |
| 108 | jclass type) { |
| 109 | return oboe::OboeGlobals::areWorkaroundsEnabled(); |
| 110 | } |
| 111 | |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 112 | JNIEXPORT jint JNICALL |
| 113 | Java_com_google_sample_oboe_manualtest_OboeAudioStream_openNative( |
| 114 | JNIEnv *env, jobject synth, |
Phil Burk | 6c16ce9 | 2019-03-05 16:07:38 -0800 | [diff] [blame] | 115 | jint nativeApi, |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 116 | jint sampleRate, |
| 117 | jint channelCount, |
| 118 | jint format, |
| 119 | jint sharingMode, |
| 120 | jint performanceMode, |
Phil Burk | cd03b99 | 2019-09-20 10:28:20 +0900 | [diff] [blame] | 121 | jint inputPreset, |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 122 | jint deviceId, |
| 123 | jint sessionId, |
| 124 | jint framesPerBurst, |
Phil Burk | 301b066 | 2019-06-06 11:36:30 -0700 | [diff] [blame] | 125 | jboolean channelConversionAllowed, |
Phil Burk | 5927398 | 2019-08-29 09:10:37 -0700 | [diff] [blame] | 126 | jboolean formatConversionAllowed, |
Phil Burk | 301b066 | 2019-06-06 11:36:30 -0700 | [diff] [blame] | 127 | jint rateConversionQuality, |
Phil Burk | 2beb2c7 | 2019-09-05 18:51:14 -0700 | [diff] [blame] | 128 | jboolean isMMap, |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 129 | jboolean isInput) { |
| 130 | LOGD("OboeAudioStream_openNative: sampleRate = %d, framesPerBurst = %d", sampleRate, framesPerBurst); |
| 131 | |
Phil Burk | 0af43bb | 2019-03-12 14:11:38 -0700 | [diff] [blame] | 132 | return (jint) engine.getCurrentActivity()->open(nativeApi, |
Phil Burk | 2beb2c7 | 2019-09-05 18:51:14 -0700 | [diff] [blame] | 133 | sampleRate, |
| 134 | channelCount, |
| 135 | format, |
| 136 | sharingMode, |
| 137 | performanceMode, |
Phil Burk | cd03b99 | 2019-09-20 10:28:20 +0900 | [diff] [blame] | 138 | inputPreset, |
Phil Burk | 2beb2c7 | 2019-09-05 18:51:14 -0700 | [diff] [blame] | 139 | deviceId, |
| 140 | sessionId, |
| 141 | framesPerBurst, |
| 142 | channelConversionAllowed, |
| 143 | formatConversionAllowed, |
| 144 | rateConversionQuality, |
| 145 | isMMap, |
| 146 | isInput); |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | JNIEXPORT jint JNICALL |
Phil Burk | 03bdc0a | 2019-03-06 15:56:25 -0800 | [diff] [blame] | 150 | Java_com_google_sample_oboe_manualtest_TestAudioActivity_startNative(JNIEnv *env, jobject) { |
Phil Burk | 0af43bb | 2019-03-12 14:11:38 -0700 | [diff] [blame] | 151 | return (jint) engine.getCurrentActivity()->start(); |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | JNIEXPORT jint JNICALL |
Phil Burk | 03bdc0a | 2019-03-06 15:56:25 -0800 | [diff] [blame] | 155 | Java_com_google_sample_oboe_manualtest_TestAudioActivity_pauseNative(JNIEnv *env, jobject) { |
Phil Burk | 0af43bb | 2019-03-12 14:11:38 -0700 | [diff] [blame] | 156 | return (jint) engine.getCurrentActivity()->pause(); |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | JNIEXPORT jint JNICALL |
Phil Burk | 03bdc0a | 2019-03-06 15:56:25 -0800 | [diff] [blame] | 160 | Java_com_google_sample_oboe_manualtest_TestAudioActivity_stopNative(JNIEnv *env, jobject) { |
Phil Burk | 0af43bb | 2019-03-12 14:11:38 -0700 | [diff] [blame] | 161 | return (jint) engine.getCurrentActivity()->stop(); |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | JNIEXPORT jint JNICALL |
Phil Burk | 27c7271 | 2020-01-27 09:13:19 -0800 | [diff] [blame] | 165 | Java_com_google_sample_oboe_manualtest_TestAudioActivity_getFramesPerCallback(JNIEnv *env, jobject) { |
| 166 | return (jint) engine.getCurrentActivity()->getFramesPerCallback(); |
| 167 | } |
| 168 | |
| 169 | JNIEXPORT jint JNICALL |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 170 | Java_com_google_sample_oboe_manualtest_OboeAudioStream_startPlaybackNative(JNIEnv *env, jobject) { |
Phil Burk | 0af43bb | 2019-03-12 14:11:38 -0700 | [diff] [blame] | 171 | return (jint) engine.getCurrentActivity()->startPlayback(); |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | JNIEXPORT void JNICALL |
Phil Burk | 6c16ce9 | 2019-03-05 16:07:38 -0800 | [diff] [blame] | 175 | 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] | 176 | engine.getCurrentActivity()->close(streamIndex); |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | JNIEXPORT jint JNICALL |
| 180 | Java_com_google_sample_oboe_manualtest_OboeAudioStream_setBufferSizeInFrames( |
Phil Burk | 6c16ce9 | 2019-03-05 16:07:38 -0800 | [diff] [blame] | 181 | JNIEnv *env, jobject, jint streamIndex, jint threshold) { |
Haibo Huang | c0d5f47 | 2021-02-09 16:44:15 -0800 | [diff] [blame^] | 182 | std::shared_ptr<oboe::AudioStream> oboeStream = engine.getCurrentActivity()->getStream(streamIndex); |
Phil Burk | 6c16ce9 | 2019-03-05 16:07:38 -0800 | [diff] [blame] | 183 | if (oboeStream != nullptr) { |
| 184 | auto result = oboeStream->setBufferSizeInFrames(threshold); |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 185 | return (!result) |
| 186 | ? (jint) result.error() |
| 187 | : (jint) result.value(); |
| 188 | } |
| 189 | return (jint) oboe::Result::ErrorNull; |
| 190 | } |
| 191 | |
| 192 | JNIEXPORT jint JNICALL |
| 193 | Java_com_google_sample_oboe_manualtest_OboeAudioStream_getBufferSizeInFrames( |
Phil Burk | 6c16ce9 | 2019-03-05 16:07:38 -0800 | [diff] [blame] | 194 | JNIEnv *env, jobject, jint streamIndex) { |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 195 | jint result = (jint) oboe::Result::ErrorNull; |
Haibo Huang | c0d5f47 | 2021-02-09 16:44:15 -0800 | [diff] [blame^] | 196 | std::shared_ptr<oboe::AudioStream> oboeStream = engine.getCurrentActivity()->getStream(streamIndex); |
Phil Burk | 6c16ce9 | 2019-03-05 16:07:38 -0800 | [diff] [blame] | 197 | if (oboeStream != nullptr) { |
| 198 | result = oboeStream->getBufferSizeInFrames(); |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 199 | } |
| 200 | return result; |
| 201 | } |
| 202 | |
| 203 | JNIEXPORT jint JNICALL |
| 204 | Java_com_google_sample_oboe_manualtest_OboeAudioStream_getBufferCapacityInFrames( |
Phil Burk | 6c16ce9 | 2019-03-05 16:07:38 -0800 | [diff] [blame] | 205 | JNIEnv *env, jobject, jint streamIndex) { |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 206 | jint result = (jint) oboe::Result::ErrorNull; |
Haibo Huang | c0d5f47 | 2021-02-09 16:44:15 -0800 | [diff] [blame^] | 207 | std::shared_ptr<oboe::AudioStream> oboeStream = engine.getCurrentActivity()->getStream(streamIndex); |
Phil Burk | 6c16ce9 | 2019-03-05 16:07:38 -0800 | [diff] [blame] | 208 | if (oboeStream != nullptr) { |
| 209 | result = oboeStream->getBufferCapacityInFrames(); |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 210 | } |
| 211 | return result; |
| 212 | } |
| 213 | |
| 214 | static int convertAudioApiToNativeApi(oboe::AudioApi audioApi) { |
| 215 | switch(audioApi) { |
| 216 | case oboe::AudioApi::Unspecified: |
| 217 | return NATIVE_MODE_UNSPECIFIED; |
| 218 | case oboe::AudioApi::OpenSLES: |
| 219 | return NATIVE_MODE_OPENSLES; |
| 220 | case oboe::AudioApi::AAudio: |
| 221 | return NATIVE_MODE_AAUDIO; |
| 222 | default: |
| 223 | return -1; |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | JNIEXPORT jint JNICALL |
| 228 | Java_com_google_sample_oboe_manualtest_OboeAudioStream_getNativeApi( |
Phil Burk | 6c16ce9 | 2019-03-05 16:07:38 -0800 | [diff] [blame] | 229 | JNIEnv *env, jobject, jint streamIndex) { |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 230 | jint result = (jint) oboe::Result::ErrorNull; |
Haibo Huang | c0d5f47 | 2021-02-09 16:44:15 -0800 | [diff] [blame^] | 231 | std::shared_ptr<oboe::AudioStream> oboeStream = engine.getCurrentActivity()->getStream(streamIndex); |
Phil Burk | 6c16ce9 | 2019-03-05 16:07:38 -0800 | [diff] [blame] | 232 | if (oboeStream != nullptr) { |
| 233 | oboe::AudioApi audioApi = oboeStream->getAudioApi(); |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 234 | result = convertAudioApiToNativeApi(audioApi); |
| 235 | LOGD("OboeAudioStream_getNativeApi got %d", result); |
| 236 | } |
| 237 | return result; |
| 238 | } |
| 239 | |
| 240 | JNIEXPORT jint JNICALL |
| 241 | Java_com_google_sample_oboe_manualtest_OboeAudioStream_getSampleRate( |
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; |
Haibo Huang | c0d5f47 | 2021-02-09 16:44:15 -0800 | [diff] [blame^] | 244 | std::shared_ptr<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->getSampleRate(); |
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_getSharingMode( |
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; |
Haibo Huang | c0d5f47 | 2021-02-09 16:44:15 -0800 | [diff] [blame^] | 255 | std::shared_ptr<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 = (jint) oboeStream->getSharingMode(); |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 258 | } |
| 259 | return result; |
| 260 | } |
| 261 | |
| 262 | JNIEXPORT jint JNICALL |
| 263 | Java_com_google_sample_oboe_manualtest_OboeAudioStream_getPerformanceMode( |
Phil Burk | 6c16ce9 | 2019-03-05 16:07:38 -0800 | [diff] [blame] | 264 | JNIEnv *env, jobject, jint streamIndex) { |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 265 | jint result = (jint) oboe::Result::ErrorNull; |
Haibo Huang | c0d5f47 | 2021-02-09 16:44:15 -0800 | [diff] [blame^] | 266 | std::shared_ptr<oboe::AudioStream> oboeStream = engine.getCurrentActivity()->getStream(streamIndex); |
Phil Burk | 6c16ce9 | 2019-03-05 16:07:38 -0800 | [diff] [blame] | 267 | if (oboeStream != nullptr) { |
| 268 | result = (jint) oboeStream->getPerformanceMode(); |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 269 | } |
| 270 | return result; |
| 271 | } |
| 272 | |
| 273 | JNIEXPORT jint JNICALL |
Phil Burk | cd03b99 | 2019-09-20 10:28:20 +0900 | [diff] [blame] | 274 | Java_com_google_sample_oboe_manualtest_OboeAudioStream_getInputPreset( |
| 275 | JNIEnv *env, jobject, jint streamIndex) { |
| 276 | jint result = (jint) oboe::Result::ErrorNull; |
Haibo Huang | c0d5f47 | 2021-02-09 16:44:15 -0800 | [diff] [blame^] | 277 | std::shared_ptr<oboe::AudioStream> oboeStream = engine.getCurrentActivity()->getStream(streamIndex); |
Phil Burk | cd03b99 | 2019-09-20 10:28:20 +0900 | [diff] [blame] | 278 | if (oboeStream != nullptr) { |
| 279 | result = (jint) oboeStream->getInputPreset(); |
| 280 | } |
| 281 | return result; |
| 282 | } |
| 283 | |
| 284 | JNIEXPORT jint JNICALL |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 285 | Java_com_google_sample_oboe_manualtest_OboeAudioStream_getFramesPerBurst( |
Phil Burk | 6c16ce9 | 2019-03-05 16:07:38 -0800 | [diff] [blame] | 286 | JNIEnv *env, jobject, jint streamIndex) { |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 287 | jint result = (jint) oboe::Result::ErrorNull; |
Haibo Huang | c0d5f47 | 2021-02-09 16:44:15 -0800 | [diff] [blame^] | 288 | std::shared_ptr<oboe::AudioStream> oboeStream = engine.getCurrentActivity()->getStream(streamIndex); |
Phil Burk | 6c16ce9 | 2019-03-05 16:07:38 -0800 | [diff] [blame] | 289 | if (oboeStream != nullptr) { |
| 290 | result = oboeStream->getFramesPerBurst(); |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 291 | } |
| 292 | return result; |
| 293 | } |
| 294 | |
| 295 | JNIEXPORT jint JNICALL |
| 296 | Java_com_google_sample_oboe_manualtest_OboeAudioStream_getChannelCount( |
Phil Burk | 6c16ce9 | 2019-03-05 16:07:38 -0800 | [diff] [blame] | 297 | JNIEnv *env, jobject, jint streamIndex) { |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 298 | jint result = (jint) oboe::Result::ErrorNull; |
Haibo Huang | c0d5f47 | 2021-02-09 16:44:15 -0800 | [diff] [blame^] | 299 | std::shared_ptr<oboe::AudioStream> oboeStream = engine.getCurrentActivity()->getStream(streamIndex); |
Phil Burk | 6c16ce9 | 2019-03-05 16:07:38 -0800 | [diff] [blame] | 300 | if (oboeStream != nullptr) { |
| 301 | result = oboeStream->getChannelCount(); |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 302 | } |
| 303 | return result; |
| 304 | } |
| 305 | |
| 306 | JNIEXPORT jint JNICALL |
Phil Burk | 6c16ce9 | 2019-03-05 16:07:38 -0800 | [diff] [blame] | 307 | 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] | 308 | jint result = (jint) oboe::Result::ErrorNull; |
Haibo Huang | c0d5f47 | 2021-02-09 16:44:15 -0800 | [diff] [blame^] | 309 | std::shared_ptr<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 = (jint) oboeStream->getFormat(); |
| 312 | } |
| 313 | return result; |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 314 | } |
| 315 | |
| 316 | JNIEXPORT jint JNICALL |
| 317 | Java_com_google_sample_oboe_manualtest_OboeAudioStream_getDeviceId( |
Phil Burk | 6c16ce9 | 2019-03-05 16:07:38 -0800 | [diff] [blame] | 318 | JNIEnv *env, jobject, jint streamIndex) { |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 319 | jint result = (jint) oboe::Result::ErrorNull; |
Haibo Huang | c0d5f47 | 2021-02-09 16:44:15 -0800 | [diff] [blame^] | 320 | std::shared_ptr<oboe::AudioStream> oboeStream = engine.getCurrentActivity()->getStream(streamIndex); |
Phil Burk | 6c16ce9 | 2019-03-05 16:07:38 -0800 | [diff] [blame] | 321 | if (oboeStream != nullptr) { |
| 322 | result = oboeStream->getDeviceId(); |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 323 | } |
| 324 | return result; |
| 325 | } |
| 326 | |
| 327 | JNIEXPORT jint JNICALL |
| 328 | Java_com_google_sample_oboe_manualtest_OboeAudioStream_getSessionId( |
Phil Burk | 6c16ce9 | 2019-03-05 16:07:38 -0800 | [diff] [blame] | 329 | JNIEnv *env, jobject, jint streamIndex) { |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 330 | jint result = (jint) oboe::Result::ErrorNull; |
Haibo Huang | c0d5f47 | 2021-02-09 16:44:15 -0800 | [diff] [blame^] | 331 | std::shared_ptr<oboe::AudioStream> oboeStream = engine.getCurrentActivity()->getStream(streamIndex); |
Phil Burk | 6c16ce9 | 2019-03-05 16:07:38 -0800 | [diff] [blame] | 332 | if (oboeStream != nullptr) { |
| 333 | result = oboeStream->getSessionId(); |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 334 | } |
| 335 | return result; |
| 336 | } |
| 337 | |
| 338 | JNIEXPORT jlong JNICALL |
| 339 | Java_com_google_sample_oboe_manualtest_OboeAudioStream_getFramesWritten( |
Phil Burk | 6c16ce9 | 2019-03-05 16:07:38 -0800 | [diff] [blame] | 340 | JNIEnv *env, jobject, jint streamIndex) { |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 341 | jlong result = (jint) oboe::Result::ErrorNull; |
Haibo Huang | c0d5f47 | 2021-02-09 16:44:15 -0800 | [diff] [blame^] | 342 | std::shared_ptr<oboe::AudioStream> oboeStream = engine.getCurrentActivity()->getStream(streamIndex); |
Phil Burk | 6c16ce9 | 2019-03-05 16:07:38 -0800 | [diff] [blame] | 343 | if (oboeStream != nullptr) { |
| 344 | result = oboeStream->getFramesWritten(); |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 345 | } |
| 346 | return result; |
| 347 | } |
| 348 | |
| 349 | JNIEXPORT jlong JNICALL |
| 350 | Java_com_google_sample_oboe_manualtest_OboeAudioStream_getFramesRead( |
Phil Burk | 6c16ce9 | 2019-03-05 16:07:38 -0800 | [diff] [blame] | 351 | JNIEnv *env, jobject, jint streamIndex) { |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 352 | jlong result = (jlong) oboe::Result::ErrorNull; |
Haibo Huang | c0d5f47 | 2021-02-09 16:44:15 -0800 | [diff] [blame^] | 353 | std::shared_ptr<oboe::AudioStream> oboeStream = engine.getCurrentActivity()->getStream(streamIndex); |
Phil Burk | 6c16ce9 | 2019-03-05 16:07:38 -0800 | [diff] [blame] | 354 | if (oboeStream != nullptr) { |
| 355 | result = oboeStream->getFramesRead(); |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 356 | } |
| 357 | return result; |
| 358 | } |
| 359 | |
Phil Burk | 5cb621f | 2019-02-14 17:51:30 -0800 | [diff] [blame] | 360 | JNIEXPORT jint JNICALL |
| 361 | Java_com_google_sample_oboe_manualtest_OboeAudioStream_getXRunCount( |
Phil Burk | 6c16ce9 | 2019-03-05 16:07:38 -0800 | [diff] [blame] | 362 | JNIEnv *env, jobject, jint streamIndex) { |
Phil Burk | 5cb621f | 2019-02-14 17:51:30 -0800 | [diff] [blame] | 363 | jint result = (jlong) oboe::Result::ErrorNull; |
Haibo Huang | c0d5f47 | 2021-02-09 16:44:15 -0800 | [diff] [blame^] | 364 | std::shared_ptr<oboe::AudioStream> oboeStream = engine.getCurrentActivity()->getStream(streamIndex); |
Phil Burk | 6c16ce9 | 2019-03-05 16:07:38 -0800 | [diff] [blame] | 365 | if (oboeStream != nullptr) { |
| 366 | auto oboeResult = oboeStream->getXRunCount(); |
Phil Burk | 5cb621f | 2019-02-14 17:51:30 -0800 | [diff] [blame] | 367 | if (!oboeResult) { |
| 368 | result = (jint) oboeResult.error(); |
| 369 | } else { |
| 370 | result = oboeResult.value(); |
| 371 | } |
| 372 | } |
| 373 | return result; |
| 374 | } |
| 375 | |
Phil Burk | 6fb1d80 | 2018-12-21 15:28:07 -0800 | [diff] [blame] | 376 | JNIEXPORT jlong JNICALL |
| 377 | Java_com_google_sample_oboe_manualtest_OboeAudioStream_getCallbackCount( |
| 378 | JNIEnv *env, jobject) { |
Phil Burk | 0af43bb | 2019-03-12 14:11:38 -0700 | [diff] [blame] | 379 | return engine.getCurrentActivity()->getCallbackCount(); |
Phil Burk | 6fb1d80 | 2018-12-21 15:28:07 -0800 | [diff] [blame] | 380 | } |
| 381 | |
Phil Burk | 5617ca6 | 2020-10-12 07:14:06 -0700 | [diff] [blame] | 382 | JNIEXPORT jint JNICALL |
| 383 | Java_com_google_sample_oboe_manualtest_OboeAudioStream_getLastErrorCallbackResult( |
Phil Burk | 7b814ba | 2020-11-11 07:30:52 -0800 | [diff] [blame] | 384 | JNIEnv *env, jobject, jint streamIndex) { |
Haibo Huang | c0d5f47 | 2021-02-09 16:44:15 -0800 | [diff] [blame^] | 385 | std::shared_ptr<oboe::AudioStream> oboeStream = engine.getCurrentActivity()->getStream(streamIndex); |
Phil Burk | 7b814ba | 2020-11-11 07:30:52 -0800 | [diff] [blame] | 386 | if (oboeStream != nullptr) { |
| 387 | return (jint) oboeStream->getLastErrorCallbackResult(); |
| 388 | } |
| 389 | return 0; |
Phil Burk | 5617ca6 | 2020-10-12 07:14:06 -0700 | [diff] [blame] | 390 | } |
| 391 | |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 392 | JNIEXPORT jdouble JNICALL |
Haibo Huang | c0d5f47 | 2021-02-09 16:44:15 -0800 | [diff] [blame^] | 393 | Java_com_google_sample_oboe_manualtest_OboeAudioStream_getTimestampLatency(JNIEnv *env, |
| 394 | jobject instance, |
| 395 | jint streamIndex) { |
| 396 | return engine.getCurrentActivity()->getTimestampLatency(streamIndex); |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 397 | } |
| 398 | |
Phil Burk | 8e03882 | 2020-02-25 15:00:59 -0800 | [diff] [blame] | 399 | JNIEXPORT jdouble JNICALL |
| 400 | Java_com_google_sample_oboe_manualtest_OboeAudioStream_getCpuLoad(JNIEnv *env, jobject instance, jint streamIndex) { |
| 401 | return engine.getCurrentActivity()->getCpuLoad(); |
| 402 | } |
| 403 | |
Phil Burk | 0f94ca1 | 2019-12-21 15:13:40 -0800 | [diff] [blame] | 404 | JNIEXPORT void JNICALL |
| 405 | Java_com_google_sample_oboe_manualtest_OboeAudioStream_setWorkload( |
| 406 | JNIEnv *env, jobject, jdouble workload) { |
| 407 | engine.getCurrentActivity()->setWorkload(workload); |
| 408 | } |
| 409 | |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 410 | JNIEXPORT jint JNICALL |
Phil Burk | 6c16ce9 | 2019-03-05 16:07:38 -0800 | [diff] [blame] | 411 | Java_com_google_sample_oboe_manualtest_OboeAudioStream_getState(JNIEnv *env, jobject instance, jint streamIndex) { |
Haibo Huang | c0d5f47 | 2021-02-09 16:44:15 -0800 | [diff] [blame^] | 412 | std::shared_ptr<oboe::AudioStream> oboeStream = engine.getCurrentActivity()->getStream(streamIndex); |
Phil Burk | 6c16ce9 | 2019-03-05 16:07:38 -0800 | [diff] [blame] | 413 | if (oboeStream != nullptr) { |
| 414 | auto state = oboeStream->getState(); |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 415 | if (state != oboe::StreamState::Starting && state != oboe::StreamState::Started) { |
Phil Burk | 6c16ce9 | 2019-03-05 16:07:38 -0800 | [diff] [blame] | 416 | oboe::Result result = oboeStream->waitForStateChange( |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 417 | oboe::StreamState::Uninitialized, |
| 418 | &state, 0); |
Don Turner | 5c42747 | 2019-11-15 15:59:25 +0000 | [diff] [blame] | 419 | |
| 420 | if (result != oboe::Result::OK){ |
| 421 | if (result == oboe::Result::ErrorClosed) { |
| 422 | state = oboe::StreamState::Closed; |
| 423 | } else if (result == oboe::Result::ErrorDisconnected){ |
| 424 | state = oboe::StreamState::Disconnected; |
| 425 | } else { |
| 426 | state = oboe::StreamState::Unknown; |
| 427 | } |
| 428 | } |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 429 | } |
| 430 | return (jint) state; |
| 431 | } |
| 432 | return -1; |
| 433 | } |
| 434 | |
| 435 | JNIEXPORT jdouble JNICALL |
| 436 | Java_com_google_sample_oboe_manualtest_AudioInputTester_getPeakLevel(JNIEnv *env, |
| 437 | jobject instance, |
| 438 | jint index) { |
Phil Burk | 0af43bb | 2019-03-12 14:11:38 -0700 | [diff] [blame] | 439 | return engine.getCurrentActivity()->getPeakLevel(index); |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | JNIEXPORT void JNICALL |
| 443 | Java_com_google_sample_oboe_manualtest_OboeAudioStream_setUseCallback(JNIEnv *env, jclass type, |
Phil Burk | 6fb1d80 | 2018-12-21 15:28:07 -0800 | [diff] [blame] | 444 | jboolean useCallback) { |
Phil Burk | bd76d6a | 2019-06-01 08:48:03 -0700 | [diff] [blame] | 445 | ActivityContext::mUseCallback = useCallback; |
Phil Burk | 6fb1d80 | 2018-12-21 15:28:07 -0800 | [diff] [blame] | 446 | } |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 447 | |
Phil Burk | 6fb1d80 | 2018-12-21 15:28:07 -0800 | [diff] [blame] | 448 | JNIEXPORT void JNICALL |
| 449 | Java_com_google_sample_oboe_manualtest_OboeAudioStream_setCallbackReturnStop(JNIEnv *env, jclass type, |
| 450 | jboolean b) { |
Phil Burk | 6f1d5c1 | 2019-04-05 15:33:07 -0700 | [diff] [blame] | 451 | OboeStreamCallbackProxy::setCallbackReturnStop(b); |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 452 | } |
| 453 | |
| 454 | JNIEXPORT void JNICALL |
| 455 | Java_com_google_sample_oboe_manualtest_OboeAudioStream_setCallbackSize(JNIEnv *env, jclass type, |
| 456 | jint callbackSize) { |
Phil Burk | 0af43bb | 2019-03-12 14:11:38 -0700 | [diff] [blame] | 457 | ActivityContext::callbackSize = callbackSize; |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 458 | } |
| 459 | |
| 460 | JNIEXPORT jboolean JNICALL |
Phil Burk | 6c16ce9 | 2019-03-05 16:07:38 -0800 | [diff] [blame] | 461 | 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] | 462 | return engine.getCurrentActivity()->isMMapUsed(streamIndex); |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 463 | } |
| 464 | |
| 465 | // ================= OboeAudioOutputStream ================================ |
| 466 | |
| 467 | JNIEXPORT void JNICALL |
Phil Burk | 9102c2a | 2020-11-04 16:19:52 -0800 | [diff] [blame] | 468 | Java_com_google_sample_oboe_manualtest_OboeAudioOutputStream_trigger( |
| 469 | JNIEnv *env, jobject) { |
| 470 | engine.getCurrentActivity()->trigger(); |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 471 | } |
| 472 | |
| 473 | JNIEXPORT void JNICALL |
Phil Burk | e5985ed | 2018-12-06 11:38:30 -0800 | [diff] [blame] | 474 | Java_com_google_sample_oboe_manualtest_OboeAudioOutputStream_setChannelEnabled( |
| 475 | JNIEnv *env, jobject, jint channelIndex, jboolean enabled) { |
Phil Burk | 0af43bb | 2019-03-12 14:11:38 -0700 | [diff] [blame] | 476 | engine.getCurrentActivity()->setChannelEnabled(channelIndex, enabled); |
Phil Burk | e5985ed | 2018-12-06 11:38:30 -0800 | [diff] [blame] | 477 | } |
| 478 | |
Phil Burk | 0a784e6 | 2019-07-20 12:43:15 -0700 | [diff] [blame] | 479 | JNIEXPORT void JNICALL |
| 480 | Java_com_google_sample_oboe_manualtest_OboeAudioOutputStream_setSignalType( |
| 481 | JNIEnv *env, jobject, jint signalType) { |
| 482 | engine.getCurrentActivity()->setSignalType(signalType); |
| 483 | } |
| 484 | |
Phil Burk | b8356bb | 2019-11-06 11:11:07 -0800 | [diff] [blame] | 485 | JNIEXPORT jint JNICALL |
| 486 | Java_com_google_sample_oboe_manualtest_OboeAudioStream_getOboeVersionNumber(JNIEnv *env, |
| 487 | jclass type) { |
| 488 | return OBOE_VERSION_NUMBER; |
| 489 | } |
| 490 | |
Phil Burk | 7386a83 | 2019-03-21 16:07:27 -0700 | [diff] [blame] | 491 | // ========================================================================== |
Phil Burk | 03bdc0a | 2019-03-06 15:56:25 -0800 | [diff] [blame] | 492 | JNIEXPORT void JNICALL |
| 493 | Java_com_google_sample_oboe_manualtest_TestAudioActivity_setActivityType(JNIEnv *env, |
| 494 | jobject instance, |
| 495 | jint activityType) { |
| 496 | engine.setActivityType(activityType); |
| 497 | } |
| 498 | |
Phil Burk | 7386a83 | 2019-03-21 16:07:27 -0700 | [diff] [blame] | 499 | // ========================================================================== |
Phil Burk | 327361c | 2019-04-13 14:45:27 -0700 | [diff] [blame] | 500 | JNIEXPORT jint JNICALL |
| 501 | Java_com_google_sample_oboe_manualtest_TestInputActivity_saveWaveFile(JNIEnv *env, |
| 502 | jobject instance, |
| 503 | jstring fileName) { |
| 504 | const char *str = env->GetStringUTFChars(fileName, nullptr); |
| 505 | LOGD("nativeSaveFile(%s)", str); |
| 506 | jint result = engine.getCurrentActivity()->saveWaveFile(str); |
| 507 | env->ReleaseStringUTFChars(fileName, str); |
| 508 | return result; |
| 509 | } |
| 510 | |
| 511 | // ========================================================================== |
Phil Burk | 1d17a60 | 2019-03-12 15:37:56 -0700 | [diff] [blame] | 512 | JNIEXPORT void JNICALL |
Phil Burk | bbde5bb | 2019-09-02 16:00:18 -0700 | [diff] [blame] | 513 | Java_com_google_sample_oboe_manualtest_TestInputActivity_setMinimumFramesBeforeRead(JNIEnv *env, |
| 514 | jobject instance, |
| 515 | jint numFrames) { |
| 516 | engine.getCurrentActivity()->setMinimumFramesBeforeRead(numFrames); |
| 517 | } |
| 518 | |
| 519 | // ========================================================================== |
| 520 | JNIEXPORT void JNICALL |
Phil Burk | 1d17a60 | 2019-03-12 15:37:56 -0700 | [diff] [blame] | 521 | Java_com_google_sample_oboe_manualtest_EchoActivity_setDelayTime(JNIEnv *env, |
| 522 | jobject instance, |
| 523 | jdouble delayTimeSeconds) { |
| 524 | engine.setDelayTime(delayTimeSeconds); |
| 525 | } |
| 526 | |
Haibo Huang | c0d5f47 | 2021-02-09 16:44:15 -0800 | [diff] [blame^] | 527 | JNIEXPORT int JNICALL |
| 528 | Java_com_google_sample_oboe_manualtest_EchoActivity_getColdStartInputMillis(JNIEnv *env, |
| 529 | jobject instance) { |
| 530 | return engine.getCurrentActivity()->getColdStartInputMillis(); |
| 531 | } |
| 532 | |
| 533 | JNIEXPORT int JNICALL |
| 534 | Java_com_google_sample_oboe_manualtest_EchoActivity_getColdStartOutputMillis(JNIEnv *env, |
| 535 | jobject instance) { |
| 536 | return engine.getCurrentActivity()->getColdStartOutputMillis(); |
| 537 | } |
| 538 | |
Phil Burk | 7386a83 | 2019-03-21 16:07:27 -0700 | [diff] [blame] | 539 | // ========================================================================== |
Phil Burk | 80d83d8 | 2019-03-15 12:03:37 -0700 | [diff] [blame] | 540 | JNIEXPORT jint JNICALL |
| 541 | Java_com_google_sample_oboe_manualtest_RoundTripLatencyActivity_getAnalyzerProgress(JNIEnv *env, |
Phil Burk | 3873e88 | 2019-03-18 10:15:13 -0700 | [diff] [blame] | 542 | jobject instance) { |
Phil Burk | d2dd527 | 2019-03-18 16:05:25 -0700 | [diff] [blame] | 543 | return engine.mActivityRoundTripLatency.getLatencyAnalyzer()->getProgress(); |
Phil Burk | 80d83d8 | 2019-03-15 12:03:37 -0700 | [diff] [blame] | 544 | } |
| 545 | |
Phil Burk | cd12e2c | 2019-07-29 20:39:42 -0700 | [diff] [blame] | 546 | JNIEXPORT jint JNICALL |
Phil Burk | 80d83d8 | 2019-03-15 12:03:37 -0700 | [diff] [blame] | 547 | Java_com_google_sample_oboe_manualtest_RoundTripLatencyActivity_getMeasuredLatency(JNIEnv *env, |
| 548 | jobject instance) { |
Phil Burk | d2dd527 | 2019-03-18 16:05:25 -0700 | [diff] [blame] | 549 | return engine.mActivityRoundTripLatency.getLatencyAnalyzer()->getMeasuredLatency(); |
Phil Burk | 80d83d8 | 2019-03-15 12:03:37 -0700 | [diff] [blame] | 550 | } |
| 551 | |
| 552 | JNIEXPORT jdouble JNICALL |
| 553 | Java_com_google_sample_oboe_manualtest_RoundTripLatencyActivity_getMeasuredConfidence(JNIEnv *env, |
Phil Burk | d2dd527 | 2019-03-18 16:05:25 -0700 | [diff] [blame] | 554 | jobject instance) { |
| 555 | return engine.mActivityRoundTripLatency.getLatencyAnalyzer()->getMeasuredConfidence(); |
| 556 | } |
| 557 | |
Phil Burk | cd12e2c | 2019-07-29 20:39:42 -0700 | [diff] [blame] | 558 | JNIEXPORT jdouble JNICALL |
| 559 | Java_com_google_sample_oboe_manualtest_RoundTripLatencyActivity_getBackgroundRMS(JNIEnv *env, |
| 560 | jobject instance) { |
| 561 | return engine.mActivityRoundTripLatency.getLatencyAnalyzer()->getBackgroundRMS(); |
| 562 | } |
| 563 | |
| 564 | JNIEXPORT jdouble JNICALL |
| 565 | Java_com_google_sample_oboe_manualtest_RoundTripLatencyActivity_getSignalRMS(JNIEnv *env, |
| 566 | jobject instance) { |
| 567 | return engine.mActivityRoundTripLatency.getLatencyAnalyzer()->getSignalRMS(); |
| 568 | } |
| 569 | |
| 570 | JNIEXPORT jint JNICALL |
| 571 | Java_com_google_sample_oboe_manualtest_AnalyzerActivity_getMeasuredResult(JNIEnv *env, |
| 572 | jobject instance) { |
| 573 | return engine.mActivityRoundTripLatency.getLatencyAnalyzer()->getResult(); |
| 574 | } |
| 575 | |
Phil Burk | 7386a83 | 2019-03-21 16:07:27 -0700 | [diff] [blame] | 576 | // ========================================================================== |
Phil Burk | d2dd527 | 2019-03-18 16:05:25 -0700 | [diff] [blame] | 577 | JNIEXPORT jint JNICALL |
Phil Burk | 7386a83 | 2019-03-21 16:07:27 -0700 | [diff] [blame] | 578 | Java_com_google_sample_oboe_manualtest_AnalyzerActivity_getAnalyzerState(JNIEnv *env, |
| 579 | jobject instance) { |
| 580 | return ((ActivityFullDuplex *)engine.getCurrentActivity())->getState(); |
| 581 | } |
| 582 | |
| 583 | JNIEXPORT jboolean JNICALL |
| 584 | Java_com_google_sample_oboe_manualtest_AnalyzerActivity_isAnalyzerDone(JNIEnv *env, |
| 585 | jobject instance) { |
| 586 | return ((ActivityFullDuplex *)engine.getCurrentActivity())->isAnalyzerDone(); |
| 587 | } |
| 588 | |
| 589 | JNIEXPORT jint JNICALL |
Phil Burk | cd81832 | 2019-03-22 16:51:40 -0700 | [diff] [blame] | 590 | Java_com_google_sample_oboe_manualtest_AnalyzerActivity_getResetCount(JNIEnv *env, |
| 591 | jobject instance) { |
| 592 | return ((ActivityFullDuplex *)engine.getCurrentActivity())->getResetCount(); |
| 593 | } |
Phil Burk | 7386a83 | 2019-03-21 16:07:27 -0700 | [diff] [blame] | 594 | |
| 595 | // ========================================================================== |
| 596 | JNIEXPORT jint JNICALL |
| 597 | Java_com_google_sample_oboe_manualtest_GlitchActivity_getGlitchCount(JNIEnv *env, |
| 598 | jobject instance) { |
Phil Burk | 7386a83 | 2019-03-21 16:07:27 -0700 | [diff] [blame] | 599 | return engine.mActivityGlitches.getGlitchAnalyzer()->getGlitchCount(); |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 600 | } |
Phil Burk | 7386a83 | 2019-03-21 16:07:27 -0700 | [diff] [blame] | 601 | |
Phil Burk | bbde5bb | 2019-09-02 16:00:18 -0700 | [diff] [blame] | 602 | JNIEXPORT jint JNICALL |
| 603 | Java_com_google_sample_oboe_manualtest_GlitchActivity_getStateFrameCount(JNIEnv *env, |
| 604 | jobject instance, |
| 605 | jint state) { |
| 606 | return engine.mActivityGlitches.getGlitchAnalyzer()->getStateFrameCount(state); |
| 607 | } |
| 608 | |
Phil Burk | 7386a83 | 2019-03-21 16:07:27 -0700 | [diff] [blame] | 609 | JNIEXPORT jdouble JNICALL |
| 610 | Java_com_google_sample_oboe_manualtest_GlitchActivity_getSignalToNoiseDB(JNIEnv *env, |
| 611 | jobject instance) { |
Phil Burk | 7386a83 | 2019-03-21 16:07:27 -0700 | [diff] [blame] | 612 | return engine.mActivityGlitches.getGlitchAnalyzer()->getSignalToNoiseDB(); |
| 613 | } |
Haibo Huang | c0d5f47 | 2021-02-09 16:44:15 -0800 | [diff] [blame^] | 614 | |
Phil Burk | e87667d | 2019-04-30 14:01:42 -0700 | [diff] [blame] | 615 | JNIEXPORT jdouble JNICALL |
| 616 | Java_com_google_sample_oboe_manualtest_GlitchActivity_getPeakAmplitude(JNIEnv *env, |
Phil Burk | af0c19f | 2019-09-22 17:18:23 +0800 | [diff] [blame] | 617 | jobject instance) { |
Phil Burk | e87667d | 2019-04-30 14:01:42 -0700 | [diff] [blame] | 618 | return engine.mActivityGlitches.getGlitchAnalyzer()->getPeakAmplitude(); |
| 619 | } |
Phil Burk | 7386a83 | 2019-03-21 16:07:27 -0700 | [diff] [blame] | 620 | |
Haibo Huang | c0d5f47 | 2021-02-09 16:44:15 -0800 | [diff] [blame^] | 621 | JNIEXPORT jdouble JNICALL |
| 622 | Java_com_google_sample_oboe_manualtest_TestDataPathsActivity_getMagnitude(JNIEnv *env, |
| 623 | jobject instance) { |
| 624 | return engine.mActivityDataPath.getDataPathAnalyzer()->getMagnitude(); |
| 625 | } |
| 626 | |
| 627 | JNIEXPORT jdouble JNICALL |
| 628 | Java_com_google_sample_oboe_manualtest_TestDataPathsActivity_getMaxMagnitude(JNIEnv *env, |
| 629 | jobject instance) { |
| 630 | return engine.mActivityDataPath.getDataPathAnalyzer()->getMaxMagnitude(); |
| 631 | } |
| 632 | |
| 633 | JNIEXPORT jdouble JNICALL |
| 634 | Java_com_google_sample_oboe_manualtest_TestDataPathsActivity_getPhase(JNIEnv *env, |
| 635 | jobject instance) { |
| 636 | return engine.mActivityDataPath.getDataPathAnalyzer()->getPhaseOffset(); |
| 637 | } |
| 638 | |
Phil Burk | af0c19f | 2019-09-22 17:18:23 +0800 | [diff] [blame] | 639 | JNIEXPORT void JNICALL |
| 640 | Java_com_google_sample_oboe_manualtest_GlitchActivity_setTolerance(JNIEnv *env, |
| 641 | jobject instance, |
| 642 | jfloat tolerance) { |
| 643 | if (engine.mActivityGlitches.getGlitchAnalyzer()) { |
| 644 | engine.mActivityGlitches.getGlitchAnalyzer()->setTolerance(tolerance); |
| 645 | } |
| 646 | } |
| 647 | |
Haibo Huang | c0d5f47 | 2021-02-09 16:44:15 -0800 | [diff] [blame^] | 648 | JNIEXPORT void JNICALL |
| 649 | Java_com_google_sample_oboe_manualtest_GlitchActivity_setInputChannelNative(JNIEnv *env, |
| 650 | jobject instance, |
| 651 | jint channel) { |
| 652 | if (engine.mActivityGlitches.getGlitchAnalyzer()) { |
| 653 | engine.mActivityGlitches.getGlitchAnalyzer()->setInputChannel(channel); |
| 654 | } |
| 655 | if (engine.mActivityDataPath.getDataPathAnalyzer()) { |
| 656 | engine.mActivityDataPath.getDataPathAnalyzer()->setInputChannel(channel); |
| 657 | } |
| 658 | } |
| 659 | |
| 660 | JNIEXPORT void JNICALL |
| 661 | Java_com_google_sample_oboe_manualtest_GlitchActivity_setOutputChannelNative(JNIEnv *env, |
| 662 | jobject instance, |
| 663 | jint channel) { |
| 664 | if (engine.mActivityGlitches.getGlitchAnalyzer()) { |
| 665 | engine.mActivityGlitches.getGlitchAnalyzer()->setOutputChannel(channel); |
| 666 | } |
| 667 | if (engine.mActivityDataPath.getDataPathAnalyzer()) { |
| 668 | engine.mActivityDataPath.getDataPathAnalyzer()->setOutputChannel(channel); |
| 669 | } |
| 670 | } |
| 671 | |
Phil Burk | 5686874 | 2019-11-21 20:19:53 +0000 | [diff] [blame] | 672 | JNIEXPORT jint JNICALL |
| 673 | Java_com_google_sample_oboe_manualtest_ManualGlitchActivity_getGlitch(JNIEnv *env, jobject instance, |
| 674 | jfloatArray waveform_) { |
Phil Burk | 6ff9266 | 2019-11-25 15:47:58 -0800 | [diff] [blame] | 675 | float *waveform = env->GetFloatArrayElements(waveform_, nullptr); |
Phil Burk | 5686874 | 2019-11-21 20:19:53 +0000 | [diff] [blame] | 676 | jsize length = env->GetArrayLength(waveform_); |
| 677 | jsize numSamples = 0; |
| 678 | auto *analyzer = engine.mActivityGlitches.getGlitchAnalyzer(); |
| 679 | if (analyzer) { |
| 680 | numSamples = analyzer->getLastGlitch(waveform, length); |
| 681 | } |
| 682 | |
| 683 | env->ReleaseFloatArrayElements(waveform_, waveform, 0); |
| 684 | return numSamples; |
| 685 | } |
| 686 | |
| 687 | } |