• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     /**
34      * Specifies the sample rate for the source.
35      * @param sampleRate The sample rate for this source.
36      */
setSampleRate(int sampleRate)37     public void setSampleRate(int sampleRate) {
38         setSampleRateN(mNativeSourcePtr, sampleRate);
39     }
40 
41     /**
42      * (for period sources) sets the frequency of the signal
43      * @param freq
44      */
setFreq(float freq)45     public void setFreq(float freq) {
46         setFreqN(mNativeSourcePtr, freq);
47     };
48 
49     // These can be called from Java, but only do so if you don't mind the JNI overhead
50     @Override
reset()51     public void reset() {
52         resetN(mNativeSourcePtr);
53     }
54 
55     @Override
trigger()56     public void trigger() {
57         triggerN(mNativeSourcePtr);
58     }
59 
60     @Override
pull(float[] audioData, int numFrames, int numChans)61     public int pull(float[] audioData, int numFrames, int numChans) {
62         return pullN(mNativeSourcePtr, audioData, numFrames, numChans);
63     }
64 
initN(long nativeSourcePtr, int numFrames, int numChans)65     private native void initN(long nativeSourcePtr, int numFrames, int numChans);
setSampleRateN(long nativeSourcePtr, int sampleRate)66     private native void setSampleRateN(long nativeSourcePtr, int sampleRate);
setFreqN(long nativeSourcePtr, float freq)67     private native void setFreqN(long nativeSourcePtr, float freq);
resetN(long nativeSourcePtr)68     private native void resetN(long nativeSourcePtr);
triggerN(long nativeSourcePtr)69     private native void triggerN(long nativeSourcePtr);
pullN(long nativeSourcePtr, float[] audioData, int numFrames, int numChans)70     private native int pullN(long nativeSourcePtr, float[] audioData, int numFrames, int numChans);
71 }
72