wsola_internals.h 3.7 KB

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