blob: 2f6a6d6a809cc9c76a0321e6aeb7ce26ed16c21f [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
13#include <sstream>
14
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020015#include "rtc_base/stringutils.h"
peahb46083e2016-05-03 07:01:18 -070016
17// Check to verify that the define is properly set.
peahf28a3892016-09-01 08:58:21 -070018#if !defined(WEBRTC_APM_DEBUG_DUMP) || \
19 (WEBRTC_APM_DEBUG_DUMP != 0 && WEBRTC_APM_DEBUG_DUMP != 1)
20#error "Set WEBRTC_APM_DEBUG_DUMP to either 0 or 1"
peahb46083e2016-05-03 07:01:18 -070021#endif
22
23namespace webrtc {
24
25namespace {
26
peahf28a3892016-09-01 08:58:21 -070027#if WEBRTC_APM_DEBUG_DUMP == 1
peahb46083e2016-05-03 07:01:18 -070028std::string FormFileName(const char* name,
29 int instance_index,
30 int reinit_index,
31 const std::string& suffix) {
32 std::stringstream ss;
33 ss << name << "_" << instance_index << "-" << reinit_index << suffix;
34 return ss.str();
35}
36#endif
37
38} // namespace
39
peahf28a3892016-09-01 08:58:21 -070040#if WEBRTC_APM_DEBUG_DUMP == 1
peahf8f754a2016-08-30 10:31:45 -070041ApmDataDumper::ApmDataDumper(int instance_index)
42 : instance_index_(instance_index) {}
43#else
44ApmDataDumper::ApmDataDumper(int instance_index) {}
45#endif
46
47ApmDataDumper::~ApmDataDumper() {}
48
peahf28a3892016-09-01 08:58:21 -070049#if WEBRTC_APM_DEBUG_DUMP == 1
peahb46083e2016-05-03 07:01:18 -070050FILE* ApmDataDumper::GetRawFile(const char* name) {
51 std::string filename =
52 FormFileName(name, instance_index_, recording_set_index_, ".dat");
53 auto& f = raw_files_[filename];
54 if (!f) {
55 f.reset(fopen(filename.c_str(), "wb"));
56 }
57 return f.get();
58}
59
60WavWriter* ApmDataDumper::GetWavFile(const char* name,
61 int sample_rate_hz,
62 int num_channels) {
63 std::string filename =
64 FormFileName(name, instance_index_, recording_set_index_, ".wav");
65 auto& f = wav_files_[filename];
66 if (!f) {
67 f.reset(new WavWriter(filename.c_str(), sample_rate_hz, num_channels));
68 }
69 return f.get();
70}
71
72#endif
73
74} // namespace webrtc