peah | b46083e | 2016-05-03 07:01:18 -0700 | [diff] [blame] | 1 | /* |
| 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 Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "modules/audio_processing/logging/apm_data_dumper.h" |
peah | b46083e | 2016-05-03 07:01:18 -0700 | [diff] [blame] | 12 | |
Per Åhgren | f0c449e | 2018-10-23 20:17:18 +0200 | [diff] [blame] | 13 | #include "rtc_base/strings/string_builder.h" |
| 14 | |
peah | b46083e | 2016-05-03 07:01:18 -0700 | [diff] [blame] | 15 | // Check to verify that the define is properly set. |
peah | f28a389 | 2016-09-01 08:58:21 -0700 | [diff] [blame] | 16 | #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" |
peah | b46083e | 2016-05-03 07:01:18 -0700 | [diff] [blame] | 19 | #endif |
| 20 | |
| 21 | namespace webrtc { |
| 22 | |
| 23 | namespace { |
| 24 | |
peah | f28a389 | 2016-09-01 08:58:21 -0700 | [diff] [blame] | 25 | #if WEBRTC_APM_DEBUG_DUMP == 1 |
peah | b46083e | 2016-05-03 07:01:18 -0700 | [diff] [blame] | 26 | std::string FormFileName(const char* name, |
| 27 | int instance_index, |
| 28 | int reinit_index, |
| 29 | const std::string& suffix) { |
Jonas Olsson | 18f151a | 2018-04-05 11:34:56 +0200 | [diff] [blame] | 30 | char buf[1024]; |
| 31 | rtc::SimpleStringBuilder ss(buf); |
peah | b46083e | 2016-05-03 07:01:18 -0700 | [diff] [blame] | 32 | ss << name << "_" << instance_index << "-" << reinit_index << suffix; |
| 33 | return ss.str(); |
| 34 | } |
| 35 | #endif |
| 36 | |
| 37 | } // namespace |
| 38 | |
peah | f28a389 | 2016-09-01 08:58:21 -0700 | [diff] [blame] | 39 | #if WEBRTC_APM_DEBUG_DUMP == 1 |
peah | f8f754a | 2016-08-30 10:31:45 -0700 | [diff] [blame] | 40 | ApmDataDumper::ApmDataDumper(int instance_index) |
| 41 | : instance_index_(instance_index) {} |
| 42 | #else |
| 43 | ApmDataDumper::ApmDataDumper(int instance_index) {} |
| 44 | #endif |
| 45 | |
| 46 | ApmDataDumper::~ApmDataDumper() {} |
| 47 | |
peah | f28a389 | 2016-09-01 08:58:21 -0700 | [diff] [blame] | 48 | #if WEBRTC_APM_DEBUG_DUMP == 1 |
Per Åhgren | 7a95e0f | 2018-10-25 09:56:49 +0200 | [diff] [blame^] | 49 | bool ApmDataDumper::recording_activated_ = false; |
| 50 | ; |
peah | b46083e | 2016-05-03 07:01:18 -0700 | [diff] [blame] | 51 | FILE* ApmDataDumper::GetRawFile(const char* name) { |
| 52 | std::string filename = |
| 53 | FormFileName(name, instance_index_, recording_set_index_, ".dat"); |
| 54 | auto& f = raw_files_[filename]; |
| 55 | if (!f) { |
| 56 | f.reset(fopen(filename.c_str(), "wb")); |
| 57 | } |
| 58 | return f.get(); |
| 59 | } |
| 60 | |
| 61 | WavWriter* ApmDataDumper::GetWavFile(const char* name, |
| 62 | int sample_rate_hz, |
| 63 | int num_channels) { |
| 64 | std::string filename = |
| 65 | FormFileName(name, instance_index_, recording_set_index_, ".wav"); |
| 66 | auto& f = wav_files_[filename]; |
| 67 | if (!f) { |
| 68 | f.reset(new WavWriter(filename.c_str(), sample_rate_hz, num_channels)); |
| 69 | } |
| 70 | return f.get(); |
| 71 | } |
| 72 | |
| 73 | #endif |
| 74 | |
| 75 | } // namespace webrtc |