• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2019 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 #ifndef _IO_WAV_WAVSTREAMREADER_H_
17 #define _IO_WAV_WAVSTREAMREADER_H_
18 
19 #include <map>
20 
21 #include "AudioEncoding.h"
22 #include "WavRIFFChunkHeader.h"
23 #include "WavFmtChunkHeader.h"
24 
25 /*
26  * WAV format documentation can be found:
27  * http://soundfile.sapp.org/doc/WaveFormat/
28  * https://web.archive.org/web/20090417165828/http://www.kk.iij4u.or.jp/~kondo/wave/mpidata.txt
29  */
30 namespace parselib {
31 
32 class InputStream;
33 
34 class WavStreamReader {
35 public:
36     WavStreamReader(InputStream *stream);
37 
getSampleRate()38     int getSampleRate() { return mFmtChunk->mSampleRate; }
39 
getNumSampleFrames()40     int getNumSampleFrames() {
41         return mDataChunk->mChunkSize / (mFmtChunk->mSampleSize / 8) / mFmtChunk->mNumChannels;
42     }
43 
getNumChannels()44     int getNumChannels() { return mFmtChunk != 0 ? mFmtChunk->mNumChannels : 0; }
45 
46     int getSampleEncoding();
47 
getBitsPerSample()48     int getBitsPerSample() { return mFmtChunk->mSampleSize; }
49 
50     void parse();
51 
52     // Data access
53     void positionToAudio();
54 
55     int getDataFloat(float *buff, int numFrames);
56 
57     // int getData16(short *buff, int numFramees);
58 
59 protected:
60     InputStream *mStream;
61 
62     WavRIFFChunkHeader *mWavChunk;
63     WavFmtChunkHeader *mFmtChunk;
64     WavChunkHeader *mDataChunk;
65 
66     long mAudioDataStartPos;
67 
68     std::map<RiffID, WavChunkHeader *> *mChunkMap;
69 };
70 
71 } // namespace parselib
72 
73 #endif // _IO_WAV_WAVSTREAMREADER_H_
74