1 /* 2 * Copyright 2022 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 #include <fstream> 18 #include <vector> 19 20 namespace bluetooth { 21 namespace testing { 22 23 struct WavHeader { 24 // RIFF chunk descriptor 25 uint8_t chunk_id[4]; 26 uint32_t chunk_size; 27 uint8_t chunk_format[4]; 28 // "fmt" sub-chunk 29 uint8_t subchunk1_id[4]; 30 uint32_t subchunk1_size; 31 uint16_t audio_format; 32 uint16_t num_channels; 33 uint32_t sample_rate; 34 uint32_t byte_rate; 35 uint16_t block_align; 36 uint16_t bits_per_sample; 37 // "data" sub-chunk 38 uint8_t subchunk2_id[4]; 39 uint32_t subchunk2_size; 40 }; 41 42 namespace { 43 constexpr size_t kWavHeaderSize = sizeof(WavHeader); 44 } 45 46 class WavReader { 47 public: 48 WavReader(const char* filename); 49 ~WavReader(); 50 WavHeader GetHeader() const; 51 uint8_t* GetSamples(); 52 size_t GetSampleCount(); 53 54 private: 55 std::ifstream wavFile_; 56 WavHeader header_; 57 std::vector<uint8_t> samples_; 58 59 void ReadSamples(); 60 }; 61 62 } // namespace testing 63 } // namespace bluetooth 64