real_fourier.cc (1788B)
1 /* 2 * Copyright (c) 2014 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/real_fourier.h" 12 13 #include <complex> 14 #include <cstddef> 15 #include <cstdint> 16 #include <memory> 17 18 #include "common_audio/real_fourier_ooura.h" 19 #include "common_audio/signal_processing/include/signal_processing_library.h" // IWYU pragma: keep 20 #include "common_audio/signal_processing/include/spl_inl.h" 21 #include "rtc_base/checks.h" 22 #include "rtc_base/memory/aligned_malloc.h" 23 24 namespace webrtc { 25 26 using std::complex; 27 28 const size_t RealFourier::kFftBufferAlignment = 32; 29 30 std::unique_ptr<RealFourier> RealFourier::Create(int fft_order) { 31 return std::unique_ptr<RealFourier>(new RealFourierOoura(fft_order)); 32 } 33 34 int RealFourier::FftOrder(size_t length) { 35 RTC_CHECK_GT(length, 0U); 36 return WebRtcSpl_GetSizeInBits(static_cast<uint32_t>(length - 1)); 37 } 38 39 size_t RealFourier::FftLength(int order) { 40 RTC_CHECK_GE(order, 0); 41 return size_t{1} << order; 42 } 43 44 size_t RealFourier::ComplexLength(int order) { 45 return FftLength(order) / 2 + 1; 46 } 47 48 RealFourier::fft_real_scoper RealFourier::AllocRealBuffer(int count) { 49 return fft_real_scoper(static_cast<float*>( 50 AlignedMalloc(sizeof(float) * count, kFftBufferAlignment))); 51 } 52 53 RealFourier::fft_cplx_scoper RealFourier::AllocCplxBuffer(int count) { 54 return fft_cplx_scoper(static_cast<complex<float>*>( 55 AlignedMalloc(sizeof(complex<float>) * count, kFftBufferAlignment))); 56 } 57 58 } // namespace webrtc