blob: 19528e312ec54cc6175c358ec3ac79cf24de87bf [file] [log] [blame]
Patrik Höglundf715c532017-11-17 11:04:15 +01001/*
2 * Copyright (c) 2017 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 "common_audio/fir_filter_factory.h"
12
13#include "common_audio/fir_filter_c.h"
14#include "rtc_base/checks.h"
Niels Möllera12c42a2018-07-25 16:05:48 +020015#include "rtc_base/system/arch.h"
Patrik Höglundf715c532017-11-17 11:04:15 +010016
17#if defined(WEBRTC_HAS_NEON)
18#include "common_audio/fir_filter_neon.h"
19#elif defined(WEBRTC_ARCH_X86_FAMILY)
20#include "common_audio/fir_filter_sse.h"
Yves Gerey988cc082018-10-23 12:03:01 +020021#include "system_wrappers/include/cpu_features_wrapper.h" // kSSE2, WebRtc_G...
Patrik Höglundf715c532017-11-17 11:04:15 +010022#endif
23
24namespace webrtc {
25
26FIRFilter* CreateFirFilter(const float* coefficients,
27 size_t coefficients_length,
28 size_t max_input_length) {
29 if (!coefficients || coefficients_length <= 0 || max_input_length <= 0) {
30 RTC_NOTREACHED();
31 return nullptr;
32 }
33
34 FIRFilter* filter = nullptr;
35// If we know the minimum architecture at compile time, avoid CPU detection.
36#if defined(WEBRTC_ARCH_X86_FAMILY)
37#if defined(__SSE2__)
38 filter =
39 new FIRFilterSSE2(coefficients, coefficients_length, max_input_length);
40#else
41 // x86 CPU detection required.
42 if (WebRtc_GetCPUInfo(kSSE2)) {
43 filter =
44 new FIRFilterSSE2(coefficients, coefficients_length, max_input_length);
45 } else {
46 filter = new FIRFilterC(coefficients, coefficients_length);
47 }
48#endif
49#elif defined(WEBRTC_HAS_NEON)
50 filter =
51 new FIRFilterNEON(coefficients, coefficients_length, max_input_length);
52#else
53 filter = new FIRFilterC(coefficients, coefficients_length);
54#endif
55
56 return filter;
57}
58
59} // namespace webrtc