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 17 #ifndef MEGA_PLAYER_AUDIOSOURCE_H 18 #define MEGA_PLAYER_AUDIOSOURCE_H 19 20 class AudioSource { 21 public: AudioSource()22 AudioSource() {} ~AudioSource()23 virtual ~AudioSource() {} 24 25 static const int NUMCHANNELS_UNSPECIFIED = -1; 26 static const int NUMCHANNELS_ERROR = -2; getNumChannels()27 virtual int getNumChannels() { return NUMCHANNELS_UNSPECIFIED; } 28 29 // Encoding Constants (specific to MegaAudio) 30 static const int ENCODING_UNSPECIFIED = -1; 31 static const int ENCODING_ERROR = -2; 32 static const int ENCODING_UNINITIALIZED = 0; 33 static const int ENCODING_FLOAT = 1; 34 static const int ENCODING_PCM16 = 2; 35 static const int ENCODING_PCM24 = 3; 36 static const int ENCODING_PCM32 = 4; getEncoding()37 virtual int getEncoding() { return ENCODING_UNSPECIFIED; }; 38 39 /** 40 * Called before the stream starts to allow initialization of the source 41 * @param numFrames The number of frames that will be requested in each pull() call. 42 * @param numChans The number of channels in the stream. 43 */ init(int numFrames,int numChans)44 virtual void init(int numFrames, int numChans) {} 45 setSampleRate(int sampleRate)46 virtual void setSampleRate(int sampleRate) {} 47 setFreq(float freq)48 virtual void setFreq(float freq) {} 49 50 /** 51 * Reset the stream to its beginning 52 */ reset()53 virtual void reset() {} 54 trigger()55 virtual void trigger() {} 56 57 /** 58 * Process a request for audio data. 59 * @param audioData The buffer to be filled. 60 * @param numFrames The number of frames of audio to provide. 61 * @param numChans The number of channels (in the buffer) required by the player. 62 * @return The number of frames actually generated. If this value is less than that 63 * requested, it may be interpreted by the player as the end of playback. 64 * Note that the player will be blocked by this call. 65 * Note that the data is assumed to be *interleaved*. 66 */ 67 virtual int pull(float* buffer, int numFrames, int numChans) = 0; 68 }; 69 70 #endif // MEGA_PLAYER_AUDIOSOURCE_H 71