Move UpdateManifest test from unit_tests into extensions_unittests.
[chromium-blink-merge.git] / media / filters / wsola_internals.h
blob13d2875cb3104655aeb4bd98a1ba1f04ca166dfe
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.
5 // A set of utility functions to perform WSOLA.
7 #ifndef MEDIA_FILTERS_WSOLA_INTERNALS_H_
8 #define MEDIA_FILTERS_WSOLA_INTERNALS_H_
10 #include <utility>
12 #include "media/base/media_export.h"
14 namespace media {
16 class AudioBus;
18 namespace internal {
20 typedef std::pair<int, int> Interval;
22 // Dot-product of channels of two AudioBus. For each AudioBus an offset is
23 // given. |dot_product[k]| is the dot-product of channel |k|. The caller should
24 // allocate sufficient space for |dot_product|.
25 MEDIA_EXPORT void MultiChannelDotProduct(const AudioBus* a,
26 int frame_offset_a,
27 const AudioBus* b,
28 int frame_offset_b,
29 int num_frames,
30 float* dot_product);
32 // Energies of sliding windows of channels are interleaved.
33 // The number windows is |input->frames()| - (|frames_per_window| - 1), hence,
34 // the method assumes |energy| must be, at least, of size
35 // (|input->frames()| - (|frames_per_window| - 1)) * |input->channels()|.
36 MEDIA_EXPORT void MultiChannelMovingBlockEnergies(const AudioBus* input,
37 int frames_per_window,
38 float* energy);
40 // Fit the curve f(x) = a * x^2 + b * x + c such that
41 // f(-1) = y[0]
42 // f(0) = y[1]
43 // f(1) = y[2]
44 // and return the maximum, assuming that y[0] <= y[1] >= y[2].
45 MEDIA_EXPORT void QuadraticInterpolation(const float* y_values,
46 float* extremum,
47 float* extremum_value);
49 // Search a subset of all candid blocks. The search is performed every
50 // |decimation| frames. This reduces complexity by a factor of about
51 // 1 / |decimation|. A cubic interpolation is used to have a better estimate of
52 // the best match.
53 MEDIA_EXPORT int DecimatedSearch(int decimation,
54 Interval exclude_interval,
55 const AudioBus* target_block,
56 const AudioBus* search_segment,
57 const float* energy_target_block,
58 const float* energy_candid_blocks);
60 // Search [|low_limit|, |high_limit|] of |search_segment| to find a block that
61 // is most similar to |target_block|. |energy_target_block| is the energy of the
62 // |target_block|. |energy_candidate_blocks| is the energy of all blocks within
63 // |search_block|.
64 MEDIA_EXPORT int FullSearch(int low_limit,
65 int hight_limimit,
66 Interval exclude_interval,
67 const AudioBus* target_block,
68 const AudioBus* search_block,
69 const float* energy_target_block,
70 const float* energy_candidate_blocks);
72 // Find the index of the block, within |search_block|, that is most similar
73 // to |target_block|. Obviously, the returned index is w.r.t. |search_block|.
74 // |exclude_interval| is an interval that is excluded from the search.
75 MEDIA_EXPORT int OptimalIndex(const AudioBus* search_block,
76 const AudioBus* target_block,
77 Interval exclude_interval);
79 // Return a "periodic" Hann window. This is the first L samples of an L+1
80 // Hann window. It is perfect reconstruction for overlap-and-add.
81 MEDIA_EXPORT void GetSymmetricHanningWindow(int window_length, float* window);
83 } // namespace internal
85 } // namespace media
87 #endif // MEDIA_FILTERS_WSOLA_INTERNALS_H_