OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 // A set of utility functions to perform WSOLA. | |
6 | |
7 #ifndef MEDIA_FILTERS_WSOLA_INTERNALS_H_ | |
8 #define MEDIA_FILTERS_WSOLA_INTERNALS_H_ | |
9 | |
10 #include <utility> | |
11 | |
12 namespace media { | |
13 | |
14 class AudioBus; | |
15 | |
16 namespace internal { | |
17 | |
18 typedef std::pair<int, int> Interval; | |
19 | |
20 // Dot-product of channels of two AudioBus. For each AudioBus an offset is | |
21 // given. |dot_product[k]| is the dot-product of channel |k|. The caller should | |
22 // allocate sufficient space for |dot_product|. | |
23 void MultiChannelDotProduct(const AudioBus* a, | |
24 int frame_offset_a, | |
25 const AudioBus* b, | |
26 int frame_offset_b, | |
27 int num_frames, | |
28 float* dot_product); | |
29 | |
30 // Energies of sliding windows of channels are interleaved. | |
31 // The number windows is |input->frames()| - (|frames_per_window| - 1), hence, | |
32 // the method assumes |energy| must be, at least, of size | |
33 // (|input->frames()| - (|frames_per_window| - 1)) * |input->channels()|. | |
34 void MultiChannelMovingBlockEnergies(const AudioBus* input, | |
35 int frames_per_window, | |
36 float* energy); | |
37 | |
38 // Fit the curve f(x) = a * x^2 + b * x + c such that | |
39 // | |
40 // f(-1) = |y[0]| | |
41 // f(0) = |y[1]| | |
42 // f(1) = |y[2]|. | |
43 // | |
44 // Then compute the |extremum| point -b / (2*a) and |extremum_value| | |
45 // b^2 / (4*a) - b^2 / (2*a) + c. | |
46 // | |
47 // It is not expected that this function is called with | |
48 // y[0] == y[1] == y[2]. | |
49 void CubicInterpolation(const float* y_values, | |
50 float* extremum, | |
51 float* extremum_value); | |
52 | |
53 // Search a subset of all candid blocks. The search is performed every | |
54 // |decimation| frames. This reduces complexity by a factor of about | |
55 // 1 / |decimation|. A cubic interpolation is used to have a better estimate of | |
56 // the best match. | |
57 int DecimatedSearch(int decimation, | |
58 Interval exclude_interval, | |
59 const AudioBus* target_block, | |
60 const AudioBus* search_segment, | |
61 const float* energy_target_block, | |
62 const float* energy_candid_blocks); | |
63 | |
64 // Search [|lim_low|, |lim_high|] of |search_segment| to find a block that is | |
65 // most similar to |target_block|. |energy_target_block| is the energy of the | |
66 // target block. |energy_candidate_blocks| is the energy of all blocks within | |
67 // |search_block|. | |
68 int FullSearch(int lim_low, | |
DaleCurtis
2013/08/13 21:11:04
low_limit, high_limit ?
turaj
2013/08/16 22:13:56
Done.
| |
69 int lim_high, | |
70 Interval exclude_interval, | |
71 const AudioBus* target_block, | |
72 const AudioBus* search_block, | |
73 const float* energy_target_block, | |
74 const float* energy_candidate_blocks); | |
75 | |
76 // Find the index of the block, within |search_block|, that is most similar | |
77 // to |target_block|. Obviously, the returned index is w.r.t. |search_block|. | |
78 // |exclude_interval| is an interval that is excluded from the search. | |
79 int OptimalIndex(const AudioBus* search_block, | |
80 const AudioBus* target_block, | |
81 Interval exclude_interval); | |
82 | |
83 // Return a "periodic" Hann window. This is the first L samples of an L+1 | |
84 // Hann window. It is perfect reconstruction for overlap-and-add. | |
85 void GetSymmetricHanningWindow(int window_length, float* window); | |
86 | |
87 } // namespace internal | |
88 | |
89 } // namespace media | |
90 | |
91 #endif // MEDIA_FILTERS_WSOLA_INTERNALS_H_ | |
OLD | NEW |