• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.google.oboe.samples.hellooboe;
2 /*
3  * Copyright 2017 The Android Open Source Project
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 import android.content.Context;
19 import android.media.AudioManager;
20 import android.os.Build;
21 
22 public class PlaybackEngine {
23     // Load native library
24     static {
25         System.loadLibrary("hello-oboe");
26     }
27 
setDefaultStreamValues(Context context)28     static void setDefaultStreamValues(Context context) {
29         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1){
30             AudioManager myAudioMgr = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
31             String sampleRateStr = myAudioMgr.getProperty(AudioManager.PROPERTY_OUTPUT_SAMPLE_RATE);
32             int defaultSampleRate = Integer.parseInt(sampleRateStr);
33             String framesPerBurstStr = myAudioMgr.getProperty(AudioManager.PROPERTY_OUTPUT_FRAMES_PER_BUFFER);
34             int defaultFramesPerBurst = Integer.parseInt(framesPerBurstStr);
35 
36             setDefaultStreamValues(defaultSampleRate, defaultFramesPerBurst);
37         }
38     }
39 
40 
41     // Native methods that require audioserver calls and might take several seconds.
startEngine(int audioApi, int deviceId, int channelCount)42     static native int startEngine(int audioApi, int deviceId, int channelCount);
stopEngine()43     static native int stopEngine();
44 
45     // Native methods that only talk to the native client code.
setToneOn(boolean isToneOn)46     static native void setToneOn(boolean isToneOn);
setBufferSizeInBursts(int bufferSizeInBursts)47     static native void setBufferSizeInBursts(int bufferSizeInBursts);
getCurrentOutputLatencyMillis()48     static native double getCurrentOutputLatencyMillis();
isLatencyDetectionSupported()49     static native boolean isLatencyDetectionSupported();
isAAudioRecommended()50     static native boolean isAAudioRecommended();
setDefaultStreamValues(int sampleRate, int framesPerBurst)51     static native void setDefaultStreamValues(int sampleRate, int framesPerBurst);
52 }
53