tor-browser

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

output_audio_file.h (1591B)


      1 /*
      2 *  Copyright (c) 2014 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_NETEQ_TOOLS_OUTPUT_AUDIO_FILE_H_
     12 #define MODULES_AUDIO_CODING_NETEQ_TOOLS_OUTPUT_AUDIO_FILE_H_
     13 
     14 #include <stdio.h>
     15 
     16 #include <cstdint>
     17 #include <string>
     18 
     19 #include "absl/strings/string_view.h"
     20 #include "modules/audio_coding/neteq/tools/audio_sink.h"
     21 #include "rtc_base/checks.h"
     22 
     23 namespace webrtc {
     24 namespace test {
     25 
     26 class OutputAudioFile : public AudioSink {
     27 public:
     28  // Creates an OutputAudioFile, opening a file named `file_name` for writing.
     29  // The file format is 16-bit signed host-endian PCM.
     30  explicit OutputAudioFile(absl::string_view file_name) {
     31    out_file_ = fopen(std::string(file_name).c_str(), "wb");
     32  }
     33 
     34  virtual ~OutputAudioFile() {
     35    if (out_file_)
     36      fclose(out_file_);
     37  }
     38 
     39  OutputAudioFile(const OutputAudioFile&) = delete;
     40  OutputAudioFile& operator=(const OutputAudioFile&) = delete;
     41 
     42  bool WriteArray(const int16_t* audio, size_t num_samples) override {
     43    RTC_DCHECK(out_file_);
     44    return fwrite(audio, sizeof(*audio), num_samples, out_file_) == num_samples;
     45  }
     46 
     47 private:
     48  FILE* out_file_;
     49 };
     50 
     51 }  // namespace test
     52 }  // namespace webrtc
     53 #endif  // MODULES_AUDIO_CODING_NETEQ_TOOLS_OUTPUT_AUDIO_FILE_H_