blob: c4487b813321d336b875829aae2ceb475367d80b [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
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000011#ifndef WEBRTC_MODULES_AUDIO_CODING_MAIN_TEST_PCMFILE_H_
12#define WEBRTC_MODULES_AUDIO_CODING_MAIN_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
turaj@webrtc.org6ea3d1c2013-10-02 21:44:33 +000019#include "webrtc/modules/interface/module_common_types.h"
20#include "webrtc/typedefs.h"
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000021
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000022namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:25 +000023
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000024class PCMFile {
25 public:
26 PCMFile();
pbos@webrtc.org0946a562013-04-09 00:28:06 +000027 PCMFile(uint32_t timestamp);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000028 ~PCMFile() {
29 if (pcm_file_ != NULL) {
30 fclose(pcm_file_);
niklase@google.com470e71d2011-07-07 08:21:25 +000031 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000032 }
tina.legrand@webrtc.orgba468042012-08-17 10:38:28 +000033
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000034 void Open(const std::string& filename, uint16_t frequency, const char* mode,
35 bool auto_rewind = false);
niklase@google.com470e71d2011-07-07 08:21:25 +000036
pbos@webrtc.org0946a562013-04-09 00:28:06 +000037 int32_t Read10MsData(AudioFrame& audio_frame);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000038
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000039 void Write10MsData(int16_t *playout_buffer, uint16_t length_smpls);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000040 void Write10MsData(AudioFrame& audio_frame);
41
pbos@webrtc.org0946a562013-04-09 00:28:06 +000042 uint16_t PayloadLength10Ms() const;
43 int32_t SamplingFrequency() const;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000044 void Close();
45 bool EndOfFile() const {
46 return end_of_file_;
47 }
48 void Rewind();
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000049 static int16_t ChooseFile(std::string* file_name, int16_t max_len,
pbos@webrtc.org0946a562013-04-09 00:28:06 +000050 uint16_t* frequency_hz);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000051 bool Rewinded();
52 void SaveStereo(bool is_stereo = true);
53 void ReadStereo(bool is_stereo = true);
54 private:
55 FILE* pcm_file_;
pbos@webrtc.org0946a562013-04-09 00:28:06 +000056 uint16_t samples_10ms_;
57 int32_t frequency_;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000058 bool end_of_file_;
59 bool auto_rewind_;
60 bool rewinded_;
pbos@webrtc.org0946a562013-04-09 00:28:06 +000061 uint32_t timestamp_;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000062 bool read_stereo_;
63 bool save_stereo_;
niklase@google.com470e71d2011-07-07 08:21:25 +000064};
65
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000066} // namespace webrtc
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000067
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000068#endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_TEST_PCMFILE_H_