niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame^] | 11 | #ifndef MODULES_AUDIO_CODING_TEST_PCMFILE_H_ |
| 12 | #define MODULES_AUDIO_CODING_TEST_PCMFILE_H_ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 13 | |
pbos@webrtc.org | 12dc1a3 | 2013-08-05 16:22:53 +0000 | [diff] [blame] | 14 | #include <stdio.h> |
| 15 | #include <stdlib.h> |
| 16 | |
tina.legrand@webrtc.org | ba46804 | 2012-08-17 10:38:28 +0000 | [diff] [blame] | 17 | #include <string> |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 18 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame^] | 19 | #include "api/optional.h" |
| 20 | #include "modules/include/module_common_types.h" |
| 21 | #include "typedefs.h" |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 22 | |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 23 | namespace webrtc { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 24 | |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 25 | class PCMFile { |
| 26 | public: |
| 27 | PCMFile(); |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 28 | PCMFile(uint32_t timestamp); |
kwiberg | 65fc8b9 | 2016-08-29 10:05:24 -0700 | [diff] [blame] | 29 | ~PCMFile(); |
tina.legrand@webrtc.org | ba46804 | 2012-08-17 10:38:28 +0000 | [diff] [blame] | 30 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 31 | void Open(const std::string& filename, uint16_t frequency, const char* mode, |
| 32 | bool auto_rewind = false); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 33 | |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 34 | int32_t Read10MsData(AudioFrame& audio_frame); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 35 | |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 36 | void Write10MsData(const int16_t *playout_buffer, size_t length_smpls); |
| 37 | void Write10MsData(const AudioFrame& audio_frame); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 38 | |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 39 | uint16_t PayloadLength10Ms() const; |
| 40 | int32_t SamplingFrequency() const; |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 41 | void Close(); |
| 42 | bool EndOfFile() const { |
| 43 | return end_of_file_; |
| 44 | } |
Henrik Lundin | 4d68208 | 2015-12-10 16:24:39 +0100 | [diff] [blame] | 45 | // Moves forward the specified number of 10 ms blocks. If a limit has been set |
| 46 | // with SetNum10MsBlocksToRead, fast-forwarding does not count towards this |
| 47 | // limit. |
| 48 | void FastForward(int num_10ms_blocks); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 49 | void Rewind(); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 50 | static int16_t ChooseFile(std::string* file_name, int16_t max_len, |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 51 | uint16_t* frequency_hz); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 52 | bool Rewinded(); |
| 53 | void SaveStereo(bool is_stereo = true); |
| 54 | void ReadStereo(bool is_stereo = true); |
Henrik Lundin | 4d68208 | 2015-12-10 16:24:39 +0100 | [diff] [blame] | 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 | |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 60 | private: |
| 61 | FILE* pcm_file_; |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 62 | uint16_t samples_10ms_; |
| 63 | int32_t frequency_; |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 64 | bool end_of_file_; |
| 65 | bool auto_rewind_; |
| 66 | bool rewinded_; |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 67 | uint32_t timestamp_; |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 68 | bool read_stereo_; |
| 69 | bool save_stereo_; |
Henrik Lundin | 4d68208 | 2015-12-10 16:24:39 +0100 | [diff] [blame] | 70 | rtc::Optional<int> num_10ms_blocks_to_read_; |
| 71 | int blocks_read_ = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 72 | }; |
| 73 | |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 74 | } // namespace webrtc |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 75 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame^] | 76 | #endif // MODULES_AUDIO_CODING_TEST_PCMFILE_H_ |