webrtc/modules/audio_processing/voice_detection_unittest.cc
Henrik Lundin 64253a93dc Remove more traces of keyboard mic support from APM
The 6-parameter Initialize method is removed. The has_keyboard parameter
in the StreamConfig constructor is removed together with the underlying
member and helper functions.

Bug: chromium:1271981, b/217349489
Change-Id: I7259a114a395f74f735a9c06510c0fc0f0f008e3
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/250221
Reviewed-by: Sam Zackrisson <saza@google.com>
Reviewed-by: Sam Zackrisson <saza@webrtc.org>
Auto-Submit: Henrik Lundin <henrik.lundin@webrtc.org>
Commit-Queue: Henrik Lundin <henrik.lundin@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#35908}
2022-02-04 14:27:51 +00:00

104 lines
3.6 KiB
C++

/*
* Copyright (c) 2016 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 <vector>
#include "api/array_view.h"
#include "modules/audio_processing/audio_buffer.h"
#include "modules/audio_processing/test/audio_buffer_tools.h"
#include "modules/audio_processing/test/bitexactness_tools.h"
#include "modules/audio_processing/voice_detection.h"
#include "test/gtest.h"
namespace webrtc {
namespace {
const int kNumFramesToProcess = 1000;
// Process one frame of data and produce the output.
bool ProcessOneFrame(int sample_rate_hz,
AudioBuffer* audio_buffer,
VoiceDetection* voice_detection) {
if (sample_rate_hz > AudioProcessing::kSampleRate16kHz) {
audio_buffer->SplitIntoFrequencyBands();
}
return voice_detection->ProcessCaptureAudio(audio_buffer);
}
// Processes a specified amount of frames, verifies the results and reports
// any errors.
void RunBitexactnessTest(int sample_rate_hz,
size_t num_channels,
bool stream_has_voice_reference) {
int sample_rate_to_use = std::min(sample_rate_hz, 16000);
VoiceDetection voice_detection(sample_rate_to_use,
VoiceDetection::kLowLikelihood);
int samples_per_channel = rtc::CheckedDivExact(sample_rate_hz, 100);
const StreamConfig capture_config(sample_rate_hz, num_channels);
AudioBuffer capture_buffer(
capture_config.sample_rate_hz(), capture_config.num_channels(),
capture_config.sample_rate_hz(), capture_config.num_channels(),
capture_config.sample_rate_hz(), capture_config.num_channels());
test::InputAudioFile capture_file(
test::GetApmCaptureTestVectorFileName(sample_rate_hz));
std::vector<float> capture_input(samples_per_channel * num_channels);
bool stream_has_voice = false;
for (int frame_no = 0; frame_no < kNumFramesToProcess; ++frame_no) {
ReadFloatSamplesFromStereoFile(samples_per_channel, num_channels,
&capture_file, capture_input);
test::CopyVectorToAudioBuffer(capture_config, capture_input,
&capture_buffer);
stream_has_voice =
ProcessOneFrame(sample_rate_hz, &capture_buffer, &voice_detection);
}
EXPECT_EQ(stream_has_voice_reference, stream_has_voice);
}
const bool kStreamHasVoiceReference = true;
} // namespace
TEST(VoiceDetectionBitExactnessTest, Mono8kHz) {
RunBitexactnessTest(8000, 1, kStreamHasVoiceReference);
}
TEST(VoiceDetectionBitExactnessTest, Mono16kHz) {
RunBitexactnessTest(16000, 1, kStreamHasVoiceReference);
}
TEST(VoiceDetectionBitExactnessTest, Mono32kHz) {
RunBitexactnessTest(32000, 1, kStreamHasVoiceReference);
}
TEST(VoiceDetectionBitExactnessTest, Mono48kHz) {
RunBitexactnessTest(48000, 1, kStreamHasVoiceReference);
}
TEST(VoiceDetectionBitExactnessTest, Stereo8kHz) {
RunBitexactnessTest(8000, 2, kStreamHasVoiceReference);
}
TEST(VoiceDetectionBitExactnessTest, Stereo16kHz) {
RunBitexactnessTest(16000, 2, kStreamHasVoiceReference);
}
TEST(VoiceDetectionBitExactnessTest, Stereo32kHz) {
RunBitexactnessTest(32000, 2, kStreamHasVoiceReference);
}
TEST(VoiceDetectionBitExactnessTest, Stereo48kHz) {
RunBitexactnessTest(48000, 2, kStreamHasVoiceReference);
}
} // namespace webrtc