time_stretch.h 888 B

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