blob: c140ef27cccbb1397e04ce8bc07926c6b42f3182 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
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 Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef MODULES_AUDIO_CODING_TEST_PCMFILE_H_
12#define MODULES_AUDIO_CODING_TEST_PCMFILE_H_
niklase@google.com470e71d2011-07-07 08:21:25 +000013
pbos@webrtc.org12dc1a32013-08-05 16:22:53 +000014#include <stdio.h>
15#include <stdlib.h>
16
tina.legrand@webrtc.orgba468042012-08-17 10:38:28 +000017#include <string>
niklase@google.com470e71d2011-07-07 08:21:25 +000018
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020019#include "api/optional.h"
20#include "modules/include/module_common_types.h"
21#include "typedefs.h"
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000022
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000023namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:25 +000024
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000025class PCMFile {
26 public:
27 PCMFile();
pbos@webrtc.org0946a562013-04-09 00:28:06 +000028 PCMFile(uint32_t timestamp);
kwiberg65fc8b92016-08-29 10:05:24 -070029 ~PCMFile();
tina.legrand@webrtc.orgba468042012-08-17 10:38:28 +000030
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000031 void Open(const std::string& filename, uint16_t frequency, const char* mode,
32 bool auto_rewind = false);
niklase@google.com470e71d2011-07-07 08:21:25 +000033
pbos@webrtc.org0946a562013-04-09 00:28:06 +000034 int32_t Read10MsData(AudioFrame& audio_frame);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000035
yujo36b1a5f2017-06-12 12:45:32 -070036 void Write10MsData(const int16_t *playout_buffer, size_t length_smpls);
37 void Write10MsData(const AudioFrame& audio_frame);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000038
pbos@webrtc.org0946a562013-04-09 00:28:06 +000039 uint16_t PayloadLength10Ms() const;
40 int32_t SamplingFrequency() const;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000041 void Close();
42 bool EndOfFile() const {
43 return end_of_file_;
44 }
Henrik Lundin4d682082015-12-10 16:24:39 +010045 // 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.orga6ecd1e2012-04-26 07:54:30 +000049 void Rewind();
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000050 static int16_t ChooseFile(std::string* file_name, int16_t max_len,
pbos@webrtc.org0946a562013-04-09 00:28:06 +000051 uint16_t* frequency_hz);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000052 bool Rewinded();
53 void SaveStereo(bool is_stereo = true);
54 void ReadStereo(bool is_stereo = true);
Henrik Lundin4d682082015-12-10 16:24:39 +010055 // 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.orga6ecd1e2012-04-26 07:54:30 +000060 private:
61 FILE* pcm_file_;
pbos@webrtc.org0946a562013-04-09 00:28:06 +000062 uint16_t samples_10ms_;
63 int32_t frequency_;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000064 bool end_of_file_;
65 bool auto_rewind_;
66 bool rewinded_;
pbos@webrtc.org0946a562013-04-09 00:28:06 +000067 uint32_t timestamp_;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000068 bool read_stereo_;
69 bool save_stereo_;
Henrik Lundin4d682082015-12-10 16:24:39 +010070 rtc::Optional<int> num_10ms_blocks_to_read_;
71 int blocks_read_ = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000072};
73
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000074} // namespace webrtc
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000075
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020076#endif // MODULES_AUDIO_CODING_TEST_PCMFILE_H_