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 abstract class AudioSource { AudioSource()19 public AudioSource() {} 20 21 /** 22 * Called before the stream starts to allow initialization of the source 23 * @param numFrames The number of frames that will be requested in each pull() call. 24 * @param numChans The number of channels in the stream. 25 */ init(int numFrames, int numChans)26 public void init(int numFrames, int numChans) {} 27 start()28 public void start() {} stop()29 public void stop() {} 30 31 /** 32 * reset a stream to the beginning. 33 */ reset()34 public void reset() {} 35 36 /** 37 * triggers some event in the AudioSource. Whatever that event is is up to the AudioSource 38 * subclass. 39 */ trigger()40 public void trigger() {} 41 42 /** 43 * Process a request for audio data. 44 * @param audioData The buffer to be filled. 45 * @param numFrames The number of frames of audio to provide. 46 * @param numChans The number of channels (in the buffer) required by the player. 47 * @return The number of frames actually generated. If this value is less than that 48 * requested, it may be interpreted by the player as the end of playback. 49 * Note that the player will be blocked by this call. 50 * Note that the data is assumed to be *interleaved*. 51 */ pull(float[] audioData, int numFrames, int numChans)52 public abstract int pull(float[] audioData, int numFrames, int numChans); 53 } 54