blob: ebb85268f9fbd307c09f02aeb2d8a39c65bd780b [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
Per Ã…hgrenf0c449e2018-10-23 20:17:18 +020013#include "rtc_base/strings/string_builder.h"
14
peahb46083e2016-05-03 07:01:18 -070015// Check to verify that the define is properly set.
peahf28a3892016-09-01 08:58:21 -070016#if !defined(WEBRTC_APM_DEBUG_DUMP) || \
17 (WEBRTC_APM_DEBUG_DUMP != 0 && WEBRTC_APM_DEBUG_DUMP != 1)
18#error "Set WEBRTC_APM_DEBUG_DUMP to either 0 or 1"
peahb46083e2016-05-03 07:01:18 -070019#endif
20
21namespace webrtc {
22
23namespace {
24
peahf28a3892016-09-01 08:58:21 -070025#if WEBRTC_APM_DEBUG_DUMP == 1
peahb46083e2016-05-03 07:01:18 -070026std::string FormFileName(const char* name,
27 int instance_index,
28 int reinit_index,
29 const std::string& suffix) {
Jonas Olsson18f151a2018-04-05 11:34:56 +020030 char buf[1024];
31 rtc::SimpleStringBuilder ss(buf);
peahb46083e2016-05-03 07:01:18 -070032 ss << name << "_" << instance_index << "-" << reinit_index << suffix;
33 return ss.str();
34}
35#endif
36
37} // namespace
38
peahf28a3892016-09-01 08:58:21 -070039#if WEBRTC_APM_DEBUG_DUMP == 1
peahf8f754a2016-08-30 10:31:45 -070040ApmDataDumper::ApmDataDumper(int instance_index)
41 : instance_index_(instance_index) {}
42#else
43ApmDataDumper::ApmDataDumper(int instance_index) {}
44#endif
45
46ApmDataDumper::~ApmDataDumper() {}
47
peahf28a3892016-09-01 08:58:21 -070048#if WEBRTC_APM_DEBUG_DUMP == 1
peahb46083e2016-05-03 07:01:18 -070049FILE* ApmDataDumper::GetRawFile(const char* name) {
50 std::string filename =
51 FormFileName(name, instance_index_, recording_set_index_, ".dat");
52 auto& f = raw_files_[filename];
53 if (!f) {
54 f.reset(fopen(filename.c_str(), "wb"));
55 }
56 return f.get();
57}
58
59WavWriter* ApmDataDumper::GetWavFile(const char* name,
60 int sample_rate_hz,
61 int num_channels) {
62 std::string filename =
63 FormFileName(name, instance_index_, recording_set_index_, ".wav");
64 auto& f = wav_files_[filename];
65 if (!f) {
66 f.reset(new WavWriter(filename.c_str(), sample_rate_hz, num_channels));
67 }
68 return f.get();
69}
70
71#endif
72
73} // namespace webrtc