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 MultiChannelMovingWindowEnergies(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 void CubicInterpolation(const float* y_values, | |
47 float* extremum, | |
48 float* extremum_value); | |
49 | |
50 // Search a subset of all candid blocks. The search is performed every | |
51 // |decimation| frames. This reduces complexity by a factor of about | |
52 // 1 / |decimation|. A cubic interpolation is used to have a better estimate of | |
53 // the best match. | |
54 int DecimatedSearch(int decimation, | |
55 Interval exclude_interval, | |
56 const AudioBus* target_block, | |
57 const AudioBus* search_segment, | |
58 const float* energy_target_block, | |
59 const float* energy_candid_blocks); | |
60 | |
61 // Search [|lim_low|, |lim_high|] of |search_segment| to find a block that is | |
62 // most similar to |target_interval|. |energy_target_block| is the energy of the | |
marpan
2013/08/02 17:56:54
Most similar to |target_block|?
turaj
2013/08/02 23:45:59
Done.
| |
63 // target block. |energy_candid_blocks| is the energy of all blocks within | |
64 // |search_segment|. | |
65 int PartialSearch(int lim_low, | |
marpan
2013/08/02 17:56:54
Maybe rename to RefinedSearch, but PartialSearch i
turaj
2013/08/02 23:45:59
how about "FullSearch".
On 2013/08/02 17:56:54, m
marpan
2013/08/06 17:14:10
FullSearch is fine.
| |
66 int lim_high, | |
67 Interval exclude_interval, | |
68 const AudioBus* target_block, | |
69 const AudioBus* search_segment, | |
70 const float* energy_target_block, | |
71 const float* energy_candid_blocks); | |
72 | |
73 // Find the index of the block, within |search_segment|, that is most similar | |
74 // to |target_block|. Obviously, the returned index is w.r.t. |search_segment|. | |
75 // |exclude_interval| is an interval that is excluded from the search. | |
76 int OptimalIndex(const AudioBus* search_segment, | |
77 const AudioBus* target_block, | |
78 Interval exclude_interval); | |
79 | |
80 // Return a "periodic" Hann window. This is the first L samples of an L+1 | |
81 // Hann window. It is perfect reconstruction for overlap-and-add. | |
82 void GetSymmetricHanningWindow(int window_length, float* window); | |
83 | |
84 } // namespace internal | |
85 | |
86 } // namespace media | |
87 | |
88 #endif // MEDIA_FILTERS_WSOLA_INTERNALS_H_ | |
OLD | NEW |