OLD | NEW |
---|---|
(Empty) | |
1 /* | |
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 #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_AEC3_FFT_DATA_H_ | |
12 #define WEBRTC_MODULES_AUDIO_PROCESSING_AEC3_FFT_DATA_H_ | |
13 | |
14 #include <algorithm> | |
15 #include <array> | |
16 | |
17 #include "webrtc/base/array_view.h" | |
18 #include "webrtc/modules/audio_processing/aec3/aec3_constants.h" | |
19 | |
20 namespace webrtc { | |
21 | |
22 // Struct that holds imaginary data produced from 128 point real-valued FFTs. | |
23 struct FftData { | |
24 // Copies the data in src. | |
25 void Assign(const FftData& src) { | |
26 std::copy(src.re.begin(), src.re.end(), re.begin()); | |
27 std::copy(src.im.begin(), src.im.end(), im.begin()); | |
28 im[0] = im[kFftLengthBy2] = 0; | |
29 } | |
30 | |
31 // Clears all the imaginary. | |
32 void Clear() { | |
33 re.fill(0.f); | |
34 im.fill(0.f); | |
35 } | |
36 | |
37 // Computes the power spectrum of the data. | |
38 void Spectrum(std::array<float, kFftLengthBy2Plus1>* power_spectrum) const { | |
39 std::transform(re.begin(), re.end(), im.begin(), power_spectrum->begin(), | |
40 [](float a, float b) { return a * a + b * b; }); | |
41 } | |
42 | |
43 // Copy the data from an interlieved array. | |
aleloi
2017/02/09 17:02:59
interlieved -> interleaved (here and in some other
peah-webrtc
2017/02/20 07:37:17
Done.
| |
44 void CopyFromPackedArray(const std::array<float, kFftLength>& v) { | |
45 re[0] = v[0]; | |
46 re[kFftLengthBy2] = v[1]; | |
47 im[0] = im[kFftLengthBy2] = 0; | |
48 for (size_t k = 1, j = 2; k < kFftLengthBy2; ++k) { | |
49 re[k] = v[j++]; | |
50 im[k] = v[j++]; | |
51 } | |
52 } | |
53 | |
54 // Copies the data into an interlieved array. | |
55 void CopyToPackedArray(std::array<float, kFftLength>* v) const { | |
56 (*v)[0] = re[0]; | |
57 (*v)[1] = re[kFftLengthBy2]; | |
58 for (size_t k = 1, j = 2; k < kFftLengthBy2; ++k) { | |
59 (*v)[j++] = re[k]; | |
60 (*v)[j++] = im[k]; | |
61 } | |
62 } | |
63 | |
64 std::array<float, kFftLengthBy2Plus1> re; | |
65 std::array<float, kFftLengthBy2Plus1> im; | |
66 }; | |
67 | |
68 } // namespace webrtc | |
69 | |
70 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_AEC3_FFT_DATA_H_ | |
OLD | NEW |