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 28 // This may be relevant to concrete classes which produce a sound with a notion of pitch setSampleRate(int sampleRate)29 public void setSampleRate(int sampleRate) {} 30 31 /** 32 * (for period sources) sets the frequency of the signal 33 * @param freq 34 */ setFreq(float freq)35 public void setFreq(float freq) {} 36 start()37 public void start() {} stop()38 public void stop() {} 39 40 /** 41 * reset a stream to the beginning. 42 */ reset()43 public void reset() {} 44 45 /** 46 * triggers some event in the AudioSource. Whatever that event is is up to the AudioSource 47 * subclass. 48 */ trigger()49 public void trigger() {} 50 51 /** 52 * Process a request for audio data. 53 * @param audioData The buffer to be filled. 54 * @param numFrames The number of frames of audio to provide. 55 * @param numChans The number of channels (in the buffer) required by the player. 56 * @return The number of frames actually generated. If this value is less than that 57 * requested, it may be interpreted by the player as the end of playback. 58 * Note that the player will be blocked by this call. 59 * Note that the data is assumed to be *interleaved*. 60 */ pull(float[] audioData, int numFrames, int numChans)61 public abstract int pull(float[] audioData, int numFrames, int numChans); 62 } 63