• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 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 _PLAYER_SAMPLEBUFFER_
18 #define _PLAYER_SAMPLEBUFFER_
19 
20 #include <wav/WavStreamReader.h>
21 
22 namespace iolib {
23 
24 /*
25  * Defines the relevant properties of the audio data being sourced.
26  */
27 struct AudioProperties {
28     int32_t channelCount;
29     int32_t sampleRate;
30 };
31 
32 class SampleBuffer {
33 public:
SampleBuffer()34     SampleBuffer() : mNumSamples(0) {};
~SampleBuffer()35     ~SampleBuffer() { unloadSampleData(); }
36 
37     // Data load/unload
38     void loadSampleData(parselib::WavStreamReader* reader);
39     void unloadSampleData();
40 
41     void resampleData(int sampleRate);
42 
getProperties()43     virtual AudioProperties getProperties() const { return mAudioProperties; }
44 
getSampleData()45     float* getSampleData() { return mSampleData; }
getNumSampleFrames()46     int32_t getNumSampleFrames() { return mNumSamples; }
47 
48 protected:
49     AudioProperties mAudioProperties;
50 
51     float*  mSampleData;
52     int32_t mNumSamples;
53 };
54 
55 }
56 
57 #endif //_PLAYER_SAMPLEBUFFER_
58