blob: bd2ce217d66eb20665ef0d606b510ff60e154a21 [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
niklase@google.com470e71d2011-07-07 08:21:25 +000014#include <cstdio>
15#include <cstdlib>
tina.legrand@webrtc.orgba468042012-08-17 10:38:28 +000016#include <string>
niklase@google.com470e71d2011-07-07 08:21:25 +000017
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000018#include "module_common_types.h"
19#include "typedefs.h"
20
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000021namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:25 +000022
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000023class PCMFile {
24 public:
25 PCMFile();
pbos@webrtc.org0946a562013-04-09 00:28:06 +000026 PCMFile(uint32_t timestamp);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000027 ~PCMFile() {
28 if (pcm_file_ != NULL) {
29 fclose(pcm_file_);
niklase@google.com470e71d2011-07-07 08:21:25 +000030 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000031 }
tina.legrand@webrtc.orgba468042012-08-17 10:38:28 +000032
pbos@webrtc.org0946a562013-04-09 00:28:06 +000033 void Open(const std::string& filename, uint16_t frequency,
tina.legrand@webrtc.orgba468042012-08-17 10:38:28 +000034 const char* mode, bool auto_rewind = false);
niklase@google.com470e71d2011-07-07 08:21:25 +000035
pbos@webrtc.org0946a562013-04-09 00:28:06 +000036 int32_t Read10MsData(AudioFrame& audio_frame);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000037
pbos@webrtc.org0946a562013-04-09 00:28:06 +000038 void Write10MsData(int16_t *playout_buffer,
39 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();
pbos@webrtc.org0946a562013-04-09 00:28:06 +000049 static int16_t ChooseFile(std::string* file_name,
50 int16_t max_len,
51 uint16_t* frequency_hz);
52 static int16_t ChooseFile(std::string* file_name,
53 int16_t max_len);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000054 bool Rewinded();
55 void SaveStereo(bool is_stereo = true);
56 void ReadStereo(bool is_stereo = true);
57 private:
58 FILE* pcm_file_;
pbos@webrtc.org0946a562013-04-09 00:28:06 +000059 uint16_t samples_10ms_;
60 int32_t frequency_;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000061 bool end_of_file_;
62 bool auto_rewind_;
63 bool rewinded_;
pbos@webrtc.org0946a562013-04-09 00:28:06 +000064 uint32_t timestamp_;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000065 bool read_stereo_;
66 bool save_stereo_;
niklase@google.com470e71d2011-07-07 08:21:25 +000067};
68
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000069} // namespace webrtc
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000070
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000071#endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_TEST_PCMFILE_H_