interpolate.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright 2016 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <array>
  6. #include <vector>
  7. #include "common/common_types.h"
  8. namespace AudioInterp {
  9. /// A variable length buffer of signed PCM16 stereo samples.
  10. using StereoBuffer16 = std::vector<std::array<s16, 2>>;
  11. struct State {
  12. // Two historical samples.
  13. std::array<s16, 2> xn1 = {}; ///< x[n-1]
  14. std::array<s16, 2> xn2 = {}; ///< x[n-2]
  15. };
  16. /**
  17. * No interpolation. This is equivalent to a zero-order hold. There is a two-sample predelay.
  18. * @param input Input buffer.
  19. * @param rate_multiplier Stretch factor. Must be a positive non-zero value.
  20. * rate_multiplier > 1.0 performs decimation and rate_multipler < 1.0
  21. * performs upsampling.
  22. * @return The resampled audio buffer.
  23. */
  24. StereoBuffer16 None(State& state, const StereoBuffer16& input, float rate_multiplier);
  25. /**
  26. * Linear interpolation. This is equivalent to a first-order hold. There is a two-sample predelay.
  27. * @param input Input buffer.
  28. * @param rate_multiplier Stretch factor. Must be a positive non-zero value.
  29. * rate_multiplier > 1.0 performs decimation and rate_multipler < 1.0
  30. * performs upsampling.
  31. * @return The resampled audio buffer.
  32. */
  33. StereoBuffer16 Linear(State& state, const StereoBuffer16& input, float rate_multiplier);
  34. } // namespace AudioInterp