Added logging using the raw variant of the new aec logging macros

Replaced the wav file dumping functionality in aec_core.c with the newly added corresponding macros

Added macros for logging of AEC internal data

BUG=

Review URL: https://codereview.webrtc.org/1272403003

Cr-Commit-Position: refs/heads/master@{#9808}
This commit is contained in:
peah
2015-08-28 04:41:25 -07:00
committed by Commit bot
parent 4fbae2b791
commit 9e69abf85e
7 changed files with 224 additions and 41 deletions

View File

@ -77,6 +77,9 @@ source_set("audio_processing") {
"intelligibility/intelligibility_utils.h",
"level_estimator_impl.cc",
"level_estimator_impl.h",
"logging/aec_logging.h",
"logging/aec_logging_file_handling.cc",
"logging/aec_logging_file_handling.h",
"noise_suppression_impl.cc",
"noise_suppression_impl.h",
"processing_component.cc",

View File

@ -29,10 +29,12 @@
#include "webrtc/modules/audio_processing/aec/aec_common.h"
#include "webrtc/modules/audio_processing/aec/aec_core_internal.h"
#include "webrtc/modules/audio_processing/aec/aec_rdft.h"
#include "webrtc/modules/audio_processing/logging/aec_logging.h"
#include "webrtc/modules/audio_processing/utility/delay_estimator_wrapper.h"
#include "webrtc/system_wrappers/interface/cpu_features_wrapper.h"
#include "webrtc/typedefs.h"
// Buffer size (samples)
static const size_t kBufSizePartitions = 250; // 1 second of audio in 16 kHz.
@ -1220,8 +1222,8 @@ static void ProcessBlock(AecCore* aec) {
float farend[PART_LEN];
float* farend_ptr = NULL;
WebRtc_ReadBuffer(aec->far_time_buf, (void**)&farend_ptr, farend, 1);
rtc_WavWriteSamples(aec->farFile, farend_ptr, PART_LEN);
rtc_WavWriteSamples(aec->nearFile, nearend_ptr, PART_LEN);
RTC_AEC_DEBUG_WAV_WRITE(aec->farFile, farend_ptr, PART_LEN);
RTC_AEC_DEBUG_WAV_WRITE(aec->nearFile, nearend_ptr, PART_LEN);
}
#endif
@ -1348,6 +1350,10 @@ static void ProcessBlock(AecCore* aec) {
ef[1][i] = fft[2 * i + 1];
}
RTC_AEC_DEBUG_RAW_WRITE(aec->e_fft_file,
&ef[0][0],
sizeof(ef[0][0]) * PART_LEN1 * 2);
if (aec->metricsMode == 1) {
// Note that the first PART_LEN samples in fft (before transformation) are
// zero. Hence, the scaling by two in UpdateLevel() should not be
@ -1374,10 +1380,8 @@ static void ProcessBlock(AecCore* aec) {
WebRtc_WriteBuffer(aec->outFrBufH[i], outputH[i], PART_LEN);
}
#ifdef WEBRTC_AEC_DEBUG_DUMP
rtc_WavWriteSamples(aec->outLinearFile, e, PART_LEN);
rtc_WavWriteSamples(aec->outFile, output, PART_LEN);
#endif
RTC_AEC_DEBUG_WAV_WRITE(aec->outLinearFile, e, PART_LEN);
RTC_AEC_DEBUG_WAV_WRITE(aec->outFile, output, PART_LEN);
}
AecCore* WebRtcAec_CreateAec() {
@ -1512,40 +1516,19 @@ void WebRtcAec_FreeAec(AecCore* aec) {
WebRtc_FreeBuffer(aec->far_buf_windowed);
#ifdef WEBRTC_AEC_DEBUG_DUMP
WebRtc_FreeBuffer(aec->far_time_buf);
rtc_WavClose(aec->farFile);
rtc_WavClose(aec->nearFile);
rtc_WavClose(aec->outFile);
rtc_WavClose(aec->outLinearFile);
#endif
RTC_AEC_DEBUG_WAV_CLOSE(aec->farFile);
RTC_AEC_DEBUG_WAV_CLOSE(aec->nearFile);
RTC_AEC_DEBUG_WAV_CLOSE(aec->outFile);
RTC_AEC_DEBUG_WAV_CLOSE(aec->outLinearFile);
RTC_AEC_DEBUG_RAW_CLOSE(aec->e_fft_file);
WebRtc_FreeDelayEstimator(aec->delay_estimator);
WebRtc_FreeDelayEstimatorFarend(aec->delay_estimator_farend);
free(aec);
}
#ifdef WEBRTC_AEC_DEBUG_DUMP
// Open a new Wav file for writing. If it was already open with a different
// sample frequency, close it first.
static void ReopenWav(rtc_WavWriter** wav_file,
const char* name,
int seq1,
int seq2,
int sample_rate) {
int written ATTRIBUTE_UNUSED;
char filename[64];
if (*wav_file) {
if (rtc_WavSampleRate(*wav_file) == sample_rate)
return;
rtc_WavClose(*wav_file);
}
written = snprintf(filename, sizeof(filename), "%s%d-%d.wav",
name, seq1, seq2);
assert(written >= 0); // no output error
assert((size_t)written < sizeof(filename)); // buffer was large enough
*wav_file = rtc_WavOpen(filename, sample_rate, 1);
}
#endif // WEBRTC_AEC_DEBUG_DUMP
int WebRtcAec_InitAec(AecCore* aec, int sampFreq) {
int i;
@ -1575,15 +1558,24 @@ int WebRtcAec_InitAec(AecCore* aec, int sampFreq) {
WebRtc_InitBuffer(aec->far_time_buf);
{
int process_rate = sampFreq > 16000 ? 16000 : sampFreq;
ReopenWav(&aec->farFile, "aec_far",
aec->instance_index, aec->debug_dump_count, process_rate);
ReopenWav(&aec->nearFile, "aec_near",
aec->instance_index, aec->debug_dump_count, process_rate);
ReopenWav(&aec->outFile, "aec_out",
aec->instance_index, aec->debug_dump_count, process_rate);
ReopenWav(&aec->outLinearFile, "aec_out_linear",
aec->instance_index, aec->debug_dump_count, process_rate);
RTC_AEC_DEBUG_WAV_REOPEN("aec_far", aec->instance_index,
aec->debug_dump_count, process_rate,
&aec->farFile );
RTC_AEC_DEBUG_WAV_REOPEN("aec_near", aec->instance_index,
aec->debug_dump_count, process_rate,
&aec->nearFile);
RTC_AEC_DEBUG_WAV_REOPEN("aec_out", aec->instance_index,
aec->debug_dump_count, process_rate,
&aec->outFile );
RTC_AEC_DEBUG_WAV_REOPEN("aec_out_linear", aec->instance_index,
aec->debug_dump_count, process_rate,
&aec->outLinearFile);
}
RTC_AEC_DEBUG_RAW_OPEN("aec_e_fft",
aec->debug_dump_count,
&aec->e_fft_file);
++aec->debug_dump_count;
#endif
aec->system_delay = 0;

View File

@ -166,6 +166,7 @@ struct AecCore {
rtc_WavWriter* nearFile;
rtc_WavWriter* outFile;
rtc_WavWriter* outLinearFile;
FILE* e_fft_file;
#endif
};

View File

@ -87,6 +87,9 @@
'intelligibility/intelligibility_utils.h',
'level_estimator_impl.cc',
'level_estimator_impl.h',
'logging/aec_logging.h',
'logging/aec_logging_file_handling.cc',
'logging/aec_logging_file_handling.h',
'noise_suppression_impl.cc',
'noise_suppression_impl.h',
'processing_component.cc',

View File

@ -0,0 +1,86 @@
/*
* Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef WEBRTC_MODULES_AUDIO_PROCESSING_AEC_AEC_LOGGING_
#define WEBRTC_MODULES_AUDIO_PROCESSING_AEC_AEC_LOGGING_
#include <stdio.h>
#include "webrtc/modules/audio_processing/logging/aec_logging_file_handling.h"
// To enable AEC logging, invoke GYP with -Daec_debug_dump=1.
#ifdef WEBRTC_AEC_DEBUG_DUMP
// Dumps a wav data to file.
#define RTC_AEC_DEBUG_WAV_WRITE(file, data, num_samples) \
do { \
rtc_WavWriteSamples(file, data, num_samples); \
} while (0)
// (Re)opens a wav file for writing using the specified sample rate.
#define RTC_AEC_DEBUG_WAV_REOPEN(name, instance_index, process_rate, \
sample_rate, wav_file) \
do { \
WebRtcAec_ReopenWav(name, instance_index, process_rate, sample_rate, \
wav_file); \
} while (0)
// Closes a wav file.
#define RTC_AEC_DEBUG_WAV_CLOSE(wav_file) \
do { \
rtc_WavClose(wav_file); \
} while (0)
// Dumps a raw data to file.
#define RTC_AEC_DEBUG_RAW_WRITE(file, data, data_size) \
do { \
(void) fwrite(data, data_size, 1, file); \
} while (0)
// Opens a raw data file for writing using the specified sample rate.
#define RTC_AEC_DEBUG_RAW_OPEN(name, instance_counter, file) \
do { \
WebRtcAec_RawFileOpen(name, instance_counter, file); \
} while (0)
// Closes a raw data file.
#define RTC_AEC_DEBUG_RAW_CLOSE(file) \
do { \
fclose(file); \
} while (0)
#else // RTC_AEC_DEBUG_DUMP
#define RTC_AEC_DEBUG_WAV_WRITE(file, data, num_samples) \
do { \
} while (0)
#define RTC_AEC_DEBUG_WAV_REOPEN(wav_file, name, instance_index, process_rate, \
sample_rate) \
do { \
} while (0)
#define RTC_AEC_DEBUG_WAV_CLOSE(wav_file) \
do { \
} while (0)
#define RTC_AEC_DEBUG_RAW_WRITE(file, data, data_size) \
do { \
} while (0)
#define RTC_AEC_DEBUG_RAW_OPEN(file, name, instance_counter) \
do { \
} while (0)
#define RTC_AEC_DEBUG_RAW_CLOSE(file) \
do { \
} while (0)
#endif // WEBRTC_AEC_DEBUG_DUMP
#endif // WEBRTC_MODULES_AUDIO_PROCESSING_AEC_AEC_LOGGING_

View File

@ -0,0 +1,57 @@
/*
* Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "webrtc/modules/audio_processing/logging/aec_logging_file_handling.h"
#include <stdint.h>
#include <stdio.h>
#include "webrtc/base/checks.h"
#include "webrtc/base/stringutils.h"
#include "webrtc/common_audio/wav_file.h"
#include "webrtc/typedefs.h"
#ifdef WEBRTC_AEC_DEBUG_DUMP
void WebRtcAec_ReopenWav(const char* name,
int instance_index,
int process_rate,
int sample_rate,
rtc_WavWriter** wav_file) {
if (*wav_file) {
if (rtc_WavSampleRate(*wav_file) == sample_rate)
return;
rtc_WavClose(*wav_file);
}
char filename[64];
int written = rtc::sprintfn(filename, sizeof(filename), "%s%d-%d.wav", name,
instance_index, process_rate);
// Ensure there was no buffer output error.
DCHECK_GE(written, 0);
// Ensure that the buffer size was sufficient.
DCHECK_LT(static_cast<size_t>(written), sizeof(filename));
*wav_file = rtc_WavOpen(filename, sample_rate, 1);
}
void WebRtcAec_RawFileOpen(const char* name, int instance_index, FILE** file) {
char filename[64];
int written = rtc::sprintfn(filename, sizeof(filename), "%s_%d.dat", name,
instance_index);
// Ensure there was no buffer output error.
DCHECK_GE(written, 0);
// Ensure that the buffer size was sufficient.
DCHECK_LT(static_cast<size_t>(written), sizeof(filename));
*file = fopen(filename, "wb");
}
#endif // WEBRTC_AEC_DEBUG_DUMP

View File

@ -0,0 +1,41 @@
/*
* Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef WEBRTC_MODULES_AUDIO_PROCESSING_AEC_AEC_LOGGING_FILE_HANDLING_
#define WEBRTC_MODULES_AUDIO_PROCESSING_AEC_AEC_LOGGING_FILE_HANDLING_
#include <stdio.h>
#include "webrtc/common_audio/wav_file.h"
#include "webrtc/typedefs.h"
#ifdef __cplusplus
extern "C" {
#endif
#ifdef WEBRTC_AEC_DEBUG_DUMP
// Opens a new Wav file for writing. If it was already open with a different
// sample frequency, it closes it first.
void WebRtcAec_ReopenWav(const char* name,
int instance_index,
int process_rate,
int sample_rate,
rtc_WavWriter** wav_file);
// Opens dumpfile with instance-specific filename.
void WebRtcAec_RawFileOpen(const char* name, int instance_index, FILE** file);
#endif // WEBRTC_AEC_DEBUG_DUMP
#ifdef __cplusplus
}
#endif
#endif // WEBRTC_MODULES_AUDIO_PROCESSING_AEC_AEC_LOGGING_FILE_HANDLING_