time_stretch.h 890 B

123456789101112131415161718192021222324252627282930313233343536
  1. // Copyright 2018 yuzu 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 <cstddef>
  7. #include <SoundTouch.h>
  8. #include "common/common_types.h"
  9. namespace AudioCore {
  10. class TimeStretcher {
  11. public:
  12. TimeStretcher(u32 sample_rate, u32 channel_count);
  13. /// @param in Input sample buffer
  14. /// @param num_in Number of input frames in `in`
  15. /// @param out Output sample buffer
  16. /// @param num_out Desired number of output frames in `out`
  17. /// @returns Actual number of frames written to `out`
  18. size_t Process(const s16* in, size_t num_in, s16* out, size_t num_out);
  19. void Clear();
  20. void Flush();
  21. private:
  22. u32 m_sample_rate;
  23. u32 m_channel_count;
  24. soundtouch::SoundTouch m_sound_touch;
  25. double m_stretch_ratio = 1.0;
  26. };
  27. } // namespace AudioCore