1 /* ------------------------------------------------------------------ 2 * Copyright (C) 1998-2009 PacketVideo 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 13 * express or implied. 14 * See the License for the specific language governing permissions 15 * and limitations under the License. 16 * ------------------------------------------------------------------- 17 */ 18 #ifndef PVWAVFILEPARSER_H_INCLUDED 19 #define PVWAVFILEPARSER_H_INCLUDED 20 21 //---------------------------------------------------------------------------- 22 // INCLUDES 23 //---------------------------------------------------------------------------- 24 25 #ifndef OSCL_BASE_H_INCLUDED 26 #include "oscl_base.h" 27 #endif 28 29 #ifndef OSCL_STRING_H_INCLUDED 30 #include "oscl_string.h" 31 #endif 32 33 #ifndef OSCL_FILE_IO_H_INCLUDED 34 #include "oscl_file_io.h" 35 #endif 36 37 #ifndef OSCL_MEM_H_INCLUDED 38 #include "oscl_mem.h" 39 #endif 40 41 #ifndef OSCL_VECTOR_H_INCLUDED 42 #include "oscl_vector.h" 43 #endif 44 45 46 //////////////////////////////////WAV File parser 47 48 // This enumeration lists the formats currently supported 49 enum PVWavAudioFormats 50 { 51 PVWAV_UNKNOWN_AUDIO_FORMAT = 0, 52 PVWAV_PCM_AUDIO_FORMAT = 1, 53 PVWAV_ITU_G711_ALAW = 6, 54 PVWAV_ITU_G711_ULAW = 7 55 }; 56 57 58 typedef struct 59 { 60 int32 AudioFormat; 61 uint16 NumChannels; 62 uint16 BlockAlign; 63 uint16 BitsPerSample; 64 uint16 BytesPerSample; // takes into account byte alignment 65 uint32 SampleRate; 66 uint32 ByteRate; 67 uint32 NumSamples; // Total number of Samples 68 bool isLittleEndian; // 1 if data is little endian and 0 if it is big endian 69 } PVWAVFileInfo; 70 71 enum PVWavParserReturnCode 72 { 73 // Return codes 74 PVWAVPARSER_OK = 0, 75 PVWAVPARSER_READ_ERROR = -1, 76 PVWAVPARSER_MISC_ERROR = -2, 77 PVWAVPARSER_UNSUPPORTED_FORMAT = -3, 78 PVWAVPARSER_END_OF_FILE = -4 79 }; 80 81 class PV_Wav_Parser 82 { 83 public: 84 OSCL_IMPORT_REF PV_Wav_Parser() 85 { 86 AudioFormat = 0; 87 NumChannels = 0; 88 SampleRate = 0; 89 ByteRate = 0; 90 BlockAlign = 0; 91 BitsPerSample = 0; 92 BytesPerSample = 0; 93 xLawTable = NULL; 94 PCMBytesRead = 0; 95 PCMBytesPresent = 0; 96 ipWAVFile = NULL; 97 iHeaderSize = 0; 98 isLittleEndian = 1; // little endian by default 99 iEndOfDataSubChunkOffset = 0; 100 } 101 102 OSCL_IMPORT_REF ~PV_Wav_Parser(); 103 //{ 104 // CleanupWAVFile(); 105 //} 106 107 // Will parse WAVE File 108 OSCL_IMPORT_REF PVWavParserReturnCode InitWavParser(OSCL_wString& aClip, Oscl_FileServer* aFileSession); 109 110 // Returns number of samples copied to the buffer 111 OSCL_IMPORT_REF PVWavParserReturnCode GetPCMData(uint8* inBuff, uint32 inBufSize, uint32 NumberOfSamples, uint32& NumSamplesRead); 112 113 // Copies Number of Channels, Sampling rate and Bits per sample to input parameters 114 OSCL_IMPORT_REF bool RetrieveFileInfo(PVWAVFileInfo& aInfo); 115 116 //Seek in PCM Data (Seeks the file position to SampleNumber specified so that user can then get PCM data starting from that Sample) 117 OSCL_IMPORT_REF PVWavParserReturnCode SeekPCMSample(uint32 SampleNumber); 118 119 //Set the paser output to uncompressed PCM. 120 OSCL_IMPORT_REF bool SetOutputToUncompressedPCM(void); 121 private: 122 PVWavParserReturnCode ReadData(uint8* buff, uint32 size, uint32& bytesread); 123 OSCL_IMPORT_REF void CleanupWAVFile(void); 124 125 //Subchunk 1 126 uint16 AudioFormat; 127 uint16 NumChannels; 128 uint32 SampleRate; 129 uint32 ByteRate; 130 uint16 BlockAlign; 131 uint16 BitsPerSample; 132 uint16 BytesPerSample; 133 bool isLittleEndian; // 1 if data is little endian and 0 if it is big endian 134 135 short *xLawTable; 136 137 // It will be incremented when PCM data is read and compared to Subchunk2_size to determine whether whole file has been read or not 138 uint32 PCMBytesRead; 139 uint32 PCMBytesPresent;// PCM data size in bytes 140 uint32 NumSamples; 141 uint32 iEndOfDataSubChunkOffset; 142 143 // Pointer to input file (File to be opened and file pointer kept with the class. It will be closed when no data is left in file descriptor of class) 144 Oscl_File* ipWAVFile; 145 146 // header size (size of data before data subchunk) 147 uint32 iHeaderSize; 148 }; 149 150 151 #endif // PVWAVFILEPARSER_H_INCLUDED 152