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 <sys/sysinfo.h>
24 #include <thread>
25
26 #include "common/AdpfWrapper.h"
27 #include "common/OboeDebug.h"
28 #include "oboe/Oboe.h"
29
30 #include "NativeAudioContext.h"
31 #include "TestColdStartLatency.h"
32 #include "TestErrorCallback.h"
33 #include "TestRoutingCrash.h"
34
35 static NativeAudioContext engine;
36
37 /*********************************************************************************/
38 /********************** JNI Prototypes *****************************************/
39 /*********************************************************************************/
40 extern "C" {
41
42 JNIEXPORT jint JNICALL
43 Java_com_mobileer_oboetester_OboeAudioStream_openNative(JNIEnv *env, jobject,
44 jint nativeApi,
45 jint sampleRate,
46 jint channelCount,
47 jint channelMask,
48 jint format,
49 jint sharingMode,
50 jint performanceMode,
51 jint inputPreset,
52 jint usage,
53 jint contentType,
54 jint bufferCapacityInFrames,
55 jint deviceId,
56 jint sessionId,
57 jboolean channelConversionAllowed,
58 jboolean formatConversionAllowed,
59 jint rateConversionQuality,
60 jboolean isMMap,
61 jboolean isInput);
62 JNIEXPORT void JNICALL
63 Java_com_mobileer_oboetester_OboeAudioStream_close(JNIEnv *env, jobject, jint);
64
65 JNIEXPORT jint JNICALL
66 Java_com_mobileer_oboetester_OboeAudioStream_setThresholdInFrames(JNIEnv *env, jobject, jint, jint);
67 JNIEXPORT jint JNICALL
68 Java_com_mobileer_oboetester_OboeAudioStream_getThresholdInFrames(JNIEnv *env, jobject, jint);
69 JNIEXPORT jint JNICALL
70 Java_com_mobileer_oboetester_OboeAudioStream_getBufferCapacityInFrames(JNIEnv *env, jobject, jint);
71 JNIEXPORT jint JNICALL
72 Java_com_mobileer_oboetester_OboeAudioStream_setNativeApi(JNIEnv *env, jobject, jint, jint);
73
74 JNIEXPORT void JNICALL
75 Java_com_mobileer_oboetester_OboeAudioStream_setUseCallback(JNIEnv *env, jclass type,
76 jboolean useCallback);
77 JNIEXPORT void JNICALL
78 Java_com_mobileer_oboetester_OboeAudioStream_setCallbackReturnStop(JNIEnv *env,
79 jclass type,
80 jboolean b);
81 JNIEXPORT void JNICALL
82 Java_com_mobileer_oboetester_OboeAudioStream_setCallbackSize(JNIEnv *env, jclass type,
83 jint callbackSize);
84
85 // ================= OboeAudioOutputStream ================================
86
87 JNIEXPORT void JNICALL
88 Java_com_mobileer_oboetester_OboeAudioOutputStream_trigger(JNIEnv *env, jobject);
89 JNIEXPORT void JNICALL
90 Java_com_mobileer_oboetester_OboeAudioOutputStream_setToneType(JNIEnv *env, jobject, jint);
91 JNIEXPORT void JNICALL
92 Java_com_mobileer_oboetester_OboeAudioOutputStream_setAmplitude(JNIEnv *env, jobject, jfloat);
93
94 /*********************************************************************************/
95 /********************** JNI Implementations *************************************/
96 /*********************************************************************************/
97
98 JNIEXPORT jboolean JNICALL
Java_com_mobileer_oboetester_NativeEngine_isMMapSupported(JNIEnv * env,jclass type)99 Java_com_mobileer_oboetester_NativeEngine_isMMapSupported(JNIEnv *env, jclass type) {
100 return oboe::AAudioExtensions::getInstance().isMMapSupported();
101 }
102
103 JNIEXPORT jboolean JNICALL
Java_com_mobileer_oboetester_NativeEngine_isMMapExclusiveSupported(JNIEnv * env,jclass type)104 Java_com_mobileer_oboetester_NativeEngine_isMMapExclusiveSupported(JNIEnv *env, jclass type) {
105 return oboe::AAudioExtensions::getInstance().isMMapExclusiveSupported();
106 }
107
108 JNIEXPORT void JNICALL
Java_com_mobileer_oboetester_NativeEngine_setWorkaroundsEnabled(JNIEnv * env,jclass type,jboolean enabled)109 Java_com_mobileer_oboetester_NativeEngine_setWorkaroundsEnabled(JNIEnv *env, jclass type,
110 jboolean enabled) {
111 oboe::OboeGlobals::setWorkaroundsEnabled(enabled);
112 }
113
114 JNIEXPORT jboolean JNICALL
Java_com_mobileer_oboetester_NativeEngine_areWorkaroundsEnabled(JNIEnv * env,jclass type)115 Java_com_mobileer_oboetester_NativeEngine_areWorkaroundsEnabled(JNIEnv *env,
116 jclass type) {
117 return oboe::OboeGlobals::areWorkaroundsEnabled();
118 }
119
120 JNIEXPORT jint JNICALL
Java_com_mobileer_oboetester_NativeEngine_getCpuCount(JNIEnv * env,jclass type)121 Java_com_mobileer_oboetester_NativeEngine_getCpuCount(JNIEnv *env, jclass type) {
122 return sysconf(_SC_NPROCESSORS_CONF);
123 }
124
125 JNIEXPORT void JNICALL
Java_com_mobileer_oboetester_NativeEngine_setCpuAffinityMask(JNIEnv * env,jclass type,jint mask)126 Java_com_mobileer_oboetester_NativeEngine_setCpuAffinityMask(JNIEnv *env,
127 jclass type,
128 jint mask) {
129 engine.getCurrentActivity()->setCpuAffinityMask(mask);
130 }
131
132 JNIEXPORT jint JNICALL
Java_com_mobileer_oboetester_OboeAudioStream_openNative(JNIEnv * env,jobject synth,jint nativeApi,jint sampleRate,jint channelCount,jint channelMask,jint format,jint sharingMode,jint performanceMode,jint inputPreset,jint usage,jint contentType,jint bufferCapacityInFrames,jint deviceId,jint sessionId,jboolean channelConversionAllowed,jboolean formatConversionAllowed,jint rateConversionQuality,jboolean isMMap,jboolean isInput)133 Java_com_mobileer_oboetester_OboeAudioStream_openNative(
134 JNIEnv *env, jobject synth,
135 jint nativeApi,
136 jint sampleRate,
137 jint channelCount,
138 jint channelMask,
139 jint format,
140 jint sharingMode,
141 jint performanceMode,
142 jint inputPreset,
143 jint usage,
144 jint contentType,
145 jint bufferCapacityInFrames,
146 jint deviceId,
147 jint sessionId,
148 jboolean channelConversionAllowed,
149 jboolean formatConversionAllowed,
150 jint rateConversionQuality,
151 jboolean isMMap,
152 jboolean isInput) {
153 LOGD("OboeAudioStream_openNative: sampleRate = %d", sampleRate);
154
155 return (jint) engine.getCurrentActivity()->open(nativeApi,
156 sampleRate,
157 channelCount,
158 channelMask,
159 format,
160 sharingMode,
161 performanceMode,
162 inputPreset,
163 usage,
164 contentType,
165 bufferCapacityInFrames,
166 deviceId,
167 sessionId,
168 channelConversionAllowed,
169 formatConversionAllowed,
170 rateConversionQuality,
171 isMMap,
172 isInput);
173 }
174
175 JNIEXPORT jint JNICALL
Java_com_mobileer_oboetester_TestAudioActivity_startNative(JNIEnv * env,jobject)176 Java_com_mobileer_oboetester_TestAudioActivity_startNative(JNIEnv *env, jobject) {
177 return (jint) engine.getCurrentActivity()->start();
178 }
179
180 JNIEXPORT jint JNICALL
Java_com_mobileer_oboetester_TestAudioActivity_pauseNative(JNIEnv * env,jobject)181 Java_com_mobileer_oboetester_TestAudioActivity_pauseNative(JNIEnv *env, jobject) {
182 return (jint) engine.getCurrentActivity()->pause();
183 }
184
185 JNIEXPORT jint JNICALL
Java_com_mobileer_oboetester_TestAudioActivity_flushNative(JNIEnv * env,jobject)186 Java_com_mobileer_oboetester_TestAudioActivity_flushNative(JNIEnv *env, jobject) {
187 return (jint) engine.getCurrentActivity()->flush();
188 }
189
190 JNIEXPORT jint JNICALL
Java_com_mobileer_oboetester_TestAudioActivity_stopNative(JNIEnv * env,jobject)191 Java_com_mobileer_oboetester_TestAudioActivity_stopNative(JNIEnv *env, jobject) {
192 return (jint) engine.getCurrentActivity()->stop();
193 }
194
195 JNIEXPORT jint JNICALL
Java_com_mobileer_oboetester_TestAudioActivity_releaseNative(JNIEnv * env,jobject)196 Java_com_mobileer_oboetester_TestAudioActivity_releaseNative(JNIEnv *env, jobject) {
197 return (jint) engine.getCurrentActivity()->release();
198 }
199
200 JNIEXPORT jint JNICALL
Java_com_mobileer_oboetester_TestAudioActivity_getFramesPerCallback(JNIEnv * env,jobject)201 Java_com_mobileer_oboetester_TestAudioActivity_getFramesPerCallback(JNIEnv *env, jobject) {
202 return (jint) engine.getCurrentActivity()->getFramesPerCallback();
203 }
204
205 JNIEXPORT jint JNICALL
Java_com_mobileer_oboetester_OboeAudioStream_startPlaybackNative(JNIEnv * env,jobject)206 Java_com_mobileer_oboetester_OboeAudioStream_startPlaybackNative(JNIEnv *env, jobject) {
207 return (jint) engine.getCurrentActivity()->startPlayback();
208 }
209
210 JNIEXPORT void JNICALL
Java_com_mobileer_oboetester_OboeAudioStream_close(JNIEnv * env,jobject,jint streamIndex)211 Java_com_mobileer_oboetester_OboeAudioStream_close(JNIEnv *env, jobject, jint streamIndex) {
212 engine.getCurrentActivity()->close(streamIndex);
213 }
214
215 JNIEXPORT void JNICALL
Java_com_mobileer_oboetester_TestAudioActivity_setUseAlternativeAdpf(JNIEnv * env,jobject,jboolean enabled)216 Java_com_mobileer_oboetester_TestAudioActivity_setUseAlternativeAdpf(JNIEnv *env, jobject, jboolean enabled) {
217 AdpfWrapper::setUseAlternative(enabled);
218 }
219
220 JNIEXPORT jint JNICALL
Java_com_mobileer_oboetester_OboeAudioStream_setBufferSizeInFrames(JNIEnv * env,jobject,jint streamIndex,jint threshold)221 Java_com_mobileer_oboetester_OboeAudioStream_setBufferSizeInFrames(
222 JNIEnv *env, jobject, jint streamIndex, jint threshold) {
223 std::shared_ptr<oboe::AudioStream> oboeStream = engine.getCurrentActivity()->getStream(streamIndex);
224 if (oboeStream != nullptr) {
225 auto result = oboeStream->setBufferSizeInFrames(threshold);
226 return (!result)
227 ? (jint) result.error()
228 : (jint) result.value();
229 }
230 return (jint) oboe::Result::ErrorNull;
231 }
232
233 JNIEXPORT jint JNICALL
Java_com_mobileer_oboetester_OboeAudioStream_getBufferSizeInFrames(JNIEnv * env,jobject,jint streamIndex)234 Java_com_mobileer_oboetester_OboeAudioStream_getBufferSizeInFrames(
235 JNIEnv *env, jobject, jint streamIndex) {
236 jint result = (jint) oboe::Result::ErrorNull;
237 std::shared_ptr<oboe::AudioStream> oboeStream = engine.getCurrentActivity()->getStream(streamIndex);
238 if (oboeStream != nullptr) {
239 result = oboeStream->getBufferSizeInFrames();
240 }
241 return result;
242 }
243
244 JNIEXPORT void JNICALL
Java_com_mobileer_oboetester_OboeAudioStream_setPerformanceHintEnabled(JNIEnv * env,jobject,jint streamIndex,jboolean enabled)245 Java_com_mobileer_oboetester_OboeAudioStream_setPerformanceHintEnabled(
246 JNIEnv *env, jobject, jint streamIndex, jboolean enabled) {
247 std::shared_ptr<oboe::AudioStream> oboeStream = engine.getCurrentActivity()->getStream(streamIndex);
248 if (oboeStream != nullptr) {
249 oboeStream->setPerformanceHintEnabled(enabled);
250 }
251 }
252
253 JNIEXPORT jint JNICALL
Java_com_mobileer_oboetester_OboeAudioStream_getBufferCapacityInFrames(JNIEnv * env,jobject,jint streamIndex)254 Java_com_mobileer_oboetester_OboeAudioStream_getBufferCapacityInFrames(
255 JNIEnv *env, jobject, jint streamIndex) {
256 jint result = (jint) oboe::Result::ErrorNull;
257 std::shared_ptr<oboe::AudioStream> oboeStream = engine.getCurrentActivity()->getStream(streamIndex);
258 if (oboeStream != nullptr) {
259 result = oboeStream->getBufferCapacityInFrames();
260 }
261 return result;
262 }
263
convertAudioApiToNativeApi(oboe::AudioApi audioApi)264 static int convertAudioApiToNativeApi(oboe::AudioApi audioApi) {
265 switch(audioApi) {
266 case oboe::AudioApi::Unspecified:
267 return NATIVE_MODE_UNSPECIFIED;
268 case oboe::AudioApi::OpenSLES:
269 return NATIVE_MODE_OPENSLES;
270 case oboe::AudioApi::AAudio:
271 return NATIVE_MODE_AAUDIO;
272 default:
273 return -1;
274 }
275 }
276
277 JNIEXPORT jint JNICALL
Java_com_mobileer_oboetester_OboeAudioStream_getNativeApi(JNIEnv * env,jobject,jint streamIndex)278 Java_com_mobileer_oboetester_OboeAudioStream_getNativeApi(
279 JNIEnv *env, jobject, jint streamIndex) {
280 jint result = (jint) oboe::Result::ErrorNull;
281 std::shared_ptr<oboe::AudioStream> oboeStream = engine.getCurrentActivity()->getStream(streamIndex);
282 if (oboeStream != nullptr) {
283 oboe::AudioApi audioApi = oboeStream->getAudioApi();
284 result = convertAudioApiToNativeApi(audioApi);
285 LOGD("OboeAudioStream_getNativeApi got %d", result);
286 }
287 return result;
288 }
289
290 JNIEXPORT jint JNICALL
Java_com_mobileer_oboetester_OboeAudioStream_getSampleRate(JNIEnv * env,jobject,jint streamIndex)291 Java_com_mobileer_oboetester_OboeAudioStream_getSampleRate(
292 JNIEnv *env, jobject, jint streamIndex) {
293 jint result = (jint) oboe::Result::ErrorNull;
294 std::shared_ptr<oboe::AudioStream> oboeStream = engine.getCurrentActivity()->getStream(streamIndex);
295 if (oboeStream != nullptr) {
296 result = oboeStream->getSampleRate();
297 }
298 return result;
299 }
300
301 JNIEXPORT jint JNICALL
Java_com_mobileer_oboetester_OboeAudioStream_getSharingMode(JNIEnv * env,jobject,jint streamIndex)302 Java_com_mobileer_oboetester_OboeAudioStream_getSharingMode(
303 JNIEnv *env, jobject, jint streamIndex) {
304 jint result = (jint) oboe::Result::ErrorNull;
305 std::shared_ptr<oboe::AudioStream> oboeStream = engine.getCurrentActivity()->getStream(streamIndex);
306 if (oboeStream != nullptr) {
307 result = (jint) oboeStream->getSharingMode();
308 }
309 return result;
310 }
311
312 JNIEXPORT jint JNICALL
Java_com_mobileer_oboetester_OboeAudioStream_getPerformanceMode(JNIEnv * env,jobject,jint streamIndex)313 Java_com_mobileer_oboetester_OboeAudioStream_getPerformanceMode(
314 JNIEnv *env, jobject, jint streamIndex) {
315 jint result = (jint) oboe::Result::ErrorNull;
316 std::shared_ptr<oboe::AudioStream> oboeStream = engine.getCurrentActivity()->getStream(streamIndex);
317 if (oboeStream != nullptr) {
318 result = (jint) oboeStream->getPerformanceMode();
319 }
320 return result;
321 }
322
323 JNIEXPORT jint JNICALL
Java_com_mobileer_oboetester_OboeAudioStream_getInputPreset(JNIEnv * env,jobject,jint streamIndex)324 Java_com_mobileer_oboetester_OboeAudioStream_getInputPreset(
325 JNIEnv *env, jobject, jint streamIndex) {
326 jint result = (jint) oboe::Result::ErrorNull;
327 std::shared_ptr<oboe::AudioStream> oboeStream = engine.getCurrentActivity()->getStream(streamIndex);
328 if (oboeStream != nullptr) {
329 result = (jint) oboeStream->getInputPreset();
330 }
331 return result;
332 }
333
334 JNIEXPORT jint JNICALL
Java_com_mobileer_oboetester_OboeAudioStream_getFramesPerBurst(JNIEnv * env,jobject,jint streamIndex)335 Java_com_mobileer_oboetester_OboeAudioStream_getFramesPerBurst(
336 JNIEnv *env, jobject, jint streamIndex) {
337 jint result = (jint) oboe::Result::ErrorNull;
338 std::shared_ptr<oboe::AudioStream> oboeStream = engine.getCurrentActivity()->getStream(streamIndex);
339 if (oboeStream != nullptr) {
340 result = oboeStream->getFramesPerBurst();
341 }
342 return result;
343 }
344
345 JNIEXPORT jint JNICALL
Java_com_mobileer_oboetester_OboeAudioStream_getChannelCount(JNIEnv * env,jobject,jint streamIndex)346 Java_com_mobileer_oboetester_OboeAudioStream_getChannelCount(
347 JNIEnv *env, jobject, jint streamIndex) {
348 jint result = (jint) oboe::Result::ErrorNull;
349 std::shared_ptr<oboe::AudioStream> oboeStream = engine.getCurrentActivity()->getStream(streamIndex);
350 if (oboeStream != nullptr) {
351 result = oboeStream->getChannelCount();
352 }
353 return result;
354 }
355
356 JNIEXPORT jint JNICALL
Java_com_mobileer_oboetester_OboeAudioStream_getChannelMask(JNIEnv * env,jobject,jint streamIndex)357 Java_com_mobileer_oboetester_OboeAudioStream_getChannelMask(
358 JNIEnv *env, jobject, jint streamIndex) {
359 jint result = (jint) oboe::Result::ErrorNull;
360 std::shared_ptr<oboe::AudioStream> oboeStream = engine.getCurrentActivity()->getStream(streamIndex);
361 if (oboeStream != nullptr) {
362 result = (jint) oboeStream->getChannelMask();
363 }
364 return result;
365 }
366
367 JNIEXPORT jint JNICALL
Java_com_mobileer_oboetester_OboeAudioStream_getFormat(JNIEnv * env,jobject instance,jint streamIndex)368 Java_com_mobileer_oboetester_OboeAudioStream_getFormat(JNIEnv *env, jobject instance, jint streamIndex) {
369 jint result = (jint) oboe::Result::ErrorNull;
370 std::shared_ptr<oboe::AudioStream> oboeStream = engine.getCurrentActivity()->getStream(streamIndex);
371 if (oboeStream != nullptr) {
372 result = (jint) oboeStream->getFormat();
373 }
374 return result;
375 }
376
377 JNIEXPORT jint JNICALL
Java_com_mobileer_oboetester_OboeAudioStream_getHardwareChannelCount(JNIEnv * env,jobject,jint streamIndex)378 Java_com_mobileer_oboetester_OboeAudioStream_getHardwareChannelCount(
379 JNIEnv *env, jobject, jint streamIndex) {
380 jint result = (jint) oboe::Result::ErrorNull;
381 std::shared_ptr<oboe::AudioStream> oboeStream = engine.getCurrentActivity()->getStream(streamIndex);
382 if (oboeStream != nullptr) {
383 result = oboeStream->getHardwareChannelCount();
384 }
385 return result;
386 }
387
388 JNIEXPORT jint JNICALL
Java_com_mobileer_oboetester_OboeAudioStream_getHardwareFormat(JNIEnv * env,jobject instance,jint streamIndex)389 Java_com_mobileer_oboetester_OboeAudioStream_getHardwareFormat(JNIEnv *env, jobject instance, jint streamIndex) {
390 jint result = (jint) oboe::Result::ErrorNull;
391 std::shared_ptr<oboe::AudioStream> oboeStream = engine.getCurrentActivity()->getStream(streamIndex);
392 if (oboeStream != nullptr) {
393 result = (jint) oboeStream->getHardwareFormat();
394 }
395 return result;
396 }
397
398 JNIEXPORT jint JNICALL
Java_com_mobileer_oboetester_OboeAudioStream_getHardwareSampleRate(JNIEnv * env,jobject,jint streamIndex)399 Java_com_mobileer_oboetester_OboeAudioStream_getHardwareSampleRate(
400 JNIEnv *env, jobject, jint streamIndex) {
401 jint result = (jint) oboe::Result::ErrorNull;
402 std::shared_ptr<oboe::AudioStream> oboeStream = engine.getCurrentActivity()->getStream(streamIndex);
403 if (oboeStream != nullptr) {
404 result = oboeStream->getHardwareSampleRate();
405 }
406 return result;
407 }
408
409 JNIEXPORT jint JNICALL
Java_com_mobileer_oboetester_OboeAudioStream_getUsage(JNIEnv * env,jobject instance,jint streamIndex)410 Java_com_mobileer_oboetester_OboeAudioStream_getUsage(JNIEnv *env, jobject instance, jint streamIndex) {
411 jint result = (jint) oboe::Result::ErrorNull;
412 std::shared_ptr<oboe::AudioStream> oboeStream = engine.getCurrentActivity()->getStream(streamIndex);
413 if (oboeStream != nullptr) {
414 result = (jint) oboeStream->getUsage();
415 }
416 return result;
417 }
418
419 JNIEXPORT jint JNICALL
Java_com_mobileer_oboetester_OboeAudioStream_getContentType(JNIEnv * env,jobject instance,jint streamIndex)420 Java_com_mobileer_oboetester_OboeAudioStream_getContentType(JNIEnv *env, jobject instance, jint streamIndex) {
421 jint result = (jint) oboe::Result::ErrorNull;
422 std::shared_ptr<oboe::AudioStream> oboeStream = engine.getCurrentActivity()->getStream(streamIndex);
423 if (oboeStream != nullptr) {
424 result = (jint) oboeStream->getContentType();
425 }
426 return result;
427 }
428
429 JNIEXPORT jint JNICALL
Java_com_mobileer_oboetester_OboeAudioStream_getDeviceId(JNIEnv * env,jobject,jint streamIndex)430 Java_com_mobileer_oboetester_OboeAudioStream_getDeviceId(
431 JNIEnv *env, jobject, jint streamIndex) {
432 jint result = (jint) oboe::Result::ErrorNull;
433 std::shared_ptr<oboe::AudioStream> oboeStream = engine.getCurrentActivity()->getStream(streamIndex);
434 if (oboeStream != nullptr) {
435 result = oboeStream->getDeviceId();
436 }
437 return result;
438 }
439
440 JNIEXPORT jint JNICALL
Java_com_mobileer_oboetester_OboeAudioStream_getSessionId(JNIEnv * env,jobject,jint streamIndex)441 Java_com_mobileer_oboetester_OboeAudioStream_getSessionId(
442 JNIEnv *env, jobject, jint streamIndex) {
443 jint result = (jint) oboe::Result::ErrorNull;
444 std::shared_ptr<oboe::AudioStream> oboeStream = engine.getCurrentActivity()->getStream(streamIndex);
445 if (oboeStream != nullptr) {
446 result = oboeStream->getSessionId();
447 }
448 return result;
449 }
450
451 JNIEXPORT jlong JNICALL
Java_com_mobileer_oboetester_OboeAudioStream_getFramesWritten(JNIEnv * env,jobject,jint streamIndex)452 Java_com_mobileer_oboetester_OboeAudioStream_getFramesWritten(
453 JNIEnv *env, jobject, jint streamIndex) {
454 jlong result = (jint) oboe::Result::ErrorNull;
455 std::shared_ptr<oboe::AudioStream> oboeStream = engine.getCurrentActivity()->getStream(streamIndex);
456 if (oboeStream != nullptr) {
457 result = oboeStream->getFramesWritten();
458 }
459 return result;
460 }
461
462 JNIEXPORT jlong JNICALL
Java_com_mobileer_oboetester_OboeAudioStream_getFramesRead(JNIEnv * env,jobject,jint streamIndex)463 Java_com_mobileer_oboetester_OboeAudioStream_getFramesRead(
464 JNIEnv *env, jobject, jint streamIndex) {
465 jlong result = (jlong) oboe::Result::ErrorNull;
466 std::shared_ptr<oboe::AudioStream> oboeStream = engine.getCurrentActivity()->getStream(streamIndex);
467 if (oboeStream != nullptr) {
468 result = oboeStream->getFramesRead();
469 }
470 return result;
471 }
472
473 JNIEXPORT jint JNICALL
Java_com_mobileer_oboetester_OboeAudioStream_getXRunCount(JNIEnv * env,jobject,jint streamIndex)474 Java_com_mobileer_oboetester_OboeAudioStream_getXRunCount(
475 JNIEnv *env, jobject, jint streamIndex) {
476 jint result = (jlong) oboe::Result::ErrorNull;
477 std::shared_ptr<oboe::AudioStream> oboeStream = engine.getCurrentActivity()->getStream(streamIndex);
478 if (oboeStream != nullptr) {
479 auto oboeResult = oboeStream->getXRunCount();
480 if (!oboeResult) {
481 result = (jint) oboeResult.error();
482 } else {
483 result = oboeResult.value();
484 }
485 }
486 return result;
487 }
488
489 JNIEXPORT jlong JNICALL
Java_com_mobileer_oboetester_OboeAudioStream_getCallbackCount(JNIEnv * env,jobject)490 Java_com_mobileer_oboetester_OboeAudioStream_getCallbackCount(
491 JNIEnv *env, jobject) {
492 return engine.getCurrentActivity()->getCallbackCount();
493 }
494
495 JNIEXPORT jint JNICALL
Java_com_mobileer_oboetester_OboeAudioStream_getLastErrorCallbackResult(JNIEnv * env,jobject,jint streamIndex)496 Java_com_mobileer_oboetester_OboeAudioStream_getLastErrorCallbackResult(
497 JNIEnv *env, jobject, jint streamIndex) {
498 std::shared_ptr<oboe::AudioStream> oboeStream = engine.getCurrentActivity()->getStream(streamIndex);
499 if (oboeStream != nullptr) {
500 return (jint) oboeStream->getLastErrorCallbackResult();
501 }
502 return 0;
503 }
504
505 JNIEXPORT jdouble JNICALL
Java_com_mobileer_oboetester_OboeAudioStream_getTimestampLatency(JNIEnv * env,jobject instance,jint streamIndex)506 Java_com_mobileer_oboetester_OboeAudioStream_getTimestampLatency(JNIEnv *env,
507 jobject instance,
508 jint streamIndex) {
509 return engine.getCurrentActivity()->getTimestampLatency(streamIndex);
510 }
511
512 JNIEXPORT jfloat JNICALL
Java_com_mobileer_oboetester_OboeAudioStream_getCpuLoad(JNIEnv * env,jobject instance,jint streamIndex)513 Java_com_mobileer_oboetester_OboeAudioStream_getCpuLoad(JNIEnv *env, jobject instance, jint streamIndex) {
514 return engine.getCurrentActivity()->getCpuLoad();
515 }
516
517 JNIEXPORT jfloat JNICALL
Java_com_mobileer_oboetester_OboeAudioStream_getAndResetMaxCpuLoad(JNIEnv * env,jobject instance,jint streamIndex)518 Java_com_mobileer_oboetester_OboeAudioStream_getAndResetMaxCpuLoad(JNIEnv *env, jobject instance, jint streamIndex) {
519 return engine.getCurrentActivity()->getAndResetMaxCpuLoad();
520 }
521
522 JNIEXPORT jint JNICALL
Java_com_mobileer_oboetester_OboeAudioStream_getAndResetCpuMask(JNIEnv * env,jobject instance,jint streamIndex)523 Java_com_mobileer_oboetester_OboeAudioStream_getAndResetCpuMask(JNIEnv *env, jobject instance, jint streamIndex) {
524 return (jint) engine.getCurrentActivity()->getAndResetCpuMask();
525 }
526
527 JNIEXPORT jstring JNICALL
Java_com_mobileer_oboetester_OboeAudioStream_getCallbackTimeString(JNIEnv * env,jobject instance)528 Java_com_mobileer_oboetester_OboeAudioStream_getCallbackTimeString(JNIEnv *env, jobject instance) {
529 return env->NewStringUTF(engine.getCurrentActivity()->getCallbackTimeString().c_str());
530 }
531
532 JNIEXPORT void JNICALL
Java_com_mobileer_oboetester_OboeAudioStream_setWorkload(JNIEnv * env,jobject,jint workload)533 Java_com_mobileer_oboetester_OboeAudioStream_setWorkload(
534 JNIEnv *env, jobject, jint workload) {
535 engine.getCurrentActivity()->setWorkload(workload);
536 }
537
538 JNIEXPORT void JNICALL
Java_com_mobileer_oboetester_OboeAudioStream_setHearWorkload(JNIEnv * env,jobject,jint streamIndex,jboolean enabled)539 Java_com_mobileer_oboetester_OboeAudioStream_setHearWorkload(
540 JNIEnv *env, jobject, jint streamIndex, jboolean enabled) {
541 engine.getCurrentActivity()->setHearWorkload(enabled);
542 }
543
544 JNIEXPORT jint JNICALL
Java_com_mobileer_oboetester_OboeAudioStream_getState(JNIEnv * env,jobject instance,jint streamIndex)545 Java_com_mobileer_oboetester_OboeAudioStream_getState(JNIEnv *env, jobject instance, jint streamIndex) {
546 std::shared_ptr<oboe::AudioStream> oboeStream = engine.getCurrentActivity()->getStream(streamIndex);
547 if (oboeStream != nullptr) {
548 auto state = oboeStream->getState();
549 if (state != oboe::StreamState::Starting && state != oboe::StreamState::Started
550 && state != oboe::StreamState::Disconnected) {
551 oboe::Result result = oboeStream->waitForStateChange(
552 oboe::StreamState::Uninitialized,
553 &state, 0);
554
555 if (result != oboe::Result::OK){
556 if (result == oboe::Result::ErrorClosed) {
557 state = oboe::StreamState::Closed;
558 } else if (result == oboe::Result::ErrorDisconnected){
559 state = oboe::StreamState::Disconnected;
560 } else {
561 state = oboe::StreamState::Unknown;
562 }
563 }
564 }
565 return (jint) state;
566 }
567 return -1;
568 }
569
570 JNIEXPORT jdouble JNICALL
Java_com_mobileer_oboetester_AudioInputTester_getPeakLevel(JNIEnv * env,jobject instance,jint index)571 Java_com_mobileer_oboetester_AudioInputTester_getPeakLevel(JNIEnv *env,
572 jobject instance,
573 jint index) {
574 return engine.getCurrentActivity()->getPeakLevel(index);
575 }
576
577 JNIEXPORT void JNICALL
Java_com_mobileer_oboetester_OboeAudioStream_setUseCallback(JNIEnv * env,jclass type,jboolean useCallback)578 Java_com_mobileer_oboetester_OboeAudioStream_setUseCallback(JNIEnv *env, jclass type,
579 jboolean useCallback) {
580 ActivityContext::mUseCallback = useCallback;
581 }
582
583 JNIEXPORT void JNICALL
Java_com_mobileer_oboetester_OboeAudioStream_setCallbackReturnStop(JNIEnv * env,jclass type,jboolean b)584 Java_com_mobileer_oboetester_OboeAudioStream_setCallbackReturnStop(JNIEnv *env, jclass type,
585 jboolean b) {
586 OboeStreamCallbackProxy::setCallbackReturnStop(b);
587 }
588
589 JNIEXPORT void JNICALL
Java_com_mobileer_oboetester_OboeAudioStream_setHangTimeMillis(JNIEnv * env,jclass type,jint hangTimeMillis)590 Java_com_mobileer_oboetester_OboeAudioStream_setHangTimeMillis(JNIEnv *env, jclass type,
591 jint hangTimeMillis) {
592 OboeTesterStreamCallback::setHangTimeMillis(hangTimeMillis);
593 }
594
595 JNIEXPORT void JNICALL
Java_com_mobileer_oboetester_OboeAudioStream_setCallbackSize(JNIEnv * env,jclass type,jint callbackSize)596 Java_com_mobileer_oboetester_OboeAudioStream_setCallbackSize(JNIEnv *env, jclass type,
597 jint callbackSize) {
598 ActivityContext::callbackSize = callbackSize;
599 }
600
601 JNIEXPORT jboolean JNICALL
Java_com_mobileer_oboetester_OboeAudioStream_isMMap(JNIEnv * env,jobject instance,jint streamIndex)602 Java_com_mobileer_oboetester_OboeAudioStream_isMMap(JNIEnv *env, jobject instance, jint streamIndex) {
603 return engine.getCurrentActivity()->isMMapUsed(streamIndex);
604 }
605
606 // ================= OboeAudioOutputStream ================================
607
608 JNIEXPORT void JNICALL
Java_com_mobileer_oboetester_OboeAudioOutputStream_trigger(JNIEnv * env,jobject)609 Java_com_mobileer_oboetester_OboeAudioOutputStream_trigger(
610 JNIEnv *env, jobject) {
611 engine.getCurrentActivity()->trigger();
612 }
613
614 JNIEXPORT void JNICALL
Java_com_mobileer_oboetester_OboeAudioOutputStream_setChannelEnabled(JNIEnv * env,jobject,jint channelIndex,jboolean enabled)615 Java_com_mobileer_oboetester_OboeAudioOutputStream_setChannelEnabled(
616 JNIEnv *env, jobject, jint channelIndex, jboolean enabled) {
617 engine.getCurrentActivity()->setChannelEnabled(channelIndex, enabled);
618 }
619
620 JNIEXPORT void JNICALL
Java_com_mobileer_oboetester_OboeAudioOutputStream_setSignalType(JNIEnv * env,jobject,jint signalType)621 Java_com_mobileer_oboetester_OboeAudioOutputStream_setSignalType(
622 JNIEnv *env, jobject, jint signalType) {
623 engine.getCurrentActivity()->setSignalType(signalType);
624 }
625
626 JNIEXPORT void JNICALL
Java_com_mobileer_oboetester_OboeAudioOutputStream_setAmplitude(JNIEnv * env,jobject,jfloat amplitude)627 Java_com_mobileer_oboetester_OboeAudioOutputStream_setAmplitude(JNIEnv *env, jobject, jfloat amplitude) {
628 engine.getCurrentActivity()->setAmplitude(amplitude);
629 }
630
631 JNIEXPORT jint JNICALL
Java_com_mobileer_oboetester_OboeAudioStream_getOboeVersionNumber(JNIEnv * env,jclass type)632 Java_com_mobileer_oboetester_OboeAudioStream_getOboeVersionNumber(JNIEnv *env,
633 jclass type) {
634 return OBOE_VERSION_NUMBER;
635 }
636
637 // ==========================================================================
638 JNIEXPORT void JNICALL
Java_com_mobileer_oboetester_TestAudioActivity_setActivityType(JNIEnv * env,jobject instance,jint activityType)639 Java_com_mobileer_oboetester_TestAudioActivity_setActivityType(JNIEnv *env,
640 jobject instance,
641 jint activityType) {
642 engine.setActivityType(activityType);
643 }
644
645 // ==========================================================================
646 JNIEXPORT jint JNICALL
Java_com_mobileer_oboetester_TestInputActivity_saveWaveFile(JNIEnv * env,jobject instance,jstring fileName)647 Java_com_mobileer_oboetester_TestInputActivity_saveWaveFile(JNIEnv *env,
648 jobject instance,
649 jstring fileName) {
650 const char *str = env->GetStringUTFChars(fileName, nullptr);
651 LOGD("nativeSaveFile(%s)", str);
652 jint result = engine.getCurrentActivity()->saveWaveFile(str);
653 env->ReleaseStringUTFChars(fileName, str);
654 return result;
655 }
656
657 // ==========================================================================
658 JNIEXPORT void JNICALL
Java_com_mobileer_oboetester_TestInputActivity_setMinimumFramesBeforeRead(JNIEnv * env,jobject instance,jint numFrames)659 Java_com_mobileer_oboetester_TestInputActivity_setMinimumFramesBeforeRead(JNIEnv *env,
660 jobject instance,
661 jint numFrames) {
662 engine.getCurrentActivity()->setMinimumFramesBeforeRead(numFrames);
663 }
664
665 // ==========================================================================
666 JNIEXPORT void JNICALL
Java_com_mobileer_oboetester_EchoActivity_setDelayTime(JNIEnv * env,jobject instance,jdouble delayTimeSeconds)667 Java_com_mobileer_oboetester_EchoActivity_setDelayTime(JNIEnv *env,
668 jobject instance,
669 jdouble delayTimeSeconds) {
670 engine.setDelayTime(delayTimeSeconds);
671 }
672
673 JNIEXPORT int JNICALL
Java_com_mobileer_oboetester_EchoActivity_getColdStartInputMillis(JNIEnv * env,jobject instance)674 Java_com_mobileer_oboetester_EchoActivity_getColdStartInputMillis(JNIEnv *env,
675 jobject instance) {
676 return engine.getCurrentActivity()->getColdStartInputMillis();
677 }
678
679 JNIEXPORT int JNICALL
Java_com_mobileer_oboetester_EchoActivity_getColdStartOutputMillis(JNIEnv * env,jobject instance)680 Java_com_mobileer_oboetester_EchoActivity_getColdStartOutputMillis(JNIEnv *env,
681 jobject instance) {
682 return engine.getCurrentActivity()->getColdStartOutputMillis();
683 }
684
685 // ==========================================================================
686 JNIEXPORT jint JNICALL
Java_com_mobileer_oboetester_RoundTripLatencyActivity_getAnalyzerProgress(JNIEnv * env,jobject instance)687 Java_com_mobileer_oboetester_RoundTripLatencyActivity_getAnalyzerProgress(JNIEnv *env,
688 jobject instance) {
689 return engine.mActivityRoundTripLatency.getLatencyAnalyzer()->getProgress();
690 }
691
692 JNIEXPORT jint JNICALL
Java_com_mobileer_oboetester_RoundTripLatencyActivity_getMeasuredLatency(JNIEnv * env,jobject instance)693 Java_com_mobileer_oboetester_RoundTripLatencyActivity_getMeasuredLatency(JNIEnv *env,
694 jobject instance) {
695 return engine.mActivityRoundTripLatency.getLatencyAnalyzer()->getMeasuredLatency();
696 }
697
698 JNIEXPORT jdouble JNICALL
Java_com_mobileer_oboetester_RoundTripLatencyActivity_getMeasuredConfidence(JNIEnv * env,jobject instance)699 Java_com_mobileer_oboetester_RoundTripLatencyActivity_getMeasuredConfidence(JNIEnv *env,
700 jobject instance) {
701 return engine.mActivityRoundTripLatency.getLatencyAnalyzer()->getMeasuredConfidence();
702 }
703
704 JNIEXPORT jdouble JNICALL
Java_com_mobileer_oboetester_RoundTripLatencyActivity_getMeasuredCorrelation(JNIEnv * env,jobject instance)705 Java_com_mobileer_oboetester_RoundTripLatencyActivity_getMeasuredCorrelation(JNIEnv *env,
706 jobject instance) {
707 return engine.mActivityRoundTripLatency.getLatencyAnalyzer()->getMeasuredCorrelation();
708 }
709
710 JNIEXPORT jdouble JNICALL
Java_com_mobileer_oboetester_RoundTripLatencyActivity_measureTimestampLatency(JNIEnv * env,jobject instance)711 Java_com_mobileer_oboetester_RoundTripLatencyActivity_measureTimestampLatency(JNIEnv *env,
712 jobject instance) {
713 return engine.mActivityRoundTripLatency.measureTimestampLatency();
714 }
715
716 JNIEXPORT jdouble JNICALL
Java_com_mobileer_oboetester_RoundTripLatencyActivity_getBackgroundRMS(JNIEnv * env,jobject instance)717 Java_com_mobileer_oboetester_RoundTripLatencyActivity_getBackgroundRMS(JNIEnv *env,
718 jobject instance) {
719 return engine.mActivityRoundTripLatency.getLatencyAnalyzer()->getBackgroundRMS();
720 }
721
722 JNIEXPORT jdouble JNICALL
Java_com_mobileer_oboetester_RoundTripLatencyActivity_getSignalRMS(JNIEnv * env,jobject instance)723 Java_com_mobileer_oboetester_RoundTripLatencyActivity_getSignalRMS(JNIEnv *env,
724 jobject instance) {
725 return engine.mActivityRoundTripLatency.getLatencyAnalyzer()->getSignalRMS();
726 }
727
728 JNIEXPORT jint JNICALL
Java_com_mobileer_oboetester_AnalyzerActivity_getMeasuredResult(JNIEnv * env,jobject instance)729 Java_com_mobileer_oboetester_AnalyzerActivity_getMeasuredResult(JNIEnv *env,
730 jobject instance) {
731 return engine.mActivityRoundTripLatency.getLatencyAnalyzer()->getResult();
732 }
733
734 // ==========================================================================
735 JNIEXPORT jint JNICALL
Java_com_mobileer_oboetester_AnalyzerActivity_getAnalyzerState(JNIEnv * env,jobject instance)736 Java_com_mobileer_oboetester_AnalyzerActivity_getAnalyzerState(JNIEnv *env,
737 jobject instance) {
738 return ((ActivityFullDuplex *)engine.getCurrentActivity())->getState();
739 }
740
741 JNIEXPORT jboolean JNICALL
Java_com_mobileer_oboetester_AnalyzerActivity_isAnalyzerDone(JNIEnv * env,jobject instance)742 Java_com_mobileer_oboetester_AnalyzerActivity_isAnalyzerDone(JNIEnv *env,
743 jobject instance) {
744 return ((ActivityFullDuplex *)engine.getCurrentActivity())->isAnalyzerDone();
745 }
746
747 JNIEXPORT jint JNICALL
Java_com_mobileer_oboetester_AnalyzerActivity_getResetCount(JNIEnv * env,jobject instance)748 Java_com_mobileer_oboetester_AnalyzerActivity_getResetCount(JNIEnv *env,
749 jobject instance) {
750 return ((ActivityFullDuplex *)engine.getCurrentActivity())->getResetCount();
751 }
752
753 // ==========================================================================
754 JNIEXPORT jint JNICALL
Java_com_mobileer_oboetester_GlitchActivity_getGlitchCount(JNIEnv * env,jobject instance)755 Java_com_mobileer_oboetester_GlitchActivity_getGlitchCount(JNIEnv *env,
756 jobject instance) {
757 return engine.mActivityGlitches.getGlitchAnalyzer()->getGlitchCount();
758 }
759
760 JNIEXPORT jint JNICALL
Java_com_mobileer_oboetester_GlitchActivity_getGlitchLength(JNIEnv * env,jobject instance)761 Java_com_mobileer_oboetester_GlitchActivity_getGlitchLength(JNIEnv *env,
762 jobject instance) {
763 return engine.mActivityGlitches.getGlitchAnalyzer()->getGlitchLength();
764 }
765
766 JNIEXPORT double JNICALL
Java_com_mobileer_oboetester_GlitchActivity_getPhase(JNIEnv * env,jobject instance)767 Java_com_mobileer_oboetester_GlitchActivity_getPhase(JNIEnv *env,
768 jobject instance) {
769 return engine.mActivityGlitches.getGlitchAnalyzer()->getPhaseOffset();
770 }
771
772 JNIEXPORT jint JNICALL
Java_com_mobileer_oboetester_GlitchActivity_getStateFrameCount(JNIEnv * env,jobject instance,jint state)773 Java_com_mobileer_oboetester_GlitchActivity_getStateFrameCount(JNIEnv *env,
774 jobject instance,
775 jint state) {
776 return engine.mActivityGlitches.getGlitchAnalyzer()->getStateFrameCount(state);
777 }
778
779 JNIEXPORT jdouble JNICALL
Java_com_mobileer_oboetester_GlitchActivity_getSignalToNoiseDB(JNIEnv * env,jobject instance)780 Java_com_mobileer_oboetester_GlitchActivity_getSignalToNoiseDB(JNIEnv *env,
781 jobject instance) {
782 return engine.mActivityGlitches.getGlitchAnalyzer()->getSignalToNoiseDB();
783 }
784
785 JNIEXPORT jdouble JNICALL
Java_com_mobileer_oboetester_GlitchActivity_getPeakAmplitude(JNIEnv * env,jobject instance)786 Java_com_mobileer_oboetester_GlitchActivity_getPeakAmplitude(JNIEnv *env,
787 jobject instance) {
788 return engine.mActivityGlitches.getGlitchAnalyzer()->getPeakAmplitude();
789 }
790
791 JNIEXPORT jdouble JNICALL
Java_com_mobileer_oboetester_GlitchActivity_getSineAmplitude(JNIEnv * env,jobject instance)792 Java_com_mobileer_oboetester_GlitchActivity_getSineAmplitude(JNIEnv *env,
793 jobject instance) {
794 return engine.mActivityGlitches.getGlitchAnalyzer()->getSineAmplitude();
795 }
796
797 JNIEXPORT jint JNICALL
Java_com_mobileer_oboetester_GlitchActivity_getSinePeriod(JNIEnv * env,jobject instance)798 Java_com_mobileer_oboetester_GlitchActivity_getSinePeriod(JNIEnv *env,
799 jobject instance) {
800 return engine.mActivityGlitches.getGlitchAnalyzer()->getSinePeriod();
801 }
802
803 JNIEXPORT jdouble JNICALL
Java_com_mobileer_oboetester_TestDataPathsActivity_getMagnitude(JNIEnv * env,jobject instance)804 Java_com_mobileer_oboetester_TestDataPathsActivity_getMagnitude(JNIEnv *env,
805 jobject instance) {
806 return engine.mActivityDataPath.getDataPathAnalyzer()->getMagnitude();
807 }
808
809 JNIEXPORT jdouble JNICALL
Java_com_mobileer_oboetester_TestDataPathsActivity_getMaxMagnitude(JNIEnv * env,jobject instance)810 Java_com_mobileer_oboetester_TestDataPathsActivity_getMaxMagnitude(JNIEnv *env,
811 jobject instance) {
812 return engine.mActivityDataPath.getDataPathAnalyzer()->getMaxMagnitude();
813 }
814
815 JNIEXPORT double JNICALL
Java_com_mobileer_oboetester_TestDataPathsActivity_getPhaseDataPaths(JNIEnv * env,jobject instance)816 Java_com_mobileer_oboetester_TestDataPathsActivity_getPhaseDataPaths(JNIEnv *env,
817 jobject instance) {
818 return engine.mActivityDataPath.getDataPathAnalyzer()->getPhaseOffset();
819 }
820
821 JNIEXPORT void JNICALL
Java_com_mobileer_oboetester_GlitchActivity_setTolerance(JNIEnv * env,jobject instance,jfloat tolerance)822 Java_com_mobileer_oboetester_GlitchActivity_setTolerance(JNIEnv *env,
823 jobject instance,
824 jfloat tolerance) {
825 if (engine.mActivityGlitches.getGlitchAnalyzer()) {
826 engine.mActivityGlitches.getGlitchAnalyzer()->setTolerance(tolerance);
827 }
828 }
829
830 JNIEXPORT void JNICALL
Java_com_mobileer_oboetester_GlitchActivity_setForcedGlitchDuration(JNIEnv * env,jobject instance,jint frames)831 Java_com_mobileer_oboetester_GlitchActivity_setForcedGlitchDuration(JNIEnv *env,
832 jobject instance,
833 jint frames) {
834 if (engine.mActivityGlitches.getGlitchAnalyzer()) {
835 engine.mActivityGlitches.getGlitchAnalyzer()->setForcedGlitchDuration(frames);
836 }
837 }
838
839 JNIEXPORT void JNICALL
Java_com_mobileer_oboetester_GlitchActivity_setInputChannelNative(JNIEnv * env,jobject instance,jint channel)840 Java_com_mobileer_oboetester_GlitchActivity_setInputChannelNative(JNIEnv *env,
841 jobject instance,
842 jint channel) {
843 if (engine.mActivityGlitches.getGlitchAnalyzer()) {
844 engine.mActivityGlitches.getGlitchAnalyzer()->setInputChannel(channel);
845 }
846 if (engine.mActivityDataPath.getDataPathAnalyzer()) {
847 engine.mActivityDataPath.getDataPathAnalyzer()->setInputChannel(channel);
848 }
849 }
850
851 JNIEXPORT void JNICALL
Java_com_mobileer_oboetester_GlitchActivity_setOutputChannelNative(JNIEnv * env,jobject instance,jint channel)852 Java_com_mobileer_oboetester_GlitchActivity_setOutputChannelNative(JNIEnv *env,
853 jobject instance,
854 jint channel) {
855 if (engine.mActivityGlitches.getGlitchAnalyzer()) {
856 engine.mActivityGlitches.getGlitchAnalyzer()->setOutputChannel(channel);
857 }
858 if (engine.mActivityDataPath.getDataPathAnalyzer()) {
859 engine.mActivityDataPath.getDataPathAnalyzer()->setOutputChannel(channel);
860 }
861 }
862
863 JNIEXPORT jint JNICALL
Java_com_mobileer_oboetester_ManualGlitchActivity_getGlitch(JNIEnv * env,jobject instance,jfloatArray waveform_)864 Java_com_mobileer_oboetester_ManualGlitchActivity_getGlitch(JNIEnv *env, jobject instance,
865 jfloatArray waveform_) {
866 float *waveform = env->GetFloatArrayElements(waveform_, nullptr);
867 jsize length = env->GetArrayLength(waveform_);
868 jsize numSamples = 0;
869 auto *analyzer = engine.mActivityGlitches.getGlitchAnalyzer();
870 if (analyzer) {
871 numSamples = analyzer->getLastGlitch(waveform, length);
872 }
873
874 env->ReleaseFloatArrayElements(waveform_, waveform, 0);
875 return numSamples;
876 }
877
878 JNIEXPORT jint JNICALL
Java_com_mobileer_oboetester_ManualGlitchActivity_getRecentSamples(JNIEnv * env,jobject instance,jfloatArray waveform_)879 Java_com_mobileer_oboetester_ManualGlitchActivity_getRecentSamples(JNIEnv *env, jobject instance,
880 jfloatArray waveform_) {
881 float *waveform = env->GetFloatArrayElements(waveform_, nullptr);
882 jsize length = env->GetArrayLength(waveform_);
883 jsize numSamples = 0;
884 auto *analyzer = engine.mActivityGlitches.getGlitchAnalyzer();
885 if (analyzer) {
886 numSamples = analyzer->getRecentSamples(waveform, length);
887 }
888
889 env->ReleaseFloatArrayElements(waveform_, waveform, 0);
890 return numSamples;
891 }
892
893 JNIEXPORT void JNICALL
Java_com_mobileer_oboetester_TestAudioActivity_setDefaultAudioValues(JNIEnv * env,jclass clazz,jint audio_manager_sample_rate,jint audio_manager_frames_per_burst)894 Java_com_mobileer_oboetester_TestAudioActivity_setDefaultAudioValues(JNIEnv *env, jclass clazz,
895 jint audio_manager_sample_rate,
896 jint audio_manager_frames_per_burst) {
897 oboe::DefaultStreamValues::SampleRate = audio_manager_sample_rate;
898 oboe::DefaultStreamValues::FramesPerBurst = audio_manager_frames_per_burst;
899 }
900
901 static TestErrorCallback sErrorCallbackTester;
902
903 JNIEXPORT void JNICALL
Java_com_mobileer_oboetester_TestErrorCallbackActivity_testDeleteCrash(JNIEnv * env,jobject instance)904 Java_com_mobileer_oboetester_TestErrorCallbackActivity_testDeleteCrash(
905 JNIEnv *env, jobject instance) {
906 sErrorCallbackTester.test();
907 }
908
909 JNIEXPORT jint JNICALL
Java_com_mobileer_oboetester_TestErrorCallbackActivity_getCallbackMagic(JNIEnv * env,jobject instance)910 Java_com_mobileer_oboetester_TestErrorCallbackActivity_getCallbackMagic(
911 JNIEnv *env, jobject instance) {
912 return sErrorCallbackTester.getCallbackMagic();
913 }
914
915 static TestRoutingCrash sRoutingCrash;
916
917 JNIEXPORT jint JNICALL
Java_com_mobileer_oboetester_TestRouteDuringCallbackActivity_startStream(JNIEnv * env,jobject instance,jboolean useInput)918 Java_com_mobileer_oboetester_TestRouteDuringCallbackActivity_startStream(
919 JNIEnv *env, jobject instance,
920 jboolean useInput) {
921 return sRoutingCrash.start(useInput);
922 }
923
924 JNIEXPORT jint JNICALL
Java_com_mobileer_oboetester_TestRouteDuringCallbackActivity_stopStream(JNIEnv * env,jobject instance)925 Java_com_mobileer_oboetester_TestRouteDuringCallbackActivity_stopStream(
926 JNIEnv *env, jobject instance) {
927 return sRoutingCrash.stop();
928 }
929
930 JNIEXPORT jint JNICALL
Java_com_mobileer_oboetester_TestRouteDuringCallbackActivity_getSleepTimeMicros(JNIEnv * env,jobject instance)931 Java_com_mobileer_oboetester_TestRouteDuringCallbackActivity_getSleepTimeMicros(
932 JNIEnv *env, jobject instance) {
933 return sRoutingCrash.getSleepTimeMicros();
934 }
935
936 static TestColdStartLatency sColdStartLatency;
937
938 JNIEXPORT jint JNICALL
Java_com_mobileer_oboetester_TestColdStartLatencyActivity_openStream(JNIEnv * env,jobject instance,jboolean useInput,jboolean useLowLatency,jboolean useMmap,jboolean useExclusive)939 Java_com_mobileer_oboetester_TestColdStartLatencyActivity_openStream(
940 JNIEnv *env, jobject instance,
941 jboolean useInput, jboolean useLowLatency, jboolean useMmap, jboolean useExclusive) {
942 return sColdStartLatency.open(useInput, useLowLatency, useMmap, useExclusive);
943 }
944
945 JNIEXPORT jint JNICALL
Java_com_mobileer_oboetester_TestColdStartLatencyActivity_startStream(JNIEnv * env,jobject instance)946 Java_com_mobileer_oboetester_TestColdStartLatencyActivity_startStream(
947 JNIEnv *env, jobject instance) {
948 return sColdStartLatency.start();
949 }
950
951 JNIEXPORT jint JNICALL
Java_com_mobileer_oboetester_TestColdStartLatencyActivity_closeStream(JNIEnv * env,jobject instance)952 Java_com_mobileer_oboetester_TestColdStartLatencyActivity_closeStream(
953 JNIEnv *env, jobject instance) {
954 return sColdStartLatency.close();
955 }
956
957 JNIEXPORT jint JNICALL
Java_com_mobileer_oboetester_TestColdStartLatencyActivity_getOpenTimeMicros(JNIEnv * env,jobject instance)958 Java_com_mobileer_oboetester_TestColdStartLatencyActivity_getOpenTimeMicros(
959 JNIEnv *env, jobject instance) {
960 return sColdStartLatency.getOpenTimeMicros();
961 }
962
963 JNIEXPORT jint JNICALL
Java_com_mobileer_oboetester_TestColdStartLatencyActivity_getStartTimeMicros(JNIEnv * env,jobject instance)964 Java_com_mobileer_oboetester_TestColdStartLatencyActivity_getStartTimeMicros(
965 JNIEnv *env, jobject instance) {
966 return sColdStartLatency.getStartTimeMicros();
967 }
968
969 JNIEXPORT jint JNICALL
Java_com_mobileer_oboetester_TestColdStartLatencyActivity_getColdStartTimeMicros(JNIEnv * env,jobject instance)970 Java_com_mobileer_oboetester_TestColdStartLatencyActivity_getColdStartTimeMicros(
971 JNIEnv *env, jobject instance) {
972 return sColdStartLatency.getColdStartTimeMicros();
973 }
974
975 JNIEXPORT jint JNICALL
Java_com_mobileer_oboetester_TestColdStartLatencyActivity_getAudioDeviceId(JNIEnv * env,jobject instance)976 Java_com_mobileer_oboetester_TestColdStartLatencyActivity_getAudioDeviceId(
977 JNIEnv *env, jobject instance) {
978 return sColdStartLatency.getDeviceId();
979 }
980
981 }
982