tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

PCMFile.h (2330B)


      1 /*
      2 *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
      3 *
      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 
     11 #ifndef MODULES_AUDIO_CODING_TEST_PCMFILE_H_
     12 #define MODULES_AUDIO_CODING_TEST_PCMFILE_H_
     13 
     14 #include <stdio.h>
     15 #include <stdlib.h>
     16 
     17 #include <cstdint>
     18 #include <optional>
     19 #include <string>
     20 
     21 #include "absl/strings/string_view.h"
     22 #include "api/audio/audio_frame.h"
     23 
     24 namespace webrtc {
     25 
     26 class PCMFile {
     27 public:
     28  PCMFile();
     29  PCMFile(uint32_t timestamp);
     30  ~PCMFile();
     31 
     32  void Open(absl::string_view filename,
     33            uint16_t frequency,
     34            absl::string_view mode,
     35            bool auto_rewind = false);
     36 
     37  int32_t Read10MsData(AudioFrame& audio_frame);
     38 
     39  void Write10MsData(const int16_t* playout_buffer, size_t length_smpls);
     40  void Write10MsData(const AudioFrame& audio_frame);
     41 
     42  uint16_t PayloadLength10Ms() const;
     43  int32_t SamplingFrequency() const;
     44  void Close();
     45  bool EndOfFile() const { return end_of_file_; }
     46  // Moves forward the specified number of 10 ms blocks. If a limit has been set
     47  // with SetNum10MsBlocksToRead, fast-forwarding does not count towards this
     48  // limit.
     49  void FastForward(int num_10ms_blocks);
     50  void Rewind();
     51  static int16_t ChooseFile(std::string* file_name,
     52                            int16_t max_len,
     53                            uint16_t* frequency_hz);
     54  bool Rewinded();
     55  void SaveStereo(bool is_stereo = true);
     56  void ReadStereo(bool is_stereo = true);
     57  // If set, the reading will stop after the specified number of blocks have
     58  // been read. When that has happened, EndOfFile() will return true. Calling
     59  // Rewind() will reset the counter and start over.
     60  void SetNum10MsBlocksToRead(int value);
     61 
     62 private:
     63  FILE* pcm_file_;
     64  uint16_t samples_10ms_;
     65  int32_t frequency_;
     66  bool end_of_file_;
     67  bool auto_rewind_;
     68  bool rewinded_;
     69  uint32_t timestamp_;
     70  bool read_stereo_;
     71  bool save_stereo_;
     72  std::optional<int> num_10ms_blocks_to_read_;
     73  int blocks_read_ = 0;
     74 };
     75 
     76 }  // namespace webrtc
     77 
     78 #endif  // MODULES_AUDIO_CODING_TEST_PCMFILE_H_