1 /*
2 * Copyright 2017 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 #include <jni.h>
18 #include <oboe/Oboe.h>
19 #include "HelloOboeEngine.h"
20 #include "logging_macros.h"
21
22 extern "C" {
23 /* We only need one HelloOboeEngine and it is needed for the entire time.
24 * So just allocate one statically. */
25 static HelloOboeEngine sEngine;
26
27 JNIEXPORT jint JNICALL
Java_com_google_oboe_samples_hellooboe_PlaybackEngine_startEngine(JNIEnv * env,jclass,int audioApi,int deviceId,int channelCount)28 Java_com_google_oboe_samples_hellooboe_PlaybackEngine_startEngine(
29 JNIEnv *env,
30 jclass,
31 int audioApi, int deviceId, int channelCount) {
32 return static_cast<jint>(sEngine.start((oboe::AudioApi)audioApi, deviceId, channelCount));
33 }
34
35 JNIEXPORT jint JNICALL
Java_com_google_oboe_samples_hellooboe_PlaybackEngine_stopEngine(JNIEnv * env,jclass)36 Java_com_google_oboe_samples_hellooboe_PlaybackEngine_stopEngine(
37 JNIEnv *env,
38 jclass) {
39 return static_cast<jint>(sEngine.stop());
40 }
41
42 JNIEXPORT void JNICALL
Java_com_google_oboe_samples_hellooboe_PlaybackEngine_setToneOn(JNIEnv * env,jclass,jboolean isToneOn)43 Java_com_google_oboe_samples_hellooboe_PlaybackEngine_setToneOn(
44 JNIEnv *env,
45 jclass,
46 jboolean isToneOn) {
47
48 sEngine.tap(isToneOn);
49 }
50
51
52 JNIEXPORT void JNICALL
Java_com_google_oboe_samples_hellooboe_PlaybackEngine_setBufferSizeInBursts(JNIEnv * env,jclass,jint bufferSizeInBursts)53 Java_com_google_oboe_samples_hellooboe_PlaybackEngine_setBufferSizeInBursts(
54 JNIEnv *env,
55 jclass,
56 jint bufferSizeInBursts) {
57 sEngine.setBufferSizeInBursts(bufferSizeInBursts);
58 }
59
60 JNIEXPORT jdouble JNICALL
Java_com_google_oboe_samples_hellooboe_PlaybackEngine_getCurrentOutputLatencyMillis(JNIEnv * env,jclass)61 Java_com_google_oboe_samples_hellooboe_PlaybackEngine_getCurrentOutputLatencyMillis(
62 JNIEnv *env,
63 jclass) {
64 return static_cast<jdouble>(sEngine.getCurrentOutputLatencyMillis());
65 }
66
67 JNIEXPORT jboolean JNICALL
Java_com_google_oboe_samples_hellooboe_PlaybackEngine_isLatencyDetectionSupported(JNIEnv * env,jclass)68 Java_com_google_oboe_samples_hellooboe_PlaybackEngine_isLatencyDetectionSupported(
69 JNIEnv *env,
70 jclass) {
71 return (sEngine.isLatencyDetectionSupported() ? JNI_TRUE : JNI_FALSE);
72 }
73
74 JNIEXPORT jboolean JNICALL
Java_com_google_oboe_samples_hellooboe_PlaybackEngine_isAAudioRecommended(JNIEnv * env,jclass)75 Java_com_google_oboe_samples_hellooboe_PlaybackEngine_isAAudioRecommended(
76 JNIEnv *env,
77 jclass) {
78 return (sEngine.isAAudioRecommended() ? JNI_TRUE : JNI_FALSE);
79 }
80
81 JNIEXPORT void JNICALL
Java_com_google_oboe_samples_hellooboe_PlaybackEngine_setDefaultStreamValues(JNIEnv * env,jclass,jint sampleRate,jint framesPerBurst)82 Java_com_google_oboe_samples_hellooboe_PlaybackEngine_setDefaultStreamValues(
83 JNIEnv *env,
84 jclass,
85 jint sampleRate,
86 jint framesPerBurst) {
87 oboe::DefaultStreamValues::SampleRate = (int32_t) sampleRate;
88 oboe::DefaultStreamValues::FramesPerBurst = (int32_t) framesPerBurst;
89 }
90 } // extern "C"
91