blob: 840933a1bd88c73708cc0f378d17a74fa365ab11 [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
kjellander3e6db232015-11-26 04:44:54 -080011#ifndef WEBRTC_MODULES_AUDIO_CODING_TEST_PCMFILE_H_
12#define WEBRTC_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
Henrik Lundin4d682082015-12-10 16:24:39 +010019#include "webrtc/base/optional.h"
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010020#include "webrtc/modules/include/module_common_types.h"
turaj@webrtc.org6ea3d1c2013-10-02 21:44:33 +000021#include "webrtc/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);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000029 ~PCMFile() {
30 if (pcm_file_ != NULL) {
31 fclose(pcm_file_);
niklase@google.com470e71d2011-07-07 08:21:25 +000032 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000033 }
tina.legrand@webrtc.orgba468042012-08-17 10:38:28 +000034
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000035 void Open(const std::string& filename, uint16_t frequency, const char* mode,
36 bool auto_rewind = false);
niklase@google.com470e71d2011-07-07 08:21:25 +000037
pbos@webrtc.org0946a562013-04-09 00:28:06 +000038 int32_t Read10MsData(AudioFrame& audio_frame);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000039
Peter Kastingdce40cf2015-08-24 14:52:23 -070040 void Write10MsData(int16_t *playout_buffer, size_t length_smpls);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000041 void Write10MsData(AudioFrame& audio_frame);
42
pbos@webrtc.org0946a562013-04-09 00:28:06 +000043 uint16_t PayloadLength10Ms() const;
44 int32_t SamplingFrequency() const;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000045 void Close();
46 bool EndOfFile() const {
47 return end_of_file_;
48 }
Henrik Lundin4d682082015-12-10 16:24:39 +010049 // Moves forward the specified number of 10 ms blocks. If a limit has been set
50 // with SetNum10MsBlocksToRead, fast-forwarding does not count towards this
51 // limit.
52 void FastForward(int num_10ms_blocks);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000053 void Rewind();
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000054 static int16_t ChooseFile(std::string* file_name, int16_t max_len,
pbos@webrtc.org0946a562013-04-09 00:28:06 +000055 uint16_t* frequency_hz);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000056 bool Rewinded();
57 void SaveStereo(bool is_stereo = true);
58 void ReadStereo(bool is_stereo = true);
Henrik Lundin4d682082015-12-10 16:24:39 +010059 // If set, the reading will stop after the specified number of blocks have
60 // been read. When that has happened, EndOfFile() will return true. Calling
61 // Rewind() will reset the counter and start over.
62 void SetNum10MsBlocksToRead(int value);
63
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000064 private:
65 FILE* pcm_file_;
pbos@webrtc.org0946a562013-04-09 00:28:06 +000066 uint16_t samples_10ms_;
67 int32_t frequency_;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000068 bool end_of_file_;
69 bool auto_rewind_;
70 bool rewinded_;
pbos@webrtc.org0946a562013-04-09 00:28:06 +000071 uint32_t timestamp_;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000072 bool read_stereo_;
73 bool save_stereo_;
Henrik Lundin4d682082015-12-10 16:24:39 +010074 rtc::Optional<int> num_10ms_blocks_to_read_;
75 int blocks_read_ = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000076};
77
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000078} // namespace webrtc
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000079
kjellander3e6db232015-11-26 04:44:54 -080080#endif // WEBRTC_MODULES_AUDIO_CODING_TEST_PCMFILE_H_