1 /*
2  * Copyright 2020 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 package org.hyphonate.megaaudio.player;
17 
18 public class NativeAudioSource extends AudioSource {
19     private long    mNativeSourcePtr;
20 
NativeAudioSource(long nativeSourcePtr)21     public NativeAudioSource(long nativeSourcePtr) {
22         mNativeSourcePtr = nativeSourcePtr;
23     }
24 
25     // Use this to call the AudioSource methods in C++ directly
getNativeObject()26     public long getNativeObject() { return mNativeSourcePtr; }
27 
28     @Override
init(int numFrames, int numChans)29     public void init(int numFrames, int numChans) {
30         initN(mNativeSourcePtr, numFrames, numChans);
31     }
32 
33     // These can be called from Java, but only do so if you don't mind the JNI overhead
34     @Override
reset()35     public void reset() {
36         resetN(mNativeSourcePtr);
37     }
38 
39     @Override
trigger()40     public void trigger() {
41         triggerN(mNativeSourcePtr);
42     }
43 
44     @Override
pull(float[] audioData, int numFrames, int numChans)45     public int pull(float[] audioData, int numFrames, int numChans) {
46         return pullN(mNativeSourcePtr, audioData, numFrames, numChans);
47     }
48 
initN(long nativeSourcePtr, int numFrames, int numChans)49     private native void initN(long nativeSourcePtr, int numFrames, int numChans);
resetN(long nativeSourcePtr)50     private native void resetN(long nativeSourcePtr);
triggerN(long nativeSourcePtr)51     private native void triggerN(long nativeSourcePtr);
pullN(long nativeSourcePtr, float[] audioData, int numFrames, int numChans)52     private native int pullN(long nativeSourcePtr, float[] audioData, int numFrames, int numChans);
53 }
54