blob: 840933a1bd88c73708cc0f378d17a74fa365ab11 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:251/*
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:302 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:253 *
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 12:44:5411#ifndef WEBRTC_MODULES_AUDIO_CODING_TEST_PCMFILE_H_
12#define WEBRTC_MODULES_AUDIO_CODING_TEST_PCMFILE_H_
niklase@google.com470e71d2011-07-07 08:21:2513
pbos@webrtc.org12dc1a32013-08-05 16:22:5314#include <stdio.h>
15#include <stdlib.h>
16
tina.legrand@webrtc.orgba468042012-08-17 10:38:2817#include <string>
niklase@google.com470e71d2011-07-07 08:21:2518
Henrik Lundin4d682082015-12-10 15:24:3919#include "webrtc/base/optional.h"
Henrik Kjellanderff761fb2015-11-04 07:31:5220#include "webrtc/modules/include/module_common_types.h"
turaj@webrtc.org6ea3d1c2013-10-02 21:44:3321#include "webrtc/typedefs.h"
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:3022
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:0423namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:2524
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:3025class PCMFile {
26 public:
27 PCMFile();
pbos@webrtc.org0946a562013-04-09 00:28:0628 PCMFile(uint32_t timestamp);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:3029 ~PCMFile() {
30 if (pcm_file_ != NULL) {
31 fclose(pcm_file_);
niklase@google.com470e71d2011-07-07 08:21:2532 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:3033 }
tina.legrand@webrtc.orgba468042012-08-17 10:38:2834
tina.legrand@webrtc.orgd5726a122013-05-03 07:34:1235 void Open(const std::string& filename, uint16_t frequency, const char* mode,
36 bool auto_rewind = false);
niklase@google.com470e71d2011-07-07 08:21:2537
pbos@webrtc.org0946a562013-04-09 00:28:0638 int32_t Read10MsData(AudioFrame& audio_frame);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:3039
Peter Kastingdce40cf2015-08-24 21:52:2340 void Write10MsData(int16_t *playout_buffer, size_t length_smpls);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:3041 void Write10MsData(AudioFrame& audio_frame);
42
pbos@webrtc.org0946a562013-04-09 00:28:0643 uint16_t PayloadLength10Ms() const;
44 int32_t SamplingFrequency() const;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:3045 void Close();
46 bool EndOfFile() const {
47 return end_of_file_;
48 }
Henrik Lundin4d682082015-12-10 15:24:3949 // 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:3053 void Rewind();
tina.legrand@webrtc.orgd5726a122013-05-03 07:34:1254 static int16_t ChooseFile(std::string* file_name, int16_t max_len,
pbos@webrtc.org0946a562013-04-09 00:28:0655 uint16_t* frequency_hz);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:3056 bool Rewinded();
57 void SaveStereo(bool is_stereo = true);
58 void ReadStereo(bool is_stereo = true);
Henrik Lundin4d682082015-12-10 15:24:3959 // 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:3064 private:
65 FILE* pcm_file_;
pbos@webrtc.org0946a562013-04-09 00:28:0666 uint16_t samples_10ms_;
67 int32_t frequency_;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:3068 bool end_of_file_;
69 bool auto_rewind_;
70 bool rewinded_;
pbos@webrtc.org0946a562013-04-09 00:28:0671 uint32_t timestamp_;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:3072 bool read_stereo_;
73 bool save_stereo_;
Henrik Lundin4d682082015-12-10 15:24:3974 rtc::Optional<int> num_10ms_blocks_to_read_;
75 int blocks_read_ = 0;
niklase@google.com470e71d2011-07-07 08:21:2576};
77
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:3078} // namespace webrtc
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:0479
kjellander3e6db232015-11-26 12:44:5480#endif // WEBRTC_MODULES_AUDIO_CODING_TEST_PCMFILE_H_