1 /* 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #ifndef MODULES_AUDIO_CODING_TEST_PCMFILE_H_ 12 #define MODULES_AUDIO_CODING_TEST_PCMFILE_H_ 13 14 #include <stdio.h> 15 #include <stdlib.h> 16 17 #include <string> 18 19 #include "absl/types/optional.h" 20 #include "api/audio/audio_frame.h" 21 22 namespace webrtc { 23 24 class PCMFile { 25 public: 26 PCMFile(); 27 PCMFile(uint32_t timestamp); 28 ~PCMFile(); 29 30 void Open(const std::string& filename, 31 uint16_t frequency, 32 const char* mode, 33 bool auto_rewind = false); 34 35 int32_t Read10MsData(AudioFrame& audio_frame); 36 37 void Write10MsData(const int16_t* playout_buffer, size_t length_smpls); 38 void Write10MsData(const AudioFrame& audio_frame); 39 40 uint16_t PayloadLength10Ms() const; 41 int32_t SamplingFrequency() const; 42 void Close(); EndOfFile()43 bool EndOfFile() const { return end_of_file_; } 44 // Moves forward the specified number of 10 ms blocks. If a limit has been set 45 // with SetNum10MsBlocksToRead, fast-forwarding does not count towards this 46 // limit. 47 void FastForward(int num_10ms_blocks); 48 void Rewind(); 49 static int16_t ChooseFile(std::string* file_name, 50 int16_t max_len, 51 uint16_t* frequency_hz); 52 bool Rewinded(); 53 void SaveStereo(bool is_stereo = true); 54 void ReadStereo(bool is_stereo = true); 55 // If set, the reading will stop after the specified number of blocks have 56 // been read. When that has happened, EndOfFile() will return true. Calling 57 // Rewind() will reset the counter and start over. 58 void SetNum10MsBlocksToRead(int value); 59 60 private: 61 FILE* pcm_file_; 62 uint16_t samples_10ms_; 63 int32_t frequency_; 64 bool end_of_file_; 65 bool auto_rewind_; 66 bool rewinded_; 67 uint32_t timestamp_; 68 bool read_stereo_; 69 bool save_stereo_; 70 absl::optional<int> num_10ms_blocks_to_read_; 71 int blocks_read_ = 0; 72 }; 73 74 } // namespace webrtc 75 76 #endif // MODULES_AUDIO_CODING_TEST_PCMFILE_H_ 77