blob: d7174c64492e1dfb7bd6fcf0c623125663e5bdd0 [file] [log] [blame]
peahb46083e2016-05-03 07:01:18 -07001/*
2 * Copyright (c) 2016 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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#include "modules/audio_processing/logging/apm_data_dumper.h"
peahb46083e2016-05-03 07:01:18 -070012
peahb46083e2016-05-03 07:01:18 -070013// Check to verify that the define is properly set.
peahf28a3892016-09-01 08:58:21 -070014#if !defined(WEBRTC_APM_DEBUG_DUMP) || \
15 (WEBRTC_APM_DEBUG_DUMP != 0 && WEBRTC_APM_DEBUG_DUMP != 1)
16#error "Set WEBRTC_APM_DEBUG_DUMP to either 0 or 1"
peahb46083e2016-05-03 07:01:18 -070017#endif
18
19namespace webrtc {
20
21namespace {
22
peahf28a3892016-09-01 08:58:21 -070023#if WEBRTC_APM_DEBUG_DUMP == 1
peahb46083e2016-05-03 07:01:18 -070024std::string FormFileName(const char* name,
25 int instance_index,
26 int reinit_index,
27 const std::string& suffix) {
Jonas Olsson18f151a2018-04-05 11:34:56 +020028 char buf[1024];
29 rtc::SimpleStringBuilder ss(buf);
peahb46083e2016-05-03 07:01:18 -070030 ss << name << "_" << instance_index << "-" << reinit_index << suffix;
31 return ss.str();
32}
33#endif
34
35} // namespace
36
peahf28a3892016-09-01 08:58:21 -070037#if WEBRTC_APM_DEBUG_DUMP == 1
peahf8f754a2016-08-30 10:31:45 -070038ApmDataDumper::ApmDataDumper(int instance_index)
39 : instance_index_(instance_index) {}
40#else
41ApmDataDumper::ApmDataDumper(int instance_index) {}
42#endif
43
44ApmDataDumper::~ApmDataDumper() {}
45
peahf28a3892016-09-01 08:58:21 -070046#if WEBRTC_APM_DEBUG_DUMP == 1
peahb46083e2016-05-03 07:01:18 -070047FILE* ApmDataDumper::GetRawFile(const char* name) {
48 std::string filename =
49 FormFileName(name, instance_index_, recording_set_index_, ".dat");
50 auto& f = raw_files_[filename];
51 if (!f) {
52 f.reset(fopen(filename.c_str(), "wb"));
53 }
54 return f.get();
55}
56
57WavWriter* ApmDataDumper::GetWavFile(const char* name,
58 int sample_rate_hz,
59 int num_channels) {
60 std::string filename =
61 FormFileName(name, instance_index_, recording_set_index_, ".wav");
62 auto& f = wav_files_[filename];
63 if (!f) {
64 f.reset(new WavWriter(filename.c_str(), sample_rate_hz, num_channels));
65 }
66 return f.get();
67}
68
69#endif
70
71} // namespace webrtc