interpolate.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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 <deque>
  7. #include "audio_core/hle/common.h"
  8. #include "common/common_types.h"
  9. namespace AudioInterp {
  10. /// A variable length buffer of signed PCM16 stereo samples.
  11. using StereoBuffer16 = std::deque<std::array<s16, 2>>;
  12. struct State {
  13. /// Two historical samples.
  14. std::array<s16, 2> xn1 = {}; ///< x[n-1]
  15. std::array<s16, 2> xn2 = {}; ///< x[n-2]
  16. /// Current fractional position.
  17. u64 fposition = 0;
  18. };
  19. /**
  20. * No interpolation. This is equivalent to a zero-order hold. There is a two-sample predelay.
  21. * @param state Interpolation state.
  22. * @param input Input buffer.
  23. * @param rate Stretch factor. Must be a positive non-zero value.
  24. * rate > 1.0 performs decimation and rate < 1.0 performs upsampling.
  25. * @param output The resampled audio buffer.
  26. * @param outputi The index of output to start writing to.
  27. */
  28. void None(State& state, StereoBuffer16& input, float rate, DSP::HLE::StereoFrame16& output,
  29. size_t& outputi);
  30. /**
  31. * Linear interpolation. This is equivalent to a first-order hold. There is a two-sample predelay.
  32. * @param state Interpolation state.
  33. * @param input Input buffer.
  34. * @param rate Stretch factor. Must be a positive non-zero value.
  35. * rate > 1.0 performs decimation and rate < 1.0 performs upsampling.
  36. * @param output The resampled audio buffer.
  37. * @param outputi The index of output to start writing to.
  38. */
  39. void Linear(State& state, StereoBuffer16& input, float rate, DSP::HLE::StereoFrame16& output,
  40. size_t& outputi);
  41. } // namespace AudioInterp