1/*
2 *  Copyright (c) 2015 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#include "webrtc/modules/audio_processing/logging/aec_logging_file_handling.h"
12
13#include <stdint.h>
14#include <stdio.h>
15
16#include "webrtc/base/checks.h"
17#include "webrtc/base/stringutils.h"
18#include "webrtc/common_audio/wav_file.h"
19#include "webrtc/typedefs.h"
20
21#ifdef WEBRTC_AEC_DEBUG_DUMP
22void WebRtcAec_ReopenWav(const char* name,
23                         int instance_index,
24                         int process_rate,
25                         int sample_rate,
26                         rtc_WavWriter** wav_file) {
27  if (*wav_file) {
28    if (rtc_WavSampleRate(*wav_file) == sample_rate)
29      return;
30    rtc_WavClose(*wav_file);
31  }
32  char filename[64];
33  int written = rtc::sprintfn(filename, sizeof(filename), "%s%d-%d.wav", name,
34                              instance_index, process_rate);
35
36  // Ensure there was no buffer output error.
37  RTC_DCHECK_GE(written, 0);
38  // Ensure that the buffer size was sufficient.
39  RTC_DCHECK_LT(static_cast<size_t>(written), sizeof(filename));
40
41  *wav_file = rtc_WavOpen(filename, sample_rate, 1);
42}
43
44void WebRtcAec_RawFileOpen(const char* name, int instance_index, FILE** file) {
45  char filename[64];
46  int written = rtc::sprintfn(filename, sizeof(filename), "%s_%d.dat", name,
47                              instance_index);
48
49  // Ensure there was no buffer output error.
50  RTC_DCHECK_GE(written, 0);
51  // Ensure that the buffer size was sufficient.
52  RTC_DCHECK_LT(static_cast<size_t>(written), sizeof(filename));
53
54  *file = fopen(filename, "wb");
55}
56
57#endif  // WEBRTC_AEC_DEBUG_DUMP
58