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